Browse Source

1st try provide the whole project.

master
cs151051 5 years ago
parent
commit
354cac923d
  1. 13
      README.md
  2. 14
      iNode/parking.py
  3. BIN
      serverNode/.serv.py.swp
  4. 55
      serverNode/serv.py
  5. BIN
      webInterface/car.png
  6. 29
      webInterface/parking.css
  7. 66
      webInterface/parking.html

13
README.md

@ -1,3 +1,14 @@
# smartParking # smartParking
Smart and Autonomous parking. Smart and Autonomous parking.
At folder serverNode/ there is a flask-Python REST-API to provide parking status.
At folder sensorNode/ there is the Arduino code that sense the parking position status
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
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
the information as JSON from REST-API.

14
iNode/parking.py

@ -2,6 +2,10 @@
import time import time
import serial import serial
import requests
API_ENDPOINT = 'http://192.168.1.13:8080/parkingStatus'
parkingCode = "1"
ser = serial.Serial( ser = serial.Serial(
port='/dev/ttyACM0', port='/dev/ttyACM0',
baudrate = 9600, baudrate = 9600,
@ -12,14 +16,20 @@ ser = serial.Serial(
) )
counter=0 counter=0
prev_status = ser.readline()
while 1: while 1:
park_status = ser.readline() park_status = ser.readline()
try: try:
if park_status != prev_status: if park_status != prev_status:
if b'1' in park_status: if b'1' in park_status:
print("parking reserved.\n") data = """{"no":""" + parkingCode + ""","status":1}"""
r = requests.post(url = API_ENDPOINT, data = data)
print("parking reserved. RESPONSE :", r.status_code, "\n")
elif b'0' in park_status: elif b'0' in park_status:
print("parking not reserved.\n") data = """{"no":""" + parkingCode + ""","status":0}"""
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

BIN
serverNode/.serv.py.swp

Binary file not shown.

55
serverNode/serv.py

@ -1,14 +1,59 @@
#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras #Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras
from flask import Flask, request
# using flask restful
from flask import Flask, request, jsonify
from flask_restful import Resource, Api from flask_restful import Resource, Api
from json import dumps from json import dumps
from flask.ext.jsonpify import jsonify import json
from flask_cors import CORS
# ==================================================================
# ==================================================================
# creating the flask app
app = Flask(__name__) app = Flask(__name__)
apy = Api(app) CORS(app)
# creating an API object
api = Api(app)
parking =[] parks = dict()
# ==================================================================
# making a class for a particular resource
# the get, post methods correspond to get and post requests
# they are automatically mapped by flask_restful.
# other methods include put, delete, etc.
class Parking(Resource): class Parking(Resource):
def get(self): def get(self):
return parks, 200
class ParkingStatus(Resource):
def get(self):
return """<html>
<head><title>ERROR</title></head>
<body><h1>Not get at '/parkingStatus'.</h1></body>
</html>"""
def post(self):
print (request)
data = json.loads(request.data)
print (data)
parks[data['no']] = data['status']
return parks[data['no']], 201
# ==================================================================
# adding the defined resources along with their corresponding urls
api.add_resource(Parking, '/')
api.add_resource(ParkingStatus, '/parkingStatus')
# ==================================================================
# driver function
if __name__ == '__main__':
app.run(
debug=True,
host=app.config.get("HOST", "0.0.0.0"),
port=app.config.get("PORT", "8080")
)
# END

BIN
webInterface/car.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

29
webInterface/parking.css

@ -0,0 +1,29 @@
table, th, td {
border: 1px solid black;
}
.full {
background-color: red;
content: url("car.png");
height: 140px;
margin: auto;
display:block;
}
.empty {
background-color: grey;
content: url("car.png");
height: 140px;
margin: auto;
}
.right {
}
.left {
transform: rotate(180deg);
}
.road {
color: lightgrey;
}

66
webInterface/parking.html

@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>Smart Parking</title>
<link rel="stylesheet" type="text/css" href="parking.css">
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.min.js">
</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(){
setInterval(getParkingStatus, 1000);
});
</script>
</head>
<body>
<h1>Parking</h1>
<table width="100%">
<tr>
<td id="park4" width="30%">No4<div id="4" class="full"></div></td>
<td width="20%" bgcolor="lightgrey"><div class="road"></div></td>
<td width="20%" bgcolor="lightgrey"><div class="road"></div></td>
<td id="park5" width="30%">No5<div id="5" class="full left"></div></td>
</tr>
<tr>
<td id="park3" width="30%">No3<div id="3" class="full"></div></td>
<td width="20%" bgcolor="lightgrey"><div class="road"></div></td>
<td width="20%" bgcolor="lightgrey"><div class="road"></div></td>
<td id="park6" width="30%">No6<div id="6" class="full left"></div></td>
</tr>
<tr>
<td id="park2" width="30%">No2<div id="2" class="full"></div></td>
<td width="20%" bgcolor="lightgrey"><div class="road"></div></td>
<td width="20%" bgcolor="lightgrey"><div class="road"></div></td>
<td id="park7" width="30%">No7<div id="7" class="full left"></div></td>
</tr>
<tr>
<td id="park1" width="30%">No1<div id="1" class="full"></div></td>
<td width="20%" bgcolor="lightgrey"><div class="road"></div></td>
<td width="20%" bgcolor="lightgrey"><div class="road"></div></td>
<td id="park8" width="30%">No8<div id="8" class="full left"></div></td>
</tr>
</table>
</body>
</html>
Loading…
Cancel
Save