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 """ +
No4 | ++ | + | No5 | +
No3 | ++ | + | No6 | +
No2 | ++ | + | No7 | +
No1 | ++ | + | No8 | +