diff --git a/README.md b/README.md index a01865a..cb36fca 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # smartParking -Smart and Autonomous parking. \ No newline at end of file +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. diff --git a/iNode/parking.py b/iNode/parking.py index f191b13..bc13402 100644 --- a/iNode/parking.py +++ b/iNode/parking.py @@ -2,6 +2,10 @@ import time import serial +import requests + +API_ENDPOINT = 'http://192.168.1.13:8080/parkingStatus' +parkingCode = "1" ser = serial.Serial( port='/dev/ttyACM0', baudrate = 9600, @@ -12,14 +16,20 @@ ser = serial.Serial( ) counter=0 +prev_status = ser.readline() while 1: park_status = ser.readline() try: if park_status != prev_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: - 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: print("**Not already prev variable.\n") prev_status = park_status + diff --git a/serverNode/.serv.py.swp b/serverNode/.serv.py.swp new file mode 100644 index 0000000..c53664c Binary files /dev/null and b/serverNode/.serv.py.swp differ diff --git a/serverNode/serv.py b/serverNode/serv.py index c378f2f..9c0ad8a 100644 --- a/serverNode/serv.py +++ b/serverNode/serv.py @@ -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) + +# 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): def get(self): - + return parks, 200 + +class ParkingStatus(Resource): + def get(self): + return """ + ERROR +

Not get at '/parkingStatus'.

+ """ + 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 diff --git a/webInterface/car.png b/webInterface/car.png new file mode 100644 index 0000000..b73c8cc Binary files /dev/null and b/webInterface/car.png differ diff --git a/webInterface/parking.css b/webInterface/parking.css new file mode 100644 index 0000000..a62e658 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/webInterface/parking.html b/webInterface/parking.html new file mode 100644 index 0000000..a4d3602 --- /dev/null +++ b/webInterface/parking.html @@ -0,0 +1,66 @@ + + + +Smart Parking + + + + + + + +

Parking

+ + + + + + + + + + + + + + + + + + + + + + + + + +
No4
No5
No3
No6
No2
No7
No1
No8
+ +