webserver

This commit is contained in:
Terra 2022-04-24 23:14:49 +02:00
parent 700d676d4c
commit 6628e4f908
3 changed files with 39 additions and 2 deletions

19
RasPi/WebServer.py Normal file
View File

@ -0,0 +1,19 @@
from flask import Flask
from MultiNode import MultiNode
import threading, json
app = Flask("MultiNode Server")
multinode = MultiNode()
@app.route("/")
def index():
return json.dumps(multinode.devices)
if __name__ == "__main__":
from waitress import serve
web_thread = threading.Thread(target=lambda: serve(app, host="127.0.0.1", port=8000))
web_thread.start()
while True:
multinode.loop()

17
RasPi/nginx Normal file
View File

@ -0,0 +1,17 @@
server {
listen 80;
listen [::]:80;
gzip on;
server_name 192.168.1.12;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_redirect off;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Original-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

View File

@ -10,8 +10,9 @@ Setup:
RasPi:
# Install https://www.airspayce.com/mikem/bcm2835/ on Raspberry Pi (maybe not)
sudo apt-get install pip
pip install numpy pyLoraRFM9x pyblake2 toml
sudo apt-get install pip nginx
pip install numpy pyLoraRFM9x pyblake2 toml flask waitress (?)
In /etc/nginx/sites-enabled: sudo ln -s ~/multinode/RasPi
C++ programs need to be executed with sudo, or set permissions to use bcm2835 as user