Adding internet support
This commit is contained in:
parent
d8093786a6
commit
6473f1ea06
1 changed files with 12 additions and 0 deletions
12
myapp.py
12
myapp.py
|
@ -5,6 +5,7 @@ import evdev
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
import subprocess
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
app = flask.Flask(import_name=__name__)
|
app = flask.Flask(import_name=__name__)
|
||||||
|
@ -20,6 +21,10 @@ def opener(lck):
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
requests.get("http://192.168.0.103/open")
|
requests.get("http://192.168.0.103/open")
|
||||||
|
|
||||||
|
def localtunnel_launcher(port=8000, wanted_subdomain="open-domodoor"):
|
||||||
|
result = subprocess.run(args="lt --port {} --subdomain {}".format(port,wanted_subdomain))
|
||||||
|
print("Process returned:", result)
|
||||||
|
|
||||||
def remote_handler(lck):
|
def remote_handler(lck):
|
||||||
n_attempts = 0
|
n_attempts = 0
|
||||||
remote = None
|
remote = None
|
||||||
|
@ -52,6 +57,11 @@ def remote_handler(lck):
|
||||||
def index():
|
def index():
|
||||||
return "200 OK (working)\n"
|
return "200 OK (working)\n"
|
||||||
|
|
||||||
|
@app.route(rule="/receiving", methods=["GET"])
|
||||||
|
def receiver_from_internet():
|
||||||
|
op = threading.Thread(target=opener, args=(lock,))
|
||||||
|
op.start()
|
||||||
|
|
||||||
@app.route(rule="/receiving", methods=["POST"])
|
@app.route(rule="/receiving", methods=["POST"])
|
||||||
def receiver():
|
def receiver():
|
||||||
data = flask.request.get_data(as_text=True)
|
data = flask.request.get_data(as_text=True)
|
||||||
|
@ -91,4 +101,6 @@ def receiver():
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
remote_handler_thread = threading.Thread(target=remote_handler, args=(lock,))
|
remote_handler_thread = threading.Thread(target=remote_handler, args=(lock,))
|
||||||
remote_handler_thread.start()
|
remote_handler_thread.start()
|
||||||
|
localtunnel_thread = threading.Thread(target=localtunnel_launcher)
|
||||||
|
localtunnel_thread.start()
|
||||||
app.run(host="0.0.0.0")
|
app.run(host="0.0.0.0")
|
Loading…
Reference in a new issue