From 78cb2beb62a58309a28b35259a356702c1d0b949 Mon Sep 17 00:00:00 2001 From: cs151051 Date: Mon, 25 Nov 2019 13:58:53 +0200 Subject: [PATCH 1/2] v1.2 --- README.md | 4 ++- iNode/data.json | 4 +++ iNode/parking.py | 66 +++++++++++++++++++++++---------------- serverNode/serv.py | 2 +- webInterface/parking.css | 6 +++- webInterface/parking.html | 37 ++++++++++++++++++++-- 6 files changed, 86 insertions(+), 33 deletions(-) create mode 100644 iNode/data.json diff --git a/README.md b/README.md index cb36fca..cd44668 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # smartParking +#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras +#=================================================================== Smart and Autonomous parking. @@ -10,5 +12,5 @@ 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 +At folder webInterface/ there is an html page that provide the parking status simply get the information as JSON from REST-API. diff --git a/iNode/data.json b/iNode/data.json new file mode 100644 index 0000000..b991d4b --- /dev/null +++ b/iNode/data.json @@ -0,0 +1,4 @@ +{ + 'ip': '192.168.1.13', + 'port': '8080' +} diff --git a/iNode/parking.py b/iNode/parking.py index bc13402..2d06542 100644 --- a/iNode/parking.py +++ b/iNode/parking.py @@ -1,35 +1,47 @@ +#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras +#=================================================================== #!/usr/bin/env python import time import serial import requests +import json -API_ENDPOINT = 'http://192.168.1.13:8080/parkingStatus' -parkingCode = "1" -ser = serial.Serial( - port='/dev/ttyACM0', - baudrate = 9600, - parity=serial.PARITY_NONE, - stopbits=serial.STOPBITS_ONE, - bytesize=serial.EIGHTBITS, - timeout=1 -) -counter=0 +with open('data.json') as json_file: + server_par = json.load(json_file) + + 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' + parkingCode = "1" + ser = serial.Serial( + port='/dev/ttyACM0', + baudrate = 9600, + parity=serial.PARITY_NONE, + stopbits=serial.STOPBITS_ONE, + bytesize=serial.EIGHTBITS, + timeout=1 + ) + counter=0 -prev_status = ser.readline() -while 1: - park_status = ser.readline() - try: - if park_status != prev_status: - if b'1' in park_status: - 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: - 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 + prev_status = ser.readline() + while 1: + park_status = ser.readline() + try: + if park_status != prev_status: + if b'1' in park_status: + 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: + 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 + else: + print("Create a *.json configuration like: {'ip' : 'xxx.xxx.xxx.xxx', 'port': 'xxxx'}") diff --git a/serverNode/serv.py b/serverNode/serv.py index 9c0ad8a..3f4be91 100644 --- a/serverNode/serv.py +++ b/serverNode/serv.py @@ -1,5 +1,5 @@ #Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras - +#=================================================================== # using flask restful from flask import Flask, request, jsonify from flask_restful import Resource, Api diff --git a/webInterface/parking.css b/webInterface/parking.css index a62e658..6a05587 100644 --- a/webInterface/parking.css +++ b/webInterface/parking.css @@ -1,3 +1,7 @@ +/* +#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras +#=================================================================== +*/ table, th, td { border: 1px solid black; } @@ -26,4 +30,4 @@ table, th, td { .road { color: lightgrey; -} \ No newline at end of file +} diff --git a/webInterface/parking.html b/webInterface/parking.html index a4d3602..49fd311 100644 --- a/webInterface/parking.html +++ b/webInterface/parking.html @@ -1,3 +1,7 @@ + @@ -7,9 +11,9 @@

Parking

+

Server Settings

+ + + + + + + + + + + + + +
Server IP:
Server PORT:
+ +

Parking Diagram

From 7ee83277e0e38135fa0e41d9e540c673f9c44a9c Mon Sep 17 00:00:00 2001 From: cs151051 Date: Mon, 25 Nov 2019 15:29:42 +0200 Subject: [PATCH 2/2] v1.1 --- iNode/data.json | 4 ++-- iNode/parking.py | 24 +++++++++++++-------- webInterface/parking.html | 45 ++++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/iNode/data.json b/iNode/data.json index b991d4b..9d62f9c 100644 --- a/iNode/data.json +++ b/iNode/data.json @@ -1,4 +1,4 @@ { - 'ip': '192.168.1.13', - 'port': '8080' + "ip": "192.168.89.14", + "port": "8080" } diff --git a/iNode/parking.py b/iNode/parking.py index 2d06542..65981d1 100644 --- a/iNode/parking.py +++ b/iNode/parking.py @@ -7,15 +7,18 @@ import serial import requests import json -with open('data.json') as json_file: - server_par = json.load(json_file) +# Open file to configure communication with server. +with open('data.json', 'r') as json_file: + json_data = json_file.read() + +if json_data != "" and json_data != None: + server_par = json.loads(json_data.replace('\n','').replace(' ','')) 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' - parkingCode = "1" ser = serial.Serial( port='/dev/ttyACM0', baudrate = 9600, @@ -29,16 +32,19 @@ with open('data.json') as json_file: prev_status = ser.readline() 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 park_status != prev_status: - if b'1' in park_status: - data = """{"no":""" + parkingCode + ""","status":1}""" - r = requests.post(url = API_ENDPOINT, data = data) + if parkingStatus == "1": print("parking reserved. RESPONSE :", r.status_code, "\n") - elif b'0' in park_status: - data = """{"no":""" + parkingCode + ""","status":0}""" - r = requests.post(url = API_ENDPOINT, data = data) + elif parkingStatus == "0": print("parking not reserved. RESPONSE : ", r.status_code, "\n") + data = """{"no":""" + parkingCode + ""","status":""" + parkingStatus + """}""" + r = requests.post(url = API_ENDPOINT, data = data) except NameError: print("**Not already prev variable.\n") prev_status = park_status diff --git a/webInterface/parking.html b/webInterface/parking.html index 49fd311..16c6d89 100644 --- a/webInterface/parking.html +++ b/webInterface/parking.html @@ -11,35 +11,36 @@
No4