From 434ad49ee409dff9747bad5906234670fcd747fd Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 6 Jun 2020 12:47:27 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 33 +++++++++++++----------------- tools/pop/pop.py | 43 +++++++++++++++++++++------------------- tools/pop/startpopdaemon | 2 +- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 8d706cc..3dde7a4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,14 +3,8 @@ - - - - - - - - + + @@ -1229,10 +1224,10 @@ - + - + diff --git a/tools/pop/pop.py b/tools/pop/pop.py index 88a2b29..81f927a 100644 --- a/tools/pop/pop.py +++ b/tools/pop/pop.py @@ -7,12 +7,13 @@ import sys device = sys.argv[1] map = ['', '', 'tap', 'long', 'double'] -rooms = {'wc': 'wc', 'sdb':'sdb'} -macs = {'wc': 'a0:e6:f8:db:ff:2f','sdb':'a0:e6:f8:dc:01:d7'} +rooms = {'wc': 'wc', 'sdb': 'sdb'} +macs = {'wc': 'a0:e6:f8:db:ff:2f', 'sdb': 'a0:e6:f8:dc:01:d7'} mac = macs[device] room = rooms[device] + class MyDelegate(btle.DefaultDelegate): def __init__(self): btle.DefaultDelegate.__init__(self) @@ -34,28 +35,30 @@ print("Connecting to " + mac + " (" + device + ")") while True: # Initialisation ------- + print("Connecting") try: p = btle.Peripheral(mac, btle.ADDR_TYPE_PUBLIC) - except btle.BTLEDisconnectError: - continue + p.setDelegate(MyDelegate()) - p.setDelegate(MyDelegate()) + # Setup to turn notifications on, e.g. + svc = p.getServiceByUUID("0000fe61-0000-1000-8000-00805f9b34fb") + ch = svc.getCharacteristics()[0] - # 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, b'\x02\x00') - # Main loop -------- - p.writeCharacteristic(ch.valHandle+1, b'\x02\x00') + while True: + try: + if p.waitForNotifications(30.0): + # handleNotification() was called + continue - 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 - print("Waiting...") - # Perhaps do something else here - except: - print("Disconnected... Waiting for reconnection...") - break + except btle.BTLEDisconnectError: + print("Disconnect error") + continue diff --git a/tools/pop/startpopdaemon b/tools/pop/startpopdaemon index aafdab7..b3fbae3 100644 --- a/tools/pop/startpopdaemon +++ b/tools/pop/startpopdaemon @@ -1,2 +1,2 @@ #!/bin/sh -/sbin/start-stop-daemon --start --quiet --user root --chuid root --name pop-$1 --make-pidfile --pidfile /var/run/pop-$1.pid --background --startas /bin/bash -- -c "exec /var/www/home/tools/pop/pop.py $1 >> /var/log/pop/$1.log" \ No newline at end of file +/sbin/start-stop-daemon --start --quiet --user root --chuid root --name pop-$1 --make-pidfile --pidfile /var/run/pop-$1.pid --background --startas /bin/bash -- -c "exec /var/www/home/tools/pop/pop.py $1 >> /var/log/pop/$1.log 2>&1" \ No newline at end of file -- 2.39.5