From 775626a2c4bf38bfddc7ed429ce9a2d5805ff822 Mon Sep 17 00:00:00 2001 From: "Ryan@pi02" Date: Thu, 9 Nov 2023 16:39:31 -0500 Subject: [PATCH] added python script to push data to database --- Listen2Arduino.py | 40 ++++++++++++++++++++++++++++++++++++++++ README.md | 19 +++++++++++++++++-- interlock/interlock.ino | 10 +++++----- listen2P1AM.service | 13 +++++++++++++ 4 files changed, 75 insertions(+), 7 deletions(-) create mode 100755 Listen2Arduino.py create mode 100755 listen2P1AM.service diff --git a/Listen2Arduino.py b/Listen2Arduino.py new file mode 100755 index 0000000..2967930 --- /dev/null +++ b/Listen2Arduino.py @@ -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) diff --git a/README.md b/README.md index e8a9f0d..5629a1d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/interlock/interlock.ino b/interlock/interlock.ino index 12eecce..9259d76 100644 --- a/interlock/interlock.ino +++ b/interlock/interlock.ino @@ -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 } diff --git a/listen2P1AM.service b/listen2P1AM.service new file mode 100755 index 0000000..bfa6d4a --- /dev/null +++ b/listen2P1AM.service @@ -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