Closed stirucherai closed 3 years ago
` import btle
class MyDelegate(btle.DefaultDelegate): def init(self, params): btle.DefaultDelegate.init(self)
def handleNotification(self, cHandle, data):
# ... perhaps check cHandle
# ... process 'data'
p = btle.Peripheral( "MAC ADDRESS" ) p.setDelegate( MyDelegate(params) ) p.setMTU(200) p.setDelegate( MyDelegate()) chList = p.getCharacteristics() for ch in chList: if str(ch.uuid) == global_.CHRName: BDLLog.debug (ch) BDLLog.debug (ch.valHandle) break
desc = ch.getDescriptors(AssignedNumbers.client_characteristic_configuration); p.writeCharacteristic(desc[0].handle, b"\x01\x00")
while True: if p.waitForNotifications(1.0):
continue
print "Waiting..."
# Perhaps do something else here
` Code used -- p.writeCharacteristic(desc[0].handle, b"\x01\x00") was changed to p.writeCharacteristic(ch.valHandle+1, b"\x01\x00") --Pretty sure it +1
gatttool char-read-uuid 2902 0x0004 01 00 0x000e 01 00
char-write-req 0x0004 0100 Write successful
but no message are flowing into
from Android phone using lightblue app
Fri Oct 15 16:30:11 GMT+05:30 2021: Service 0000ffe0-0000-1000-8000-00805f9b34fb
Characteristics:
|--0000ffe1-0000-1000-8000-00805f9b34fb: Readable, Writable, Writable Without Response, Notify
|------00002902-0000-1000-8000-00805f9b34fb:
Fri Oct 15 16:30:11 GMT+05:30 2021: Service 0000ff00-0000-1000-8000-00805f9b34fb
Characteristics:
|--0000ff02-0000-1000-8000-00805f9b34fb: Writable, Writable Without Response
|--0000ff01-0000-1000-8000-00805f9b34fb: Notify
|------00002902-0000-1000-8000-00805f9b34fb:
Fri Oct 15 16:30:23 GMT+05:30 2021: Requesting an ATT MTU value of 200 for C0:20:12:01:40:7B
Fri Oct 15 16:30:23 GMT+05:30 2021: Request succeeded, current MTU is 185
Fri Oct 15 16:30:39 GMT+05:30 2021: Reading from characteristic 0000ffe1-0000-1000-8000-00805f9b34fb
Fri Oct 15 16:30:39 GMT+05:30 2021: Read characteristic 0000ffe1-0000-1000-8000-00805f9b34fb | value:
Fri Oct 15 16:30:59 GMT+05:30 2021: Enabling notifications/indications on 0000ffe1-0000-1000-8000-00805f9b34fb
Fri Oct 15 16:30:59 GMT+05:30 2021: Notifications or indications ENABLED on 0000ffe1-0000-1000-8000-00805f9b34fb
Fri Oct 15 16:30:59 GMT+05:30 2021: Wrote to descriptor 00002902-0000-1000-8000-00805f9b34fb | value: 01 00
Fri Oct 15 16:31:01 GMT+05:30 2021: Characteristic 0000ffe1-0000-1000-8000-00805f9b34fb changed | value: 01 03 24 0E 42 0D DE 0A 28 0A 8C D5 DE 00 00 D0 02 00 00 98 58 00 00 9E 34 00 00 61 A8 00 00 EC 78 00 00 69 64 28 2D
** and continue to get more
pi@BDLThirucherai:~/ble $ sudo bluetoothctl Agent registered [bluetooth]# agent on Agent is already registered [bluetooth]# power on Changing power on succeeded [bluetooth]# trust C0:20:12:01:40:7B Changing C0:20:12:01:40:7B trust succeeded [bluetooth]# pair C0:20:12:01:40:7B Attempting to pair with C0:20:12:01:40:7B [CHG] Device C0:20:12:01:40:7B Connected: yes Failed to pair: org.bluez.Error.AuthenticationFailed [CHG] Device C0:20:12:01:40:7B Connected: no [bluetooth]#
PLEASE HELP
Found the issue -- BMS responds for send message -- on default it does not publish for us to subscribe.
Thanks and Regards Sarang
Scenario -- Have BLE based Battery Management System Have subscribed notification by passing 0100 to CC Handle (2902) No message is received -- tried using python code and gatttool same
Both method the write cmd for subscription enablement is sucessful
Tried the same using lightBlue app from mobile device and it works without issue.
Any help will be greatly help.
BTW using bluetoothctl tried pairing that is also failing but connect from bluetooth, gatttool or python code are working