use influx-client to push data
This commit is contained in:
parent
efa6d1d0b9
commit
7549f1d675
|
@ -8,6 +8,20 @@ import socket
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import influxdb_client
|
||||||
|
from influxdb_client import InfluxDBClient, Point, WritePrecision
|
||||||
|
from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS
|
||||||
|
|
||||||
|
#------ database
|
||||||
|
with open('ISEG_TOKEN.txt', 'r') as f:
|
||||||
|
token = f.readline()
|
||||||
|
|
||||||
|
org = "FSUFoxLab"
|
||||||
|
ip = "https://fsunuc.physics.fsu.edu/influx/"
|
||||||
|
write_client = influxdb_client.InfluxDBClient(url=ip, token=token, org=org)
|
||||||
|
bucket = "ISEG"
|
||||||
|
write_api = write_client.write_api(write_options=ASYNCHRONOUS)
|
||||||
|
|
||||||
#assign a port, to prevent the script run mulitple time
|
#assign a port, to prevent the script run mulitple time
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
host = socket.gethostname()
|
host = socket.gethostname()
|
||||||
|
@ -272,7 +286,8 @@ while True:
|
||||||
|
|
||||||
pushToDB = window["-DatabaseEnable-"].get()
|
pushToDB = window["-DatabaseEnable-"].get()
|
||||||
if pushToDB :
|
if pushToDB :
|
||||||
tempFile = open("temp.dat", "w")
|
points = []
|
||||||
|
#tempFile = open("temp.dat", "w")
|
||||||
|
|
||||||
for i in range(0, nChannel):
|
for i in range(0, nChannel):
|
||||||
window[("a%d" % chList[i])].update("%.3f" % outVList[i])
|
window[("a%d" % chList[i])].update("%.3f" % outVList[i])
|
||||||
|
@ -280,12 +295,16 @@ while True:
|
||||||
|
|
||||||
#==== To DataBase
|
#==== To DataBase
|
||||||
if pushToDB :
|
if pushToDB :
|
||||||
tempFile.write("Voltage,Ch=%d value=%f\n" % (chList[i], outVList[i]))
|
points.append(Point("Voltage").tag("Ch",int(chList[i])).field("value",float(outVList[i])))
|
||||||
tempFile.write("LeakageCurrent,Ch=%d value=%f\n" % (chList[i], outIList[i]*1e6))
|
points.append(Point("LeakageCurrent").tag("Ch",int(chList[i])).field("value",float(outIList[i])))
|
||||||
|
|
||||||
|
#tempFile.write("Voltage,Ch=%d value=%f\n" % (chList[i], outVList[i]))
|
||||||
|
#tempFile.write("LeakageCurrent,Ch=%d value=%f\n" % (chList[i], outIList[i]*1e6))
|
||||||
|
|
||||||
if pushToDB:
|
if pushToDB:
|
||||||
tempFile.close()
|
#tempFile.close()
|
||||||
os.system("curl -XPOST http://%s:8086/write?db=testing --data-binary @temp.dat" % databaseIP )
|
write_api.write(bucket=bucket, org=org, record=points)
|
||||||
|
#os.system("curl -XPOST http://%s:8086/write?db=testing --data-binary @temp.dat" % databaseIP )
|
||||||
|
|
||||||
|
|
||||||
window.close()
|
window.close()
|
||||||
|
|
|
@ -5,6 +5,20 @@ import os
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import influxdb_client
|
||||||
|
from influxdb_client import InfluxDBClient, Point, WritePrecision
|
||||||
|
from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS
|
||||||
|
|
||||||
|
#------ database
|
||||||
|
with open('ISEG_TOKEN.txt', 'r') as f:
|
||||||
|
token = f.readline()
|
||||||
|
|
||||||
|
org = "FSUFoxLab"
|
||||||
|
ip = "https://fsunuc.physics.fsu.edu/influx/"
|
||||||
|
write_client = influxdb_client.InfluxDBClient(url=ip, token=token, org=org)
|
||||||
|
bucket = "ISEG"
|
||||||
|
write_api = write_client.write_api(write_options=ASYNCHRONOUS)
|
||||||
|
|
||||||
#assign a port, to prevent the script run mulitple time
|
#assign a port, to prevent the script run mulitple time
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
host = socket.gethostname()
|
host = socket.gethostname()
|
||||||
|
@ -22,15 +36,20 @@ while True:
|
||||||
outVList = iseg.GetAllOutputHV()
|
outVList = iseg.GetAllOutputHV()
|
||||||
outIList = iseg.GetAllLC()
|
outIList = iseg.GetAllLC()
|
||||||
|
|
||||||
tempFile = open("temp.dat", "w")
|
# tempFile = open("temp.dat", "w")
|
||||||
|
points = []
|
||||||
|
|
||||||
for i in range(0, nChannel):
|
for i in range(0, nChannel):
|
||||||
tempFile.write("Voltage,Ch=%d value=%f\n" % (chList[i], outVList[i]))
|
# tempFile.write("Voltage,Ch=%d value=%f\n" % (chList[i], outVList[i]))
|
||||||
tempFile.write("LeakageCurrent,Ch=%d value=%f\n" % (chList[i], outIList[i]*1e6))
|
# tempFile.write("LeakageCurrent,Ch=%d value=%f\n" % (chList[i], outIList[i]*1e6))
|
||||||
|
points.append(Point("Voltage").tag("Ch",int(chList[i])).field("value",float(outVList[i])))
|
||||||
|
points.append(Point("LeakageCurrent").tag("Ch",int(chList[i])).field("value",float(outIList[i])))
|
||||||
|
|
||||||
|
|
||||||
|
# tempFile.close()
|
||||||
|
|
||||||
tempFile.close()
|
write_api.write(bucket=bucket, org=org, record=points)
|
||||||
|
# os.system("curl -XPOST http://128.186.111.107:8086/write?db=testing --data-binary @temp.dat")
|
||||||
os.system("curl -XPOST http://128.186.111.107:8086/write?db=testing --data-binary @temp.dat")
|
|
||||||
|
|
||||||
time.sleep(updateTime)
|
time.sleep(updateTime)
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,15 @@
|
||||||
in Ubuntu 20+
|
in Ubuntu 20+
|
||||||
|
|
||||||
~>sudo apt install python3-tk snmp snmp-mibs-downloader curl python3-pip
|
~>sudo apt install python3-tk snmp snmp-mibs-downloader curl python3-pip
|
||||||
~>python3 -m pip install pysimplegui
|
~>python3 -m pip install pysimplegui influxdb-client
|
||||||
|
|
||||||
also, download the https://fsunuc.physics.fsu.edu/wiki/images/5/53/WIENER-CRATE-MIB.txt and put in /usr/share/snmp/mibs/
|
also, download the https://fsunuc.physics.fsu.edu/wiki/images/5/53/WIENER-CRATE-MIB.txt and put in /usr/share/snmp/mibs/
|
||||||
|
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
~>python3 IsegHVController.py <IP>
|
~>python3 IsegHVController.py <IP>
|
||||||
|
|
||||||
|
# DataBase connection
|
||||||
|
|
||||||
|
for influxDB V1, simply put the database IP. since 2024, we upgraded to influxDB V2, a token is needed for secure connection. For Token, please check https://fsunuc.physics.fsu.edu/elog/fsunuc/28
|
Loading…
Reference in New Issue
Block a user