Skip to content

Instantly share code, notes, and snippets.

@jhagberg
Created February 5, 2018 09:38
Show Gist options
  • Save jhagberg/96359a36e87cd65545c2719f877bca28 to your computer and use it in GitHub Desktop.
Save jhagberg/96359a36e87cd65545c2719f877bca28 to your computer and use it in GitHub Desktop.
Mija Bluetoot temp reader Bluepy version
from bluepy import btle
class MyDelegate(btle.DefaultDelegate):
def __init__(self):
btle.DefaultDelegate.__init__(self)
# ... initialise here
def handleNotification(self, cHandle, data):
print("A notification was received: %s" %data)
# Initialisation -------
p = btle.Peripheral('4C:65:A8:D0:2E:19' )
p.setDelegate( MyDelegate() )
# Setup to turn notifications on, e.g.
setup_data = b"\x01\x00"
p.writeCharacteristic(0x10, setup_data)
# Main loop --------
while True:
if p.waitForNotifications(1.0):
# handleNotification() was called
continue
print( "Waiting...")
# Perhaps do something else here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment