From: Vincent Date: Tue, 3 Sep 2019 07:50:31 +0000 (+0200) Subject: . X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=5988ffcf2d9be30dd5495ad59ae362ce7b01f1b8;p=tortuga-home.git . --- diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3987d1a..3fff1a2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,8 @@ - - - + - - - - - - - @@ -240,6 +231,13 @@ + + + + + + + diff --git a/tools/pop/pop.py b/tools/pop/pop.py index 9f8ea29..0b26b6f 100644 --- a/tools/pop/pop.py +++ b/tools/pop/pop.py @@ -1,32 +1,58 @@ #!/usr/bin/python from bluepy import btle +from urllib2 import urlopen +import sys + +device = sys.argv[1] +room = sys.argv[2] +mac = sys.argv[3] + +map = ['', '', 'tap', 'long', 'double'] + class MyDelegate(btle.DefaultDelegate): def __init__(self): btle.DefaultDelegate.__init__(self) def handleNotification(self, cHandle, data): - print("A notification was received: %s" %data) - -# Initialisation ------- -#p = btle.Peripheral("a0:e6:f8:dc:01:d7", btle.ADDR_TYPE_RANDOM) -p = btle.Peripheral("a0:e6:f8:db:ff:2f", btle.ADDR_TYPE_PUBLIC) -p.setDelegate( MyDelegate() ) - -# Setup to turn notifications on, e.g. -svc = p.getServiceByUUID("0000fe61-0000-1000-8000-00805f9b34fb") -ch = svc.getCharacteristics()[0] -print(ch.valHandle) + cmd = map[ord(data[0])] + print("Notification was received %s" % cmd) + req = "https://" + room + ".home.tortuga.enhydra.fr/scripts/pop.php?button=" + device + "&action=" + cmd + try: + urlopen(req) + except: + print('request timeout') -# Main loop -------- + print("A notification was handled: %s (%s)" % (cmd, req)) -p.writeCharacteristic(ch.valHandle+1, "\x02\x00") +print("Connecting to " + mac + " (" + device + ")") while True: - if p.waitForNotifications(1.0): - # handleNotification() was called + # Initialisation ------- + try: + p = btle.Peripheral(mac, btle.ADDR_TYPE_PUBLIC) + except btle.BTLEDisconnectError: continue - print("Waiting...") - # Perhaps do something else here \ No newline at end of file + p.setDelegate(MyDelegate()) + + # Setup to turn notifications on, e.g. + svc = p.getServiceByUUID("0000fe61-0000-1000-8000-00805f9b34fb") + ch = svc.getCharacteristics()[0] + + # Main loop -------- + + # p.writeCharacteristic(ch.valHandle+1, "\x02\x00") + + while True: + try: + if p.waitForNotifications(1.0): + # handleNotification() was called + continue + + print("Waiting...") + # Perhaps do something else here + except: + print("Disconnected... Waiting for reconnection...") + break