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.

54 lines
1.9 KiB

5 years ago
#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras
#===================================================================
#!/usr/bin/env python
import time
import serial
import requests
5 years ago
import json
5 years ago
# Open file to configure communication with server.
5 years ago
with open('/home/pi/project/data.json', 'r') as json_file:
5 years ago
json_data = json_file.read()
if json_data != "" and json_data != None:
server_par = json.loads(json_data.replace('\n','').replace(' ',''))
5 years ago
server_ip = server_par['ip']
server_port = server_par['port']
if server_ip != None and server_port != None:
API_ENDPOINT = 'http://' + server_ip + ':' + server_port + '/parkingStatus'
ser = serial.Serial(
port='/dev/ttyACM0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
counter=0
5 years ago
prev_status = ser.readline()
while 1:
park_status = ser.readline()
5 years ago
park_status_data = str(park_status).split("#")
parkingCode = park_status_data[0].replace('b\'','')
parkingStatus = park_status_data[1].replace('\\r\\n\'', '')
5 years ago
try:
if park_status != prev_status:
5 years ago
if parkingStatus == "1":
5 years ago
print("parking reserved. RESPONSE :", r.status_code, "\n")
5 years ago
elif parkingStatus == "0":
5 years ago
print("parking not reserved. RESPONSE : ", r.status_code, "\n")
5 years ago
data = """{"no":""" + parkingCode + ""","status":""" + parkingStatus + """}"""
r = requests.post(url = API_ENDPOINT, data = data)
5 years ago
except NameError:
print("**Not already prev variable.\n")
prev_status = park_status
else:
print("Create a *.json configuration like: {'ip' : 'xxx.xxx.xxx.xxx', 'port': 'xxxx'}")