cs161079
5 years ago
5 changed files with 49 additions and 9 deletions
@ -0,0 +1,38 @@ |
|||
#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras |
|||
#=================================================================== |
|||
#!/usr/bin/env python |
|||
|
|||
import json |
|||
import requests |
|||
|
|||
|
|||
server_ip = "iot-smart-parking.herokuapp.com" |
|||
server_port = "443" |
|||
API_ENDPOINT = 'https://' + 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 doc[str(park)] == 1: |
|||
parking = park |
|||
break |
|||
|
|||
print ("Free parking is Number: " + parking) |
|||
ser.write("b'" + parking + "'") |
|||
ser.flush() |
|||
except (NameError, TypeError) as e: |
|||
print ("No free parking") |
|||
except requests.exceptions.ConnectionError: |
|||
print("No Internet access") |
Loading…
Reference in new issue