2023-11-09 16:39:31 -05:00
|
|
|
#!/usr/bin/python
|
|
|
|
import serial
|
|
|
|
import os
|
|
|
|
|
|
|
|
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
|
|
|
|
ser.reset_input_buffer()
|
|
|
|
|
|
|
|
outFile = "/home/pi02/data.txt"
|
|
|
|
|
|
|
|
cmd='curl -s -XPOST "http://fsunuc.physics.fsu.edu:8086/write?db=interlock" --data-binary @/home/pi02/data.txt'
|
|
|
|
|
|
|
|
while True:
|
|
|
|
if ser.in_waiting > 0:
|
|
|
|
line = ser.readline().decode('utf-8').rstrip()
|
|
|
|
|
|
|
|
components = line.split(';')
|
|
|
|
format_value = {}
|
|
|
|
|
|
|
|
for component in components:
|
|
|
|
#print(component)
|
|
|
|
parts = component.strip().split(': ')
|
|
|
|
if len(parts) == 2:
|
|
|
|
key, valueUnit = parts
|
|
|
|
part2 = valueUnit.split(' ')
|
|
|
|
if len(part2) == 2:
|
|
|
|
value, unit = part2
|
|
|
|
format_value[key] = value
|
|
|
|
else:
|
|
|
|
format_value[key] = valueUnit
|
|
|
|
|
|
|
|
#print(line)
|
|
|
|
|
|
|
|
#for key, value in format_value.items():
|
|
|
|
# print(f"{key} value={value}")
|
|
|
|
|
|
|
|
with open(outFile, "w") as file:
|
2024-01-17 15:01:35 -05:00
|
|
|
for key, value in format_value.items():
|
|
|
|
file.write(f"{key} value={value}\n")
|
|
|
|
if key == "State" :
|
|
|
|
if value == "0" or value == "1":
|
|
|
|
file.write(f"preaccl value=1\n")
|
|
|
|
file.write(f"valve1 value=1\n")
|
|
|
|
file.write(f"valve2 value=1\n")
|
|
|
|
file.write(f"hv value=1\n")
|
|
|
|
file.write(f"boiler value=1\n")
|
|
|
|
file.write(f"ion value=1\n")
|
|
|
|
if value == "2":
|
|
|
|
file.write(f"preaccl value=0\n")
|
|
|
|
file.write(f"valve1 value=1\n")
|
|
|
|
file.write(f"valve2 value=1\n")
|
|
|
|
file.write(f"hv value=0\n")
|
|
|
|
file.write(f"boiler value=1\n")
|
|
|
|
file.write(f"ion value=1\n")
|
|
|
|
if value == "3":
|
|
|
|
file.write(f"preaccl value=0\n")
|
|
|
|
file.write(f"valve1 value=0\n")
|
|
|
|
file.write(f"valve2 value=0\n")
|
|
|
|
file.write(f"hv value=0\n")
|
|
|
|
file.write(f"boiler value=1\n")
|
|
|
|
file.write(f"ion value=0\n")
|
|
|
|
if value == "4":
|
|
|
|
file.write(f"preaccl value=0\n")
|
|
|
|
file.write(f"valve1 value=0\n")
|
|
|
|
file.write(f"valve2 value=0\n")
|
|
|
|
file.write(f"hv value=0\n")
|
|
|
|
file.write(f"boiler value=0\n")
|
|
|
|
file.write(f"ion value=0\n")
|
2023-11-09 16:39:31 -05:00
|
|
|
|
|
|
|
os.system(cmd)
|