filename into var

This commit is contained in:
Marcus 2023-08-08 20:43:50 +02:00
parent 472d14b048
commit cfd6b2e289
2 changed files with 4 additions and 3 deletions

View file

@ -1 +1 @@
{"1":{"temp":20.625,"state":true},"2":{"temp":20.875,"state":true}} {"1":{"temp":10.375,"state":false},"2":{"temp":-127,"state":false}}

View file

@ -1,5 +1,6 @@
#!/bin/python3 #!/bin/python3
# script to write json received by serial into a file
# bookmarks # bookmarks
# #
# threading: https://stackoverflow.com/questions/9848464/how-to-listen-to-http-requests-and-a-serial-channel-in-the-same-python-program # threading: https://stackoverflow.com/questions/9848464/how-to-listen-to-http-requests-and-a-serial-channel-in-the-same-python-program
@ -8,7 +9,7 @@ import serial
import time import time
ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout = 6) ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout = 6)
outfile = "arduino-fridge-powercontrol.json"
#time.sleep(3) #time.sleep(3)
#ser.readline() #ser.readline()
@ -16,7 +17,7 @@ while 1:
# ser.readline() # ser.readline()
Data = ser.readline().decode('ascii') Data = ser.readline().decode('ascii')
print(Data) print(Data)
outFile = open("arduino-fridge-powercontrol.json", "w") outFile = open(outfile, "w")
outFile.write(Data) outFile.write(Data)
outFile.close outFile.close