From 8f5cb2612bc140dce8dec48c3d6647215cb62ec9 Mon Sep 17 00:00:00 2001 From: cs151051 Date: Fri, 22 Nov 2019 21:43:15 +0200 Subject: [PATCH] Fixes & pi software --- iNode/Makefile | 4 ++++ iNode/parking.py | 25 +++++++++++++++++++++++++ {iNode => sensorNode}/sensor.ino | 4 ++-- serverNode/serv.py | 14 ++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 iNode/Makefile create mode 100644 iNode/parking.py rename {iNode => sensorNode}/sensor.ino (91%) create mode 100644 serverNode/serv.py diff --git a/iNode/Makefile b/iNode/Makefile new file mode 100644 index 0000000..91c9cf0 --- /dev/null +++ b/iNode/Makefile @@ -0,0 +1,4 @@ +all: + sudo chmod +x /dev/ttyACM0 + python3 parking.py + diff --git a/iNode/parking.py b/iNode/parking.py new file mode 100644 index 0000000..f191b13 --- /dev/null +++ b/iNode/parking.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import time +import serial +ser = serial.Serial( + port='/dev/ttyACM0', + baudrate = 9600, + parity=serial.PARITY_NONE, + stopbits=serial.STOPBITS_ONE, + bytesize=serial.EIGHTBITS, + timeout=1 +) +counter=0 + +while 1: + park_status = ser.readline() + try: + if park_status != prev_status: + if b'1' in park_status: + print("parking reserved.\n") + elif b'0' in park_status: + print("parking not reserved.\n") + except NameError: + print("**Not already prev variable.\n") + prev_status = park_status diff --git a/iNode/sensor.ino b/sensorNode/sensor.ino similarity index 91% rename from iNode/sensor.ino rename to sensorNode/sensor.ino index c4b4635..2037efc 100644 --- a/iNode/sensor.ino +++ b/sensorNode/sensor.ino @@ -43,11 +43,11 @@ distance= duration*0.034/2; //Serial.println(distance); if (distance < 5){ - Serial.println("0"); + Serial.println("0"); //parking isn't available. digitalWrite(response, LOW); } else{ - Serial.println("1"); + Serial.println("1"); //parking is available. digitalWrite(response, HIGH); } diff --git a/serverNode/serv.py b/serverNode/serv.py new file mode 100644 index 0000000..c378f2f --- /dev/null +++ b/serverNode/serv.py @@ -0,0 +1,14 @@ +#Authors: Oulis Evangelos, Oulis Nikolaos, Drosos Katsibras +from flask import Flask, request +from flask_restful import Resource, Api +from json import dumps +from flask.ext.jsonpify import jsonify + +app = Flask(__name__) +apy = Api(app) + +parking =[] + +class Parking(Resource): + def get(self): +