arduino-fridge-powercontrol/main.py

45 lines
1.2 KiB
Python
Raw Normal View History

2023-08-01 23:38:12 +02:00
#!/bin/python3
2023-08-08 20:43:50 +02:00
# script to write json received by serial into a file
2023-08-02 01:14:05 +02:00
# 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
2023-08-01 23:38:12 +02:00
import serial
import time
2023-08-07 01:19:09 +02:00
ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout = 6)
2023-08-08 20:43:50 +02:00
outfile = "arduino-fridge-powercontrol.json"
2023-08-02 01:04:39 +02:00
#time.sleep(3)
2023-08-01 23:38:12 +02:00
2023-08-07 01:07:42 +02:00
#ser.readline()
2023-08-02 01:04:39 +02:00
while 1:
2023-08-07 01:07:42 +02:00
# ser.readline()
Data = ser.readline().decode('ascii')
print(Data)
2023-08-08 20:43:50 +02:00
outFile = open(outfile, "w")
2023-08-07 01:27:10 +02:00
outFile.write(Data)
outFile.close
2023-08-07 01:07:42 +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)
2023-08-01 23:38:12 +02:00
2023-08-02 01:04:39 +02:00
##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())
2023-08-01 23:38:12 +02:00