Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import struct
  2. from bluepy.btle import *
  3.  
  4. # callback class
  5. class MyDelegate(DefaultDelegate):
  6. def __init__(self):
  7. DefaultDelegate.__init__(self)
  8.  
  9. def handleNotification(self, cHandle, data):
  10. print(data)
  11.  
  12. # connect to device
  13. per = Peripheral("00:0B:57:1D:B3:93","public")
  14.  
  15. try:
  16. # set callback for notifications
  17. per.setDelegate(MyDelegate())
  18.  
  19. # enable notification
  20. setup_data = b"\x01\x00"
  21. notify = per.getCharacteristics(uuid='6e400003-b5a3-f393-e0a9-e50e24dcca9e')[0]
  22. notify_handle = notify.getHandle() + 1
  23. per.writeCharacteristic(notify_handle, setup_data, withResponse=True)
  24.  
  25. # send test string
  26. c = per.getCharacteristics(uuid='6e400002-b5a3-f393-e0a9-e50e24dcca9e')[0]
  27. c.write("Hello Gecko")
  28.  
  29. # wait for answer
  30. while True:
  31. if per.waitForNotifications(1.0):
  32. continue
  33. finally:
  34. per.disconnect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement