diff --git a/IsegHVController.py b/IsegHVController.py index c4b1087..2db59f7 100755 --- a/IsegHVController.py +++ b/IsegHVController.py @@ -8,6 +8,20 @@ import socket import sys 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 s = socket.socket() host = socket.gethostname() @@ -272,7 +286,8 @@ while True: pushToDB = window["-DatabaseEnable-"].get() if pushToDB : - tempFile = open("temp.dat", "w") + points = [] + #tempFile = open("temp.dat", "w") for i in range(0, nChannel): window[("a%d" % chList[i])].update("%.3f" % outVList[i]) @@ -280,12 +295,16 @@ while True: #==== To DataBase if pushToDB : - 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)) + 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.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: - tempFile.close() - os.system("curl -XPOST http://%s:8086/write?db=testing --data-binary @temp.dat" % databaseIP ) + #tempFile.close() + 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() diff --git a/IsegHVDataBase.py b/IsegHVDataBase.py index 68ecd09..0664c27 100755 --- a/IsegHVDataBase.py +++ b/IsegHVDataBase.py @@ -5,6 +5,20 @@ import os import socket 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 s = socket.socket() host = socket.gethostname() @@ -22,15 +36,20 @@ while True: outVList = iseg.GetAllOutputHV() outIList = iseg.GetAllLC() - tempFile = open("temp.dat", "w") + # tempFile = open("temp.dat", "w") + points = [] for i in range(0, nChannel): - 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("Voltage,Ch=%d value=%f\n" % (chList[i], outVList[i])) + # 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() - - os.system("curl -XPOST http://128.186.111.107:8086/write?db=testing --data-binary @temp.dat") + 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") time.sleep(updateTime) diff --git a/README.md b/README.md index 86f0c6e..d5cfe55 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,15 @@ in Ubuntu 20+ ~>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/ + # Usage ~>python3 IsegHVController.py +# 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 \ No newline at end of file