diff --git a/commands_executor.py b/commands_executor.py deleted file mode 100644 index 8a09ca0..0000000 --- a/commands_executor.py +++ /dev/null @@ -1,49 +0,0 @@ -import flask -from RPi import GPIO -import time -import threading - -app = flask.Flask(import_name=__name__) - -motor_pin1 = 38 -motor_pin2 = 40 - -GPIO.setmode(GPIO.BOARD) -GPIO.setup(motor_pin1, GPIO.OUT, initial=GPIO.LOW) -GPIO.setup(motor_pin2, GPIO.OUT, initial=GPIO.LOW) - -def switch_off(mini_rotation_counter=30): - GPIO.output(motor_pin1, GPIO.LOW) - GPIO.output(motor_pin2, GPIO.LOW) - for _ in range(mini_rotation_counter): - GPIO.output(motor_pin2, GPIO.HIGH) - time.sleep(0.002) - GPIO.output(motor_pin2, GPIO.LOW) - time.sleep(0.2) - -def switch_on(mini_rotation_counter=30): - GPIO.output(motor_pin1, GPIO.LOW) - GPIO.output(motor_pin2, GPIO.LOW) - for _ in range(mini_rotation_counter): - GPIO.output(motor_pin1, GPIO.HIGH) - time.sleep(0.002) - GPIO.output(motor_pin1, GPIO.LOW) - time.sleep(0.2) - -def into_thread(): - for _ in range(7): - switch_on() - switch_off() - switch_off() - -@app.route("/open") -def open_command_function(): - command_applier = threading.Thread(target=into_thread) - command_applier.start() - return "OK\n" - - - -if __name__=="__main__": - switch_off() - app.run(host="0.0.0.0") diff --git a/gsminit.py b/gsminit.py deleted file mode 100644 index 4e4d6d3..0000000 --- a/gsminit.py +++ /dev/null @@ -1,46 +0,0 @@ -import serial -import os -import time -import requests - -port = serial.Serial("/dev/serial0", baudrate=9600, timeout=1) -port.flush() - -data="" -print("Finding module") -while 1: - data="";port.flush() - port.write(b'AT\n') - data=port.read(150) - print("received",data) - r=data.find(b'OK') - if r>=0: print("AT...good...");break - time.sleep(0.75) - -while 1: - data="";port.flush() - port.write(b'AT+CLIP=1\n') - data=port.read(150) - print("received",data) - r=data.find(b'OK') - if r>=0: print("CLIP...good");break - time.sleep(0.75) - -print("Finding network") -while 1: - data="";port.flush() - port.write(b'AT+CPIN?\n') - data=port.read(150) - print("received",data) - r=data.find(b'READY') - if r>=0: print("READY...good");break - time.sleep(0.75) - -while 1: - rcv = port.read(150) - if b"SM" in rcv: - port.write(b'AT+CMGF=1\n') - msg = port.write(b'AT+CMGR=1\n') - if b'please' in msg: print("got it !!!");port.write(b'AT+CMGDA=DEL ALL\n')#requests.get("http://192.168.0.103:/open"); port.write(b'AT+CMGDA=DEL ALL\n') - #print("received", rcv) - time.sleep(0.5) diff --git a/myapp.py b/myapp.py index 6a59f17..c573504 100644 --- a/myapp.py +++ b/myapp.py @@ -1,5 +1,8 @@ +import os import flask +import evdev import requests +import time import threading app = flask.Flask(import_name=__name__) @@ -11,6 +14,34 @@ def opener(lck): for _ in range(5): requests.get("http://192.168.0.103/open") +def remote_handler(lck): + n_attempts = 0 + remote = None + while remote is None: + #---search for remote--- + input_devices = os.listdir("/dev/input") + for device in input_devices: + try: + dev = evdev.InputDevice("/dev/input/"+device) + if "Wireless Present" in dev.name and "Keyboard" in dev.name and "usb" in dev.phys: + remote = dev + print("Remote found") + break + except: + pass + #---start retrieving events if remote detected--- + if remote is not None: + try: + for event in remote.read_loop(): + if event.type==evdev.ecodes.EV_KEY and event.code==evdev.ecodes.KEY_B and event.value==1: + print("Command received from remote") + opener(lck) + except: + remote = None + n_attempts += 1 + print("Attempt "+str(n_attempts)+" fails in finding remote") + time.sleep(3) + @app.route(rule="/") def index(): return "200 OK (working)\n" @@ -55,4 +86,6 @@ def receiver(): if __name__=="__main__": - app.run(host="0.0.0.0", debug=True) + remote_handler_thread = threading.Thread(target=remote_handler, args=(lock,)) + remote_handler_thread.start() + app.run(host="0.0.0.0") \ No newline at end of file diff --git a/servertest.py b/servertest.py deleted file mode 100644 index 478a518..0000000 --- a/servertest.py +++ /dev/null @@ -1,11 +0,0 @@ -import flask - -app = flask.Flask(__name__) - -@app.route("/") -def index(): - return "Okay, it's working guy" - -if __name__=="__main__": - app.run(host="0.0.0.0") - diff --git a/sim800l.py b/sim800l.py index 187cab6..9651118 100644 --- a/sim800l.py +++ b/sim800l.py @@ -52,7 +52,7 @@ class SIM800L: def command(self, cmdstr, lines=1, waitfor=500, msgtext=None): while self.ser.in_waiting: - self.ser.readline() + self.ser.readline() #or self.ser.read(150) self.ser.write(cmdstr.encode()) if msgtext: self.ser.write(msgtext.encode()) diff --git a/argg.py b/sim800lCommandLine.py similarity index 100% rename from argg.py rename to sim800lCommandLine.py diff --git a/sim800ltest.py b/sim800ltest.py deleted file mode 100644 index 3969369..0000000 --- a/sim800ltest.py +++ /dev/null @@ -1,15 +0,0 @@ -import serial -import os -import time -#import RPi.GPIO as GPIO - -#GPIO.setmode(GPIO.BOARD) -port = serial.Serial("/dev/serial0", baudrate=9600, timeout=1) -port.flush() - -port.write(b'AT\r') - -rcv = port.read(100) - -print("received", rcv) -time.sleep(1)