diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..90f924d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +drive/opt/drive-ctl/__pycache__/ diff --git a/README.md b/README.md index 65a5e01..cdba7b5 100644 --- a/README.md +++ b/README.md @@ -192,12 +192,26 @@ For Web-UI-Controller you need to have access to the raspberry-pi i.e. via a hot sudo apt install -y python3-venv python3 -m venv /opt/drive-ctl-venv - + + sudo chown -R $USER:$USER /opt/drive-ctl-venv /opt/drive-ctl-venv/bin/pip install fastapi uvicorn pyserial source /opt/drive-ctl-venv/bin/activate pip install fastapi uvicorn pyserial +Configure Arduino-USB-ID + + ls -l /dev/serial/by-id/ 2>/dev/null + +Example Output + + usb-1a86_USB2.0-Serial-if00-port0 -> ../../ttyUSB0 + +Watch USB devices while replugging + + dmesg -T | tail -n 80 + +Configure the USB-Device-ID in /opt/helva-robot/drive/opt/drive-ctl/server.py ### Activate Web Control Interface @@ -223,4 +237,14 @@ Check Serial device is stable, otherwise create a udev rule http://pi-ip/drive/ +### Debug drive-ctl WebUI + +check local webservice + + curl -s http://127.0.0.1:8002/health + +should be -> {"ok": true, ... } -> otherwise look at the logs: + + journalctl -u drive-ctl -n 80 --no-pager + diff --git a/drive/etc/nginx/snippets/drive.conf b/drive/etc/nginx/snippets/drive.conf index b4e9bd2..07fa354 100644 --- a/drive/etc/nginx/snippets/drive.conf +++ b/drive/etc/nginx/snippets/drive.conf @@ -1,15 +1,16 @@ - location /drive/ { + location ^~ /drive/ { alias /opt/helva-robot/drive/var/www/drive/; try_files $uri $uri/ /drive/index.html; } - location /drive-ws { + location = /drive-ws { proxy_pass http://127.0.0.1:8002/ws; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; + proxy_read_timeout 3600; } location /drive-health { diff --git a/drive/opt/drive-ctl/server.py b/drive/opt/drive-ctl/server.py index 955f76f..b6b2149 100644 --- a/drive/opt/drive-ctl/server.py +++ b/drive/opt/drive-ctl/server.py @@ -5,7 +5,7 @@ import serial from fastapi import FastAPI, WebSocket, WebSocketDisconnect from fastapi.responses import HTMLResponse -SERIAL_PORT = "/dev/ttyACM0" # ggf. /dev/ttyUSB0 +SERIAL_PORT = "/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0" # ggf. /dev/ttyUSB0 BAUD = 115200 # Safety: if websocket stops sending, we also stop. @@ -30,7 +30,7 @@ def send_lr(l: int, r: int): def health(): return {"ok": True, "serial": SERIAL_PORT} -@app.websocket("/ws") +@app.websocket("/drive-ws") async def ws(websocket: WebSocket): global last_msg_ts await websocket.accept() diff --git a/face/etc/nginx/sites-available/face b/face/etc/nginx/sites-available/face index db0e50c..f8d47c7 100644 --- a/face/etc/nginx/sites-available/face +++ b/face/etc/nginx/sites-available/face @@ -2,6 +2,8 @@ server { listen 80; server_name _; + include /opt/helva-robot/drive/etc/nginx/snippets/drive.conf; + root /opt/helva-robot/face/var/www/html; index index.html; @@ -31,6 +33,5 @@ server { add_header Cache-Control no-cache; } - include /opt/helva-robot/drive/etc/nginx/snippets/drive.conf; }