2023-08-10 02:37:14 +02:00
|
|
|
#!/bin/python3
|
|
|
|
|
|
|
|
# script to write json received by serial into a file
|
|
|
|
# bookmarks
|
|
|
|
#
|
|
|
|
# threading: https://stackoverflow.com/questions/9848464/how-to-listen-to-http-requests-and-a-serial-channel-in-the-same-python-program
|
|
|
|
# wait for serial input: https://stackoverflow.com/questions/13017840/using-pyserial-is-it-possible-to-wait-for-data
|
|
|
|
import serial
|
|
|
|
import time
|
|
|
|
|
|
|
|
ser = serial.Serial('/dev/ttyACM0', baudrate = 115200, timeout = 6)
|
|
|
|
outfile = "epever-tracer.json"
|
|
|
|
#time.sleep(3)
|
|
|
|
|
|
|
|
#ser.readline()
|
|
|
|
while 1:
|
|
|
|
# ser.readline()
|
|
|
|
Data = ser.readline().decode('ascii')
|
2023-08-13 04:11:45 +02:00
|
|
|
print("Data: ")
|
2023-08-10 02:37:14 +02:00
|
|
|
print(Data)
|
2023-08-13 04:11:45 +02:00
|
|
|
if len(Data) > 0:
|
|
|
|
outFile = open(outfile, "w")
|
|
|
|
outFile.write(Data)
|
|
|
|
outFile.close
|
2023-08-10 02:37:14 +02:00
|
|
|
|
|
|
|
##while 1:
|
|
|
|
## # { "command": "switch", "arg": "one", "state": "off", "ver":"1690931931"}
|
|
|
|
## userInput = input('> ')
|
|
|
|
## ser.write(str(userInput).encode('ascii'))
|
|
|
|
## arduinoData = ser.readline().decode('ascii')
|
|
|
|
## print(arduinoData)
|
|
|
|
|
|
|
|
|
|
|
|
##def getValues():
|
|
|
|
## #ser.write(b'g')
|
|
|
|
## lol = "g"
|
|
|
|
## ser.write(str(lol).encode('ascii'))
|
|
|
|
## arduinoData = ser.readline().decode('ascii')
|
|
|
|
## return arduinoData
|
|
|
|
##
|
|
|
|
##while 1:
|
|
|
|
## userInput = input('Get data point?')
|
|
|
|
##
|
|
|
|
## if userInput == 'y':
|
|
|
|
## print(getValues())
|
|
|
|
|