Skip to content

Commit

Permalink
basic read command Python script
Browse files Browse the repository at this point in the history
  • Loading branch information
orangecms committed Feb 20, 2021
1 parent 4fadcc0 commit c55cbb7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scripts/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def main():
if command == 'SENSORS_SCAN':
sensors.scan()

if command == 'SENSORS_READ':
sensors.read()

# -------------------------------- Write block -----------------------------------

if command == 'START_WRITE':
Expand Down
18 changes: 17 additions & 1 deletion scripts/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import threading
import time

from PSL.SENSORS.SHT21 import SHT21

class Sensors:
def __init__(self, I, file_write):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c55cbb7

Please sign in to comment.