Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import struct
- from bluepy.btle import *
- # callback class
- class MyDelegate(DefaultDelegate):
- def __init__(self):
- DefaultDelegate.__init__(self)
- def handleNotification(self, cHandle, data):
- print(data)
- # connect to device
- per = Peripheral("00:0B:57:1D:B3:93","public")
- try:
- # set callback for notifications
- per.setDelegate(MyDelegate())
- # enable notification
- setup_data = b"\x01\x00"
- notify = per.getCharacteristics(uuid='6e400003-b5a3-f393-e0a9-e50e24dcca9e')[0]
- notify_handle = notify.getHandle() + 1
- per.writeCharacteristic(notify_handle, setup_data, withResponse=True)
- # send test string
- c = per.getCharacteristics(uuid='6e400002-b5a3-f393-e0a9-e50e24dcca9e')[0]
- c.write("Hello Gecko")
- # wait for answer
- while True:
- if per.waitForNotifications(1.0):
- continue
- finally:
- per.disconnect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement