Skip to content

Instantly share code, notes, and snippets.

@sowbug
Created August 28, 2018 04:30
Show Gist options
  • Save sowbug/ef5bb8886fbfa949cf47e492ddcb8b50 to your computer and use it in GitHub Desktop.
Save sowbug/ef5bb8886fbfa949cf47e492ddcb8b50 to your computer and use it in GitHub Desktop.
import binascii
from bluepy import btle
from bluepy.btle import DefaultDelegate
class MyDelegate(btle.DefaultDelegate):
def __init__(self, params):
btle.DefaultDelegate.__init__(self)
def handleNotification(self, cHandle, data):
print "SOMETHING HAPPENED %s" % (binascii.hexlify(data))
p = btle.Peripheral("f6:c3:37:01:ee:36", btle.ADDR_TYPE_RANDOM)
p.withDelegate(MyDelegate(None))
buttonCharacteristic = p.getCharacteristics(uuid="99c31525-dc4f-41b1-bb04-4e4deb81fadd")[0]
setup_data = b"\x01\x00"
notify_handle = buttonCharacteristic.getHandle() + 1
p.writeCharacteristic(notify_handle, setup_data, withResponse=True)
print "Connected!"
while True:
print "Waiting..."
if p.waitForNotifications(5.0):
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment