cs151051
5 years ago
7 changed files with 169 additions and 8 deletions
@ -1,3 +1,14 @@ |
|||
# smartParking |
|||
|
|||
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. |
|||
|
Binary file not shown.
@ -1,14 +1,59 @@ |
|||
#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 json import dumps |
|||
from flask.ext.jsonpify import jsonify |
|||
import json |
|||
from flask_cors import CORS |
|||
|
|||
# ================================================================== |
|||
# ================================================================== |
|||
|
|||
# creating the flask app |
|||
app = Flask(__name__) |
|||
apy = Api(app) |
|||
CORS(app) |
|||
|
|||
parking =[] |
|||
# creating an API object |
|||
api = Api(app) |
|||
|
|||
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): |
|||
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 |
|||
|
After Width: | Height: | Size: 75 KiB |
@ -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; |
|||
} |
@ -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…
Reference in new issue