2023-11-09 16:39:31 -05:00
|
|
|
#!/usr/bin/python
|
|
|
|
import serial
|
|
|
|
import os
|
2024-03-11 13:00:09 -04:00
|
|
|
from datetime import datetime
|
2023-11-09 16:39:31 -05:00
|
|
|
|
2024-02-27 18:54:59 -05:00
|
|
|
import influxdb_client
|
|
|
|
from influxdb_client import InfluxDBClient, Point, WritePrecision
|
|
|
|
from influxdb_client.client.write_api import SYNCHRONOUS
|
|
|
|
|
2024-05-09 15:16:30 -04:00
|
|
|
with open('/home/pi03/influx_token.txt', 'r') as f:
|
2024-02-27 18:54:59 -05:00
|
|
|
first_line = f.readline()
|
|
|
|
|
|
|
|
|
|
|
|
#token = os.environ.get("INFLUXDB_TOKEN")
|
2024-05-09 15:51:27 -04:00
|
|
|
token = first_line.replace('\n', "")
|
2024-02-27 18:54:59 -05:00
|
|
|
org = "FSUFoxLab"
|
|
|
|
ip = "https://fsunuc.physics.fsu.edu/influx/"
|
|
|
|
write_client = influxdb_client.InfluxDBClient(url=ip, token=token, org=org)
|
2024-02-27 19:04:34 -05:00
|
|
|
bucket = "interlock"
|
2024-02-27 18:54:59 -05:00
|
|
|
write_api = write_client.write_api(write_options=SYNCHRONOUS)
|
|
|
|
|
|
|
|
print(token)
|
|
|
|
|
2023-11-09 16:39:31 -05:00
|
|
|
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
|
|
|
|
ser.reset_input_buffer()
|
|
|
|
|
2024-05-09 15:16:30 -04:00
|
|
|
outFile = "/home/pi03/data.txt"
|
2023-11-09 16:39:31 -05:00
|
|
|
|
2024-02-27 18:54:59 -05:00
|
|
|
# cmd='curl -s -XPOST "http://fsunuc.physics.fsu.edu:8086/write?db=interlock" --data-binary @/home/pi02/data.txt'
|
2023-11-09 16:39:31 -05:00
|
|
|
|
2024-02-08 17:34:00 -05:00
|
|
|
OPEN = 0
|
|
|
|
CLOSED = 1
|
|
|
|
|
|
|
|
input_normal= [
|
2024-03-05 11:47:41 -05:00
|
|
|
OPEN, #// 1 Reset switch
|
|
|
|
CLOSED, #// 2 Emergency source trip switch
|
|
|
|
CLOSED, #// 3 Cage door contact
|
|
|
|
CLOSED, #// 4 Fume hood flow switch
|
|
|
|
OPEN, #// 5 Vacuum condition - gnd
|
|
|
|
CLOSED, #// 6 Tritium monitor
|
2024-03-20 12:42:15 -04:00
|
|
|
OPEN, #// 7 Control Room Emergency Switch
|
2024-03-05 11:47:41 -05:00
|
|
|
CLOSED, #// 8 Power failure
|
|
|
|
CLOSED, #// 9 Coolant flow - gnd
|
|
|
|
OPEN, #//10 Vacuum condition - mid
|
|
|
|
OPEN, #//11 UNUSED
|
|
|
|
CLOSED, #//12 Coolant flow - high
|
|
|
|
OPEN, #//13 Smoke detector - high
|
|
|
|
OPEN, #//14 UNUSED
|
|
|
|
OPEN, #//15 UNUSED
|
|
|
|
OPEN #//16 UNUSED
|
2024-02-08 17:34:00 -05:00
|
|
|
]
|
|
|
|
|
2024-03-05 11:47:41 -05:00
|
|
|
in_txt = [ "Reset Button", #1
|
|
|
|
"Emergency Switch", #2
|
|
|
|
"Cage Door Open", #3
|
|
|
|
"Fume Hood Flow", #4
|
|
|
|
"Vacuum Gauge 2", #5
|
|
|
|
"Tritium Monitor", #6
|
2024-03-20 12:42:15 -04:00
|
|
|
"Emergency Switch", #7
|
2024-03-05 11:47:41 -05:00
|
|
|
"Bldg Power Fail", #8
|
|
|
|
"Coolant Flow 2", #9
|
|
|
|
"Vacuum Gauge 1", #10
|
|
|
|
"error: port map", #11
|
|
|
|
"Coolant Flow 1", #12
|
|
|
|
"Smoke at Source", #13
|
|
|
|
"error: port map", #14
|
|
|
|
"error: port map", #15
|
|
|
|
"error: port map" #16
|
|
|
|
]
|
|
|
|
|
|
|
|
in_short_txt = [
|
|
|
|
"ResetButton", #1
|
|
|
|
"EmergencySwitch", #2
|
|
|
|
"CageDoorOpen", #3
|
|
|
|
"FumeHoodFlow", #4
|
|
|
|
"VacuumGauge2", #5
|
|
|
|
"TritiumMonitor", #6
|
2024-03-20 12:42:15 -04:00
|
|
|
"EmergencySwitch", #7
|
2024-03-05 11:47:41 -05:00
|
|
|
"BldgPowerFail", #8
|
|
|
|
"CoolantFlow2", #9
|
|
|
|
"VacuumGauge1", #10
|
|
|
|
"NotUsed", #11
|
|
|
|
"CoolantFlow1", #12
|
|
|
|
"SmokeAtSource", #13
|
|
|
|
"NotUsed", #14
|
|
|
|
"NotUsed", #15
|
|
|
|
"NotUsed" #16
|
|
|
|
]
|
2024-02-08 17:34:00 -05:00
|
|
|
|
2023-11-09 16:39:31 -05:00
|
|
|
while True:
|
|
|
|
if ser.in_waiting > 0:
|
|
|
|
line = ser.readline().decode('utf-8').rstrip()
|
|
|
|
|
2024-02-08 17:34:00 -05:00
|
|
|
list = []
|
2023-11-09 16:39:31 -05:00
|
|
|
components = line.split(';')
|
|
|
|
format_value = {}
|
|
|
|
|
|
|
|
for component in components:
|
|
|
|
parts = component.strip().split(': ')
|
|
|
|
if len(parts) == 2:
|
|
|
|
key, valueUnit = parts
|
|
|
|
part2 = valueUnit.split(' ')
|
|
|
|
if len(part2) == 2:
|
|
|
|
value, unit = part2
|
2024-02-08 17:34:00 -05:00
|
|
|
if value == "ovf" :
|
|
|
|
value = 99999
|
2023-11-09 16:39:31 -05:00
|
|
|
format_value[key] = value
|
|
|
|
else:
|
|
|
|
format_value[key] = valueUnit
|
2024-02-08 17:34:00 -05:00
|
|
|
else:
|
|
|
|
list.append(component)
|
2023-11-09 16:39:31 -05:00
|
|
|
|
2024-02-08 17:34:00 -05:00
|
|
|
# print(line)
|
2024-02-27 18:54:59 -05:00
|
|
|
point = Point("Measurement")
|
|
|
|
point2 = Point("Status")
|
2024-03-05 11:47:41 -05:00
|
|
|
point3 = Point("Input")
|
2023-11-09 16:39:31 -05:00
|
|
|
|
2024-02-27 18:54:59 -05:00
|
|
|
for key, value in format_value.items():
|
|
|
|
# print(f"{key} value={value}")
|
2024-02-27 19:04:34 -05:00
|
|
|
point.field(key, float(value))
|
2023-11-09 16:39:31 -05:00
|
|
|
|
|
|
|
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")
|
2024-02-27 18:54:59 -05:00
|
|
|
|
|
|
|
point2.field("preaccl", 1).field("valve1", 1).field("valve2", 1).field("hv", 1).field("boiler", 1).field("ion",1)
|
|
|
|
|
2024-01-17 15:01:35 -05:00
|
|
|
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")
|
2024-02-27 18:54:59 -05:00
|
|
|
|
|
|
|
point2.field("preaccl", 0).field("valve1", 1).field("valve2", 1).field("hv", 0).field("boiler", 1).field("ion",1)
|
|
|
|
|
2024-01-17 15:01:35 -05:00
|
|
|
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")
|
2024-02-27 18:54:59 -05:00
|
|
|
|
|
|
|
point2.field("preaccl", 0).field("valve1", 0).field("valve2", 0).field("hv", 0).field("boiler", 1).field("ion",0)
|
|
|
|
|
2024-01-17 15:01:35 -05:00
|
|
|
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")
|
2024-02-27 18:54:59 -05:00
|
|
|
|
|
|
|
point2.field("preaccl", 0).field("valve1", 0).field("valve2", 0).field("hv", 0).field("boiler", 0).field("ion",0)
|
2024-02-08 17:34:00 -05:00
|
|
|
|
|
|
|
for i in range(16):
|
2024-03-05 11:47:41 -05:00
|
|
|
if in_short_txt[i] == "NotUsed" :
|
|
|
|
continue
|
|
|
|
point3.field(in_short_txt[i], int(list[i]))
|
2024-02-08 17:34:00 -05:00
|
|
|
if int(list[i]) != input_normal[i]:
|
|
|
|
file.write(f"#{i}--{in_txt[i]}\n")
|
2023-11-09 16:39:31 -05:00
|
|
|
|
2024-02-27 18:54:59 -05:00
|
|
|
try:
|
|
|
|
# os.system(cmd)
|
2024-03-11 13:00:09 -04:00
|
|
|
now = datetime.now() # current date and time
|
|
|
|
date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
|
|
|
|
print("==================== date-time:", date_time )
|
2024-02-27 18:54:59 -05:00
|
|
|
print(point)
|
|
|
|
print(point2)
|
2024-03-05 11:47:41 -05:00
|
|
|
print(point3)
|
2024-02-27 18:54:59 -05:00
|
|
|
write_api.write(bucket=bucket, org=org, record=point)
|
|
|
|
write_api.write(bucket=bucket, org=org, record=point2)
|
2024-03-05 11:47:41 -05:00
|
|
|
write_api.write(bucket=bucket, org=org, record=point3)
|
2024-02-27 18:54:59 -05:00
|
|
|
except:
|
|
|
|
print("problem pushing data")
|