|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
|