cs161079 5 years ago
parent
commit
99ff56a5ab
  1. 4
      README.md
  2. 4
      iNode/data.json
  3. 70
      iNode/parking.py
  4. 2
      serverNode/serv.py
  5. 6
      webInterface/parking.css
  6. 76
      webInterface/parking.html

4
README.md

@ -1,4 +1,6 @@
# smartParking # smartParking
#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras
#===================================================================
Smart and Autonomous parking. Smart and Autonomous parking.
@ -10,5 +12,5 @@ and send it via serial port the information if there is a car or no.
At folder iNode/ there is the application that runs on Raspberry Pi, get At folder iNode/ there is the application that runs on Raspberry Pi, get
the information from Arduino and post it to REST-API as JSON. the information from Arduino and post it to REST-API as JSON.
At webInterface there is an html page that provide the parking status simply get At folder webInterface/ there is an html page that provide the parking status simply get
the information as JSON from REST-API. the information as JSON from REST-API.

4
iNode/data.json

@ -0,0 +1,4 @@
{
"ip": "192.168.89.14",
"port": "8080"
}

70
iNode/parking.py

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

2
serverNode/serv.py

@ -1,5 +1,5 @@
#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras #Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras
#===================================================================
# using flask restful # using flask restful
from flask import Flask, request, jsonify from flask import Flask, request, jsonify
from flask_restful import Resource, Api from flask_restful import Resource, Api

6
webInterface/parking.css

@ -1,3 +1,7 @@
/*
#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras
#===================================================================
*/
table, th, td { table, th, td {
border: 1px solid black; border: 1px solid black;
} }
@ -26,4 +30,4 @@ table, th, td {
.road { .road {
color: lightgrey; color: lightgrey;
} }

76
webInterface/parking.html

@ -1,3 +1,7 @@
<!--
#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras
#===================================================================
-->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -7,35 +11,63 @@
</script> </script>
<script> <script>
function getParkingStatus() {
jQuery.ajax({
url: "http://192.168.1.13:8080/",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function(resultData) {
$.each(resultData, function(key, val) {
console.log(key + " -> " + val);
if (val == "1")
$("#" + key).removeClass("full").addClass("empty");
else if (val == "0")
$("#" + key).removeClass("empty").addClass("full");
});
},
error: function(jqXHR, testStatus, errorThrown) {
},
timeout: 12000,
});
}
$(document).ready(function(){ $(document).ready(function(){
setInterval(getParkingStatus, 1000); $("#approve").click(function() {
server_ip = $("#server_ip").val();
server_port = $("#server_port").val();
alert(server_ip + " " + server_port + ". Started!!!")
$("#msg").empty();
if (server_ip !== "" && server_ip !== null && server_port !== "" && server_port !== null) {
$("#msg").html("<font color='red'>ok!</font>");
setInterval(function () {
jQuery.ajax({
url: "http://" + server_ip + ":" + server_port + "/",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function(resultData) {
$.each(resultData, function(key, val) {
console.log(key + " -> " + val);
if (val == "1")
$("#" + key).removeClass("full").addClass("empty");
else if (val == "0")
$("#" + key).removeClass("empty").addClass("full");
});
},
error: function(jqXHR, testStatus, errorThrown) {
},
timeout: 12000,
});
}, 1000);
} else {
$("#msg").html("<font color='red'>Something went wrong. Try again</font>");
}
});
}); });
</script> </script>
</head> </head>
<body> <body>
<h1>Parking</h1> <h1>Parking</h1>
<h3>Server Settings</h3>
<table>
<tr>
<td>Server IP:</td>
<td><input type="text" id="server_ip" placeholder="xxx.xxx.xxx.xxx"/></td>
</tr>
<tr>
<td>Server PORT:</td>
<td><input type="text" id="server_port" placeholder="xxxx"/></td>
</tr>
<tr>
<td><div id="msg"></div></td>
<td><input type="button" id="approve" value="ok"/></td>
</tr>
</table>
<h3>Parking Diagram</h3>
<table width="100%"> <table width="100%">
<tr> <tr>
<td id="park4" width="30%">No4<div id="4" class="full"></div></td> <td id="park4" width="30%">No4<div id="4" class="full"></div></td>

Loading…
Cancel
Save