Browse Source

v1.1

master
cs151051 5 years ago
parent
commit
7ee83277e0
  1. 4
      iNode/data.json
  2. 24
      iNode/parking.py
  3. 23
      webInterface/parking.html

4
iNode/data.json

@ -1,4 +1,4 @@
{ {
'ip': '192.168.1.13', "ip": "192.168.89.14",
'port': '8080' "port": "8080"
} }

24
iNode/parking.py

@ -7,15 +7,18 @@ import serial
import requests import requests
import json import json
with open('data.json') as json_file: # Open file to configure communication with server.
server_par = json.load(json_file) 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_ip = server_par['ip']
server_port = server_par['port'] server_port = server_par['port']
if server_ip != None and server_port != None: if server_ip != None and server_port != None:
API_ENDPOINT = 'http://' + server_ip + ':' + server_port + '/parkingStatus' API_ENDPOINT = 'http://' + server_ip + ':' + server_port + '/parkingStatus'
parkingCode = "1"
ser = serial.Serial( ser = serial.Serial(
port='/dev/ttyACM0', port='/dev/ttyACM0',
baudrate = 9600, baudrate = 9600,
@ -29,16 +32,19 @@ with open('data.json') as json_file:
prev_status = ser.readline() prev_status = ser.readline()
while 1: while 1:
park_status = ser.readline() 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: try:
if park_status != prev_status: if park_status != prev_status:
if b'1' in park_status: if parkingStatus == "1":
data = """{"no":""" + parkingCode + ""","status":1}"""
r = requests.post(url = API_ENDPOINT, data = data)
print("parking reserved. RESPONSE :", r.status_code, "\n") print("parking reserved. RESPONSE :", r.status_code, "\n")
elif b'0' in park_status: elif parkingStatus == "0":
data = """{"no":""" + parkingCode + ""","status":0}"""
r = requests.post(url = API_ENDPOINT, data = data)
print("parking not reserved. RESPONSE : ", r.status_code, "\n") print("parking not reserved. RESPONSE : ", r.status_code, "\n")
data = """{"no":""" + parkingCode + ""","status":""" + parkingStatus + """}"""
r = requests.post(url = API_ENDPOINT, data = data)
except NameError: except NameError:
print("**Not already prev variable.\n") print("**Not already prev variable.\n")
prev_status = park_status prev_status = park_status

23
webInterface/parking.html

@ -11,9 +11,18 @@
</script> </script>
<script> <script>
function getParkingStatus(ip, port) { $(document).ready(function(){
$("#approve").click(function() {
server_ip = $("#server_ip").val();
server_port = $("#server_port").val();
alert(server_ip + " " + server_port + ". Started!!!")
$("#msg").empty();
if (server_ip !== "" && server_ip !== null && server_port !== "" && server_port !== null) {
$("#msg").html("<font color='red'>ok!</font>");
setInterval(function () {
jQuery.ajax({ jQuery.ajax({
url: "http://" + ip + ":" + port + "8080/", url: "http://" + server_ip + ":" + server_port + "/",
type: "GET", type: "GET",
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
@ -31,15 +40,7 @@ function getParkingStatus(ip, port) {
timeout: 12000, timeout: 12000,
}); });
} }, 1000);
$(document).ready(function(){
$("#approve").click(function() {
server_ip = $("#server_ip").val();
server_port = $("#server_port").val();
$("#msg").empty();
if (server_ip !== "" && server_ip !== null && server_port !== "" && server_port !== null) {
$("#msg").html("<font color='red'>ok!</font>");
setInterval(getParkingStatus(server_ip, server_port), 1000);
} else { } else {
$("#msg").html("<font color='red'>Something went wrong. Try again</font>"); $("#msg").html("<font color='red'>Something went wrong. Try again</font>");
} }

Loading…
Cancel
Save