IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.6k stars 491 forks source link

Notifications Example Please Correct #417

Open bapgobears opened 4 years ago

bapgobears commented 4 years ago

Thanks for the great library, but I wanted to remind you the example on notifications is not correct and is causing people a lot of headaches, especially if you are new to python and/or ble. It should be easy to correct. Also, please make it clear that 0x02 is needed to turn on "indications" and 0x01 is for "notifications". It's not clear they are different. It would be great, as someone else somewhere mentioned, to add some member functions to turn notifications/indications on. It's not intuitive at all that you would need to write data to turn on notifications. In fact, it adds to the confusion. I was ignoring that part in problem posts on the issue because I write different data to my device to get it to respond. Thanks! Brett

jlia0 commented 3 years ago

Hello, do you have an example for notifications?

CocoaBob commented 2 years ago

I just figured it out, thanks to this answer (https://github.com/IanHarvey/bluepy/issues/378#issuecomment-632399819), we have to explicitly enable characteristic's notification with the following codes

myPeripheral = Peripheral("YOUR_DEVICE_MAC_ADDRESS").withDelegate(MyNotificationDelegate())
myCharacteristic = myPeripheral.getCharacteristics(uuid="CHARACTERISTIC_UUID")[0]
myPeripheral.writeCharacteristic(myCharacteristic.getHandle()+1, b"\x01\x00", True)

Which isn't mentioned anywhere in the doc 😂