From 1886504400deaa6636f91bbc645b0776c28687f1 Mon Sep 17 00:00:00 2001 From: Evangelos Oulis Date: Wed, 22 Jan 2020 14:17:58 +0200 Subject: [PATCH 1/3] Update v1.3 --- gatewayNode/parking.py | 66 ++++++++++++++------- serverNode/__pycache__/serv.cpython-37.pyc | Bin 3971 -> 4198 bytes serverNode/serv.py | 47 +++++++++------ servo_pins_description.jpg | Bin 6896 -> 0 bytes 4 files changed, 74 insertions(+), 39 deletions(-) delete mode 100644 servo_pins_description.jpg diff --git a/gatewayNode/parking.py b/gatewayNode/parking.py index 4d94b8d..8a0f778 100644 --- a/gatewayNode/parking.py +++ b/gatewayNode/parking.py @@ -14,11 +14,14 @@ with open('/home/pi/project/data.json', 'r') as json_file: if json_data != "" and json_data != None: server_par = json.loads(json_data.replace('\n','').replace(' ','')) + # Initialize server IP and Port to make the connection. server_ip = server_par['ip'] server_port = server_par['port'] if server_ip != None and server_port != None: API_ENDPOINT = 'http://' + server_ip + ':' + server_port + '/parkingStatus' + + # Initialize Serial Connection with Arduino Uno ser = serial.Serial( port='/dev/ttyACM0', baudrate = 9600, @@ -32,28 +35,47 @@ if json_data != "" and json_data != None: ser.readline() prev_status = "-1" - device_session = requests.session() + # Authentication body content. data = """{"username" :""" + server_par['username'] + """, "password":""" + server_par['password'] + """, "device": """ + server_par['device'] + """}""" - s.post(url = API_ENDPOINT, data = data) - 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 parkingStatus != prev_status: - data = """{"no":""" + parkingCode + ""","status":""" + parkingStatus + """}""" - r = s.post(url = API_ENDPOINT, data = data) - if parkingStatus == "0": - print("parking reserved. RESPONSE :", r.status_code, "\n") - elif parkingStatus == "1": - print("parking not reserved. RESPONSE : ", r.status_code, "\n") - except NameError as e: - print("**Not already prev variable. : ", str(e), "\n") - prev_status = parkingStatus - else: - print("Create a *.json configuration like: {'ip' : 'xxx.xxx.xxx.xxx', 'port': 'xxxx'}") + # Request to Authenticate Node. + resp = requests.post(url = API_ENDPOINT, data = data) + + # Unpack our data to a JSON object + data = json.loads(resp.content) + try: + # Check if node is Authenticated. "cookie + if data['cookie'] != None: + while 1: + # For a while we request to get Parking Status + # witch is a JSON object like [{"no": 1, "status": false}, {"no": 2, "status": true}, ..., {"no": n, "status": true}] + park_status = ser.readline() + + # Substring the input data from arduino. + # Data's notation is: # + park_status_data = str(park_status).split("#") + + # Decode and clear serial input data encoding. + parkingCode = park_status_data[0].replace('b\'','') + parkingStatus = park_status_data[1].replace('\\r\\n\'', '') + + try: + if parkingStatus != prev_status: + # If parking status changed from previous status + # server would informed about this change. + data = """{"no":""" + parkingCode + ""","status":""" + parkingStatus + """}""" + r = s.post(url = API_ENDPOINT, data = data) + + # IO : node prints to output the current + if parkingStatus == "0": + print("parking reserved. RESPONSE :", r.status_code, "\n") + elif parkingStatus == "1": + print("parking not reserved. RESPONSE : ", r.status_code, "\n") + except NameError as e: + print("**Not already prev variable. : ", str(e), "\n") + prev_status = parkingStatus + except TypeError as e: + print("Node must be authenticate first.") + else: + print("Create a *.json configuration like: {'ip' : 'xxx.xxx.xxx.xxx', 'port': 'xxxx'}") diff --git a/serverNode/__pycache__/serv.cpython-37.pyc b/serverNode/__pycache__/serv.cpython-37.pyc index d11e2efae5a1b9457e0b473acc29a1d92bbb6a93..ccaa31c2005eeae6df63514da4c599eb20d8b1d8 100644 GIT binary patch delta 1818 zcmZuxTaOe)6t3!PO;68dXLoM9?C$IZ+)+@GWkFOV5YP>VkgVa-F_M|78ZvjN?lmmV zupzT=hNvmuG-M|+zWTr)z{CflZ$9=9FyV>#;+u)*^bC*?W>R0D^VR9=8aA%%Seh zgP-L&@N<#B0Dhhqz%NApqL|q)iFsZeX|Nfz7x?T*t4^FnJ{L_)@dGXGJ1RFsrn$uD z0hjkz_yS)XX%oA|mqr?2ettcbWNSqpV1R)%~;q4J))lmh+3V4;hzE6DfB_7 zA_+*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authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras #=================================================================== # using flask restful -from flask import Flask, request, jsonify, session +from flask import Flask, request, jsonify from flask_restful import Resource, Api from json import dumps import json from flask_cors import CORS import mysql.connector -import os +from base64 import b64encode +from os import urandom # ================================================================== # ================================================================== @@ -16,8 +17,8 @@ import os app = Flask(__name__) CORS(app) -# create the secret key for session -app.secret_key = os.urandom(24) +# Session list +sessions = [] # creating an API object api = Api(app) @@ -65,10 +66,13 @@ def isMember(username, password): # Function that return if the requested user is authenticated # or not (True / False). -def isAuthenticated(): - if 'device_id' in session: - return True - else: +def isAuthenticated(data): + try: + if data['cookie'] in sessions: + return True + else: + return False + except KeyError as e: return False @@ -77,6 +81,8 @@ def isAuthenticated(): # the get, post methods correspond to get and post requests # they are automatically mapped by flask_restful. # other methods include put, delete, etc. + +# Resource that returns th whole parking status in a JSON class Parking(Resource): def get(self): parks = None @@ -87,6 +93,7 @@ class Parking(Resource): return parks, 200 +# Update parking status resource from authenticated only Node class ParkingStatus(Resource): def get(self): return """ @@ -94,10 +101,9 @@ class ParkingStatus(Resource):

