Skip to content

Commit 5306766

Browse files
committed
basic read command Python script
1 parent ac5469b commit 5306766

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

scripts/bridge.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ def main():
187187
if command == 'SENSORS_SCAN':
188188
sensors.scan()
189189

190+
if command == 'SENSORS_READ':
191+
sensors.read()
192+
190193
# -------------------------------- Write block -----------------------------------
191194

192195
if command == 'START_WRITE':

scripts/sensors.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import threading
55
import time
6-
6+
from PSL.SENSORS.SHT21 import SHT21
77

88
class Sensors:
99
def __init__(self, I, file_write):
@@ -39,6 +39,22 @@ def capture_loop(self):
3939
if self.active_category == 'SCAN':
4040
self.scan()
4141

42+
def read(self):
43+
datetime_data = datetime.datetime.now()
44+
timestamp = time.time()
45+
46+
sensor = SHT21(self.device.I2C)
47+
data = sensor.getRaw()
48+
49+
self.file_write.update_buffer(
50+
"SENSORS", timestamp=timestamp, datetime=datetime_data, data='scan', value=data)
51+
time.sleep(0.25)
52+
53+
output = {'type': 'SENSORS_READ', 'data': data}
54+
print(json.dumps(output))
55+
sys.stdout.flush()
56+
57+
4258
def scan(self):
4359
datetime_data = datetime.datetime.now()
4460
timestamp = time.time()

0 commit comments

Comments
 (0)