Smart and Autonomous parking.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.0 KiB

#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras
#===================================================================
#!/usr/bin/env python
import json
import requests
import serial
server_ip = "192.168.1.13"#"iot-smart-parking.herokuapp.com"
server_port = "8080"#"443"
API_ENDPOINT = 'http://' + server_ip + ':' + server_port + '/'
try:
ser = serial.Serial(
port='/dev/ttyACM0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
c = requests.get(url=API_ENDPOINT, params = {})
doc = c.json()
parking = None
for park in doc:
if park['status'] == True:
parking = park #{"no": park['no'], "status": park['status']}
break
print ("Free parking is Number: " + str(parking['no']))
ser.flush()
ser.write(str.encode(str(parking['no'])))
# ser.write("b'" + parking['no'] + "'")
ser.flush()
except (NameError, TypeError) as e:
print ("No free parking" + str(e))
except requests.exceptions.ConnectionError:
print("No Internet access" + str(e))