Skip to content

Commit

Permalink
Handling keyboard interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
attermann committed Dec 12, 2020
1 parent 56b2ef4 commit d9aef69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# viatom-ble
Python script to read sensor values over BLE from Viatom ring oxygen (SpO2) monitors.
Python script to read sensor values over BLE from Viatom wearable ring oxygen (SpO2) monitors.

Reads values once every 2 second and logs to console or log file. Also publishes values to an MQTT broker if configured.
Reads values once every 2 second and logs to console or log file. Also publishes values to an MQTT broker if so configured.

## Compatability
Tested against a Viatom model PO3 (Wellue KidsO2) during development.
Expand All @@ -16,9 +16,9 @@ sudo pip install blueply
sudo pip install paho-mqtt
```

Scan devices while wearing the device to determine it's BLE address.
Scan while wearing the device to determine it's BLE address.

*Note: Be sure the device is not connected to any other monitor (ie the mobile app) before scanning.*
*Note: Ensure the device is not connected to any other monitor (ie the mobile app) before scanning.*

```
sudo python viatom-ble.py -s
Expand All @@ -32,7 +32,7 @@ Optionally also configure the MQTT client by enering values for the `mqtt_*` var

Test BLE connectivity while wearing the device.

*Note: Warnings and exceptions from the MQTT client can be ignored if it has not been confgured yet.
*Note: Warnings and exceptions from the MQTT client can be ignored if it has not been confgured yet.*

```
python viatom-ble.py -v -c
Expand Down
24 changes: 20 additions & 4 deletions viatom-ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def ble_scan():

# ble config params
# ble address of device
ble_address = ""
ble_address = "f3:ce:82:50:0c:a5"
ble_type = btle.ADDR_TYPE_RANDOM
# seconds to wait between reads
ble_read_period = 2
Expand Down Expand Up @@ -246,9 +246,25 @@ def ble_scan():
except IOError as e:
logger.error("IOError: " + str(e))

logger.info("BLE: Waiting " + str(ble_next_reconnect_delay) + " seconds to reconnect...")
time.sleep(ble_next_reconnect_delay);
ble_next_reconnect_delay = ble_reconnect_delay
except KeyboardInterrupt:
logger.info("KeyboardInterrupt, exiting")
sys.exit()

except:
e = sys.exc_info()[0]
logger.error("Exception: " + str(e))

try:
logger.info("BLE: Waiting " + str(ble_next_reconnect_delay) + " seconds to reconnect...")
time.sleep(ble_next_reconnect_delay);
ble_next_reconnect_delay = ble_reconnect_delay
except KeyboardInterrupt:
logger.info("KeyboardInterrupt, exiting")
sys.exit()
except:
e = sys.exc_info()[0]
logger.error("Exception: " + str(e))


logger.info("Exiting...")
client.loop_stop()
Expand Down

0 comments on commit d9aef69

Please sign in to comment.