webserver
This commit is contained in:
parent
700d676d4c
commit
6628e4f908
19
RasPi/WebServer.py
Normal file
19
RasPi/WebServer.py
Normal 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
17
RasPi/nginx
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -10,8 +10,9 @@ Setup:
|
|||||||
RasPi:
|
RasPi:
|
||||||
|
|
||||||
# Install https://www.airspayce.com/mikem/bcm2835/ on Raspberry Pi (maybe not)
|
# Install https://www.airspayce.com/mikem/bcm2835/ on Raspberry Pi (maybe not)
|
||||||
sudo apt-get install pip
|
sudo apt-get install pip nginx
|
||||||
pip install numpy pyLoraRFM9x pyblake2 toml
|
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
|
C++ programs need to be executed with sudo, or set permissions to use bcm2835 as user
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user