added python script to push data to database

This commit is contained in:
Ryan Tang 2023-11-09 16:39:31 -05:00
parent 9f3e8fe000
commit 775626a2c4
4 changed files with 75 additions and 7 deletions

40
Listen2Arduino.py Executable file
View File

@ -0,0 +1,40 @@
#!/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:
for key, value in format_value.items():
file.write(f"{key} value={value}\n")
os.system(cmd)

View File

@ -1,7 +1,22 @@
# introduction
# Introduction
The interlock folder contains P1AM-100 code (which is Arduino MKX1000).
## setup using Arduino IDE 1.X
The Listen2Arduino.py is a script for listening the P1AM-100 output, and put the status, the tritium, Vaccum, and SubPump reading to the fsunuc.physics.fsu.edu database.
## Setup using Arduino IDE 1.X
The P1AM.h library is needed.
## Setup system service for the Listen2Arduino.py
copy the listen2P1AM.service to /etc/systemd/system/
run
sudo systemctl enable listen2P1AM.service
sudo systemctl start listen2P1AM.service
## interlock database at fsunuc.physics.fsu.edu
database name : interlock

View File

@ -118,19 +118,19 @@ void loop() {
Serial.print("State: ");
Serial.print(currentState);
Serial.print(". ");
Serial.print(";");
Serial.print("Tritium sensor: ");
Serial.print("Tritium: ");
Serial.print(tSniffer);
Serial.print(" mCr. ");
Serial.print(" mCr;");
Serial.print("Vaccum: ");
Serial.print(vacuum);
Serial.print(" Torr. ");
Serial.print(" Torr;");
Serial.print("SubPump: ");
Serial.print(subPump);
Serial.println(" amp.");
Serial.println(" amp;");
previousMillis = currentMillis; // Reset the timer
}

13
listen2P1AM.service Executable file
View File

@ -0,0 +1,13 @@
[Unit]
Description=Listening P1AM output
After=network.target # Adjust the target as needed
[Service]
ExecStart=/home/pi02/Multi-SNICS_Interlock/Listen2Arduino.py
#WorkingDirectory=/home/pi02/Multi-SNICS_Interlock/ # Optional, set the working directory
#Restart=always
#StartLimitIntervalSec=10
#StartLimitBurst=5
[Install]
WantedBy=multi-user.target