From c55cbb7f8d36aef22af6a0cc037b16dd62e3cd32 Mon Sep 17 00:00:00 2001 From: Daniel Maslowski Date: Sat, 1 Aug 2020 22:55:32 +0200 Subject: [PATCH] basic read command Python script --- scripts/bridge.py | 3 +++ scripts/sensors.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/bridge.py b/scripts/bridge.py index ea6169e8..76b57f4a 100755 --- a/scripts/bridge.py +++ b/scripts/bridge.py @@ -187,6 +187,9 @@ def main(): if command == 'SENSORS_SCAN': sensors.scan() + if command == 'SENSORS_READ': + sensors.read() + # -------------------------------- Write block ----------------------------------- if command == 'START_WRITE': diff --git a/scripts/sensors.py b/scripts/sensors.py index 0caf9d4b..55613021 100644 --- a/scripts/sensors.py +++ b/scripts/sensors.py @@ -3,7 +3,7 @@ import sys import threading import time - +from PSL.SENSORS.SHT21 import SHT21 class Sensors: def __init__(self, I, file_write): @@ -39,6 +39,22 @@ def capture_loop(self): if self.active_category == 'SCAN': self.scan() + def read(self): + datetime_data = datetime.datetime.now() + timestamp = time.time() + + sensor = SHT21(self.device.I2C) + data = sensor.getRaw() + + self.file_write.update_buffer( + "SENSORS", timestamp=timestamp, datetime=datetime_data, data='scan', value=data) + time.sleep(0.25) + + output = {'type': 'SENSORS_READ', 'data': data} + print(json.dumps(output)) + sys.stdout.flush() + + def scan(self): datetime_data = datetime.datetime.now() timestamp = time.time()