cs151051
5 years ago
6 changed files with 86 additions and 33 deletions
@ -0,0 +1,4 @@ |
|||||
|
{ |
||||
|
'ip': '192.168.1.13', |
||||
|
'port': '8080' |
||||
|
} |
@ -1,35 +1,47 @@ |
|||||
|
#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras |
||||
|
#=================================================================== |
||||
#!/usr/bin/env python |
#!/usr/bin/env python |
||||
|
|
||||
import time |
import time |
||||
import serial |
import serial |
||||
import requests |
import requests |
||||
|
import json |
||||
|
|
||||
API_ENDPOINT = 'http://192.168.1.13:8080/parkingStatus' |
with open('data.json') as json_file: |
||||
parkingCode = "1" |
server_par = json.load(json_file) |
||||
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() |
server_ip = server_par['ip'] |
||||
while 1: |
server_port = server_par['port'] |
||||
park_status = ser.readline() |
|
||||
try: |
if server_ip != None and server_port != None: |
||||
if park_status != prev_status: |
API_ENDPOINT = 'http://' + server_ip + ':' + server_port + '/parkingStatus' |
||||
if b'1' in park_status: |
parkingCode = "1" |
||||
data = """{"no":""" + parkingCode + ""","status":1}""" |
ser = serial.Serial( |
||||
r = requests.post(url = API_ENDPOINT, data = data) |
port='/dev/ttyACM0', |
||||
print("parking reserved. RESPONSE :", r.status_code, "\n") |
baudrate = 9600, |
||||
elif b'0' in park_status: |
parity=serial.PARITY_NONE, |
||||
data = """{"no":""" + parkingCode + ""","status":0}""" |
stopbits=serial.STOPBITS_ONE, |
||||
r = requests.post(url = API_ENDPOINT, data = data) |
bytesize=serial.EIGHTBITS, |
||||
print("parking not reserved. RESPONSE : ", r.status_code, "\n") |
timeout=1 |
||||
except NameError: |
) |
||||
print("**Not already prev variable.\n") |
counter=0 |
||||
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'}") |
||||
|
|
||||
|
Loading…
Reference in new issue