From cfd6b2e289d52dba1255d5e3391ae868447808bc Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 8 Aug 2023 20:43:50 +0200 Subject: [PATCH] filename into var --- arduino-fridge-powercontrol.json | 2 +- main.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arduino-fridge-powercontrol.json b/arduino-fridge-powercontrol.json index f1e4bb1..0009a2c 100644 --- a/arduino-fridge-powercontrol.json +++ b/arduino-fridge-powercontrol.json @@ -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}} diff --git a/main.py b/main.py index 91457f1..9a2267b 100755 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ #!/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 @@ -8,7 +9,7 @@ import serial import time ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout = 6) - +outfile = "arduino-fridge-powercontrol.json" #time.sleep(3) #ser.readline() @@ -16,7 +17,7 @@ while 1: # ser.readline() Data = ser.readline().decode('ascii') print(Data) - outFile = open("arduino-fridge-powercontrol.json", "w") + outFile = open(outfile, "w") outFile.write(Data) outFile.close