Not get at '/parkingStatus'.

""" def post(self): - if isAuthenticated(): - # Gets the data into as a JSON Object from HTTP request. - data = json.loads(request.data) - + # Gets the data into as a JSON Object from HTTP request. + data = json.loads(request.data) + if isAuthenticated(data): try: # SQL get all Parking places status. parks = getParkings() @@ -138,13 +144,14 @@ class ParkingStatus(Resource): myCursor.execute("UPDATE PARKING SET PARKING_STATUS=%s WHERE PARKING_CODE=%s", values) mydb.commit() parks = getParkings() - except mysql.connector.errors.DatabaseError as e: + except (mysql.connector.errors.DatabaseError, mysql.connector.errors.InterfaceError) as e: mydb.reconnect(attempts=1, delay=0) return currentParking, 201 else: return "Error! You aren't authenticated. [POST] /authenticate first.", 403 +# Authentication resource. class Authenticate(Resource): def post(self): try: @@ -155,22 +162,28 @@ class Authenticate(Resource): isValid = isMember(data['username'], data['password']) if isValid: - session['device_id'] = data['device'] + session_key = str(b64encode(urandom(32)).decode('utf-8')) + + # Send the cookie value back to clinet. + session = {"cookie": session_key} + sessions.append(session_key) + return session, 200 else: return "Not Authenticatiove device", 403 else: return "Error authentication", 403 - except mysql.connector.errors.DatabaseError as e: + except (mysql.connector.errors.DatabaseError, mysql.connector.errors.InterfaceError) as e: mydb.reconnect(attempts=1, delay=0) # ================================================================== -# adding the defined resources along with their corresponding urls to REST APIs +# matches the defined resources to their corresponding urls to REST APIs api.add_resource(Parking, '/') api.add_resource(ParkingStatus, '/parkingStatus') api.add_resource(Authenticate, '/authenticate') # ================================================================== -# driver function +# ===========================MAIN CLASS============================= +# driver function "Main Class" if __name__ == '__main__': app.run( debug=True, diff --git a/servo_pins_description.jpg b/servo_pins_description.jpg deleted file mode 100644 index 1f41f4894df17a0f991598aa1628849882f6e5c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6896 zcmbt&bx<5j^zOg{i^CG!WeFZ!7MBp%Bm@f*ECdhk?v~&hED$`nYmgvIa0$*L2^!qp zAG!DbUe&95f4r)9db+1i&s3i?^Y!$Z@7&MaF9L+mpTVC2C@27c@=$>LIUpDS{Uc}( zg8o;)U*P2!cEuZBm7trTOWiu_safVMI z^az(!a~3c8>Ysr^#u5Wo7I>1+>R*+V6-?Zu^OY?o_OC`hA?6r=6fOO?PfUDn@J|Qy z02S2(6sZ3PQUE#z3J47q{0~m3{}=~=-gbz?T%K4p1vv^9Nx@r}&-Q%n*h<_6pS_1F z=m96s-;a)P2IudAEC5~TgF|f19ssaG3{>-GO?3k3re9gGJ0#}??X zEmS}eU^K%(EF2wr(4#!!5gkz&fe*0V1N4}w0VXx()=dXGCV;;L`At1d{CK;7yFb9` zlWEsmNJkH#N961_?may3h)eOYKk)bQcnKdCA}R_h2m=EZ^e{aDpo7pbz$mByCJ7NK zJ>(HFg|G@C894)wG?bT-N#MW5iGm5-l`PAJGz@&W^9gbqskHSt!yA$8Xq+-7bZt^( zxSf+K#|fu0eUZ!PYuGR?`Ck>-UN59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38V)%)GP2E2Fg`Y{Xx7u^FK{59Hxv*)giFm3k+RR_HD z9-R^Ex;w5H%7jU@2|X*^BZWoAkOl&|ALgqys_5-}?J%#tgHoZNF9`RN$QYlV=GYad zeV-Mx>J6_HI&#_iS`#RF$xQOBU~<)m2nG#7bnisMctjyD($nM@zNy>;-6Dc|iq(?E K@Dsm# Date: Wed, 22 Jan 2020 14:56:09 +0200 Subject: [PATCH 2/3] Update v1.3 --- gatewayNode/parking.py | 3 ++- serverNode/__pycache__/serv.cpython-37.pyc | Bin 4198 -> 4197 bytes serverNode/serv.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gatewayNode/parking.py b/gatewayNode/parking.py index 8a0f778..01d0c98 100644 --- a/gatewayNode/parking.py +++ b/gatewayNode/parking.py @@ -46,6 +46,7 @@ if json_data != "" and json_data != None: try: # Check if node is Authenticated. "cookie if data['cookie'] != None: + cookie = data['cookie'] while 1: # For a while we request to get Parking Status # witch is a JSON object like [{"no": 1, "status": false}, {"no": 2, "status": true}, ..., {"no": n, "status": true}] @@ -63,7 +64,7 @@ if json_data != "" and json_data != None: if parkingStatus != prev_status: # If parking status changed from previous status # server would informed about this change. - data = """{"no":""" + parkingCode + ""","status":""" + parkingStatus + """}""" + data = """{"no":""" + parkingCode + ""","status":""" + parkingStatus + """, "cookie": \"""" + cookie + """\"}""" r = s.post(url = API_ENDPOINT, data = data) # IO : node prints to output the current diff --git a/serverNode/__pycache__/serv.cpython-37.pyc b/serverNode/__pycache__/serv.cpython-37.pyc index ccaa31c2005eeae6df63514da4c599eb20d8b1d8..04c479732cab17329d36545a9fada6a06e5cc12e 100644 GIT binary patch delta 45 zcmaE+@Kk} Date: Wed, 22 Jan 2020 15:14:45 +0200 Subject: [PATCH 3/3] Update v1.3 --- serverNode/serv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serverNode/serv.py b/serverNode/serv.py index f358075..93230b7 100644 --- a/serverNode/serv.py +++ b/serverNode/serv.py @@ -88,7 +88,7 @@ class Parking(Resource): parks = None try: parks = getParkings() - except mysql.connector.errors.DatabaseError as e: + except (mysql.connector.errors.DatabaseError, mysql.connector.errors.InterfaceError) as e: mydb.reconnect(attempts=1, delay=0) return parks, 200