Skip to content
Snippets Groups Projects
pythonRead.py 1.09 KiB
import serial, urllib.request, json, time, struct

with urllib.request.urlopen("https://tranquil-citadel-63668.herokuapp.com/api/status") as url:
    data = json.loads(url.read().decode())

year = data['year']

# data['year'] = 4

# params = json.dumps(data).encode('utf8')
# req = urllib.request.Request('https://tranquil-citadel-63668.herokuapp.com/api/status',
                            # data=params,headers={'Content-Type': 'application/json'})

# response = urllib.request.urlopen(req)
# response = urllib.request.urlopen(req, json.dumps(data))
# print(response.read().decode('utf8'))

ser = serial.Serial()
ser.baudrate = 19200
ser.port = 'COM8'
ser.timeout = 1

ser.open()
ser.flush()

time.sleep(3)
# ser.write(b'1')
# print(struct.pack('b', data['year']))
# ser.write(struct.pack('b',data['year']))
# b = ser.readline()
# time.sleep(2)
ser_bytes = ser.readline()
decoded_bytes = int(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
print(decoded_bytes)
# print(struct.unpack('p',ser.read()))
# print(b)
# print(ser.readable)
# print(ser.readline())
# print(struct.unpack('<i',ser.readline()))
ser.close()