Created
February 5, 2018 09:38
-
-
Save jhagberg/96359a36e87cd65545c2719f877bca28 to your computer and use it in GitHub Desktop.
Mija Bluetoot temp reader Bluepy version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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