-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessSensor.py
49 lines (35 loc) · 1.16 KB
/
processSensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import socket
import logging
import time
import json
from raspi.detection.AccidentDetector import SensorBasedDetector
def main():
print("Starting Sensor Process")
with open("config.json") as jsonFile:
config = json.load(jsonFile)
sensorDetector = SensorBasedDetector(
config["detectionConfig"]["sensorDetectionConfig"]
)
host = "127.0.0.1"
port = 8080
sensorSocket = socket.socket()
sensorSocket.connect((host, port))
while True:
# FOR DEBUG PURPOSE ONLY #
# sensorSocket.send("SENSOR:TRUE".encode())
# time.sleep(1)
# continue
# END OF DEBUG BLOCK #
sensorResult = sensorDetector.detect()
if sensorResult == True:
previousValues = sensorDetector.readPreviousData()["accelerometer"]
previousValueString = ""
for value in previousValues:
previousValueString += "{};".format(value)
message = "SENSOR:TRUE;{}\n\r".format(previousValueString)
else:
message = "SENSOR:FALSE\n\r"
sensorSocket.send(message.encode())
# time.sleep(0.1)
if __name__ == "__main__":
main()