-
13515029 - Finiko Kasula Novenda authored6d35e848
getSerial.py 780 B
import serial, struct, time, urllib.request, json
with urllib.request.urlopen("https://tranquil-citadel-63668.herokuapp.com/api/status") as url:
data = json.loads(url.read().decode())
year = data['year']
ser = serial.Serial('COM8') # open serial port
print(ser.name) # check which port was really used
ser.write(struct.pack('>B',year + 48))
while True :
line = ser.readline()
raw = line.decode().split('\r\n')[0]
arr = raw.split(':')
humidity = arr[0]
light = arr[1]
#postUrl = "http://localhost/api-greentyno/updateStatus?humidity=" + humidity + "&light=" + light
#print(postUrl)
# print(humidity)
# print(light)
# with urllib.request.urlopen(postUrl) as url:
# print()# data = json.loads(url.read().decode())
ser.close() # close port