diff --git a/README.md b/README.md index cdba7b5..c6bee35 100644 --- a/README.md +++ b/README.md @@ -248,3 +248,10 @@ should be -> {"ok": true, ... } -> otherwise look at the logs: journalctl -u drive-ctl -n 80 --no-pager + +## Networking / AccessPoint / Captive Portal + +see /network/ folder for config + + + diff --git a/drive/etc/nginx/snippets/captive-portal.conf b/drive/etc/nginx/snippets/captive-portal.conf new file mode 100644 index 0000000..0c72b8b --- /dev/null +++ b/drive/etc/nginx/snippets/captive-portal.conf @@ -0,0 +1,16 @@ +# --- Captive Portal Trigger (Android/iOS/Windows) --- +# Android / Google connectivity check +location = /generate_204 { return 302 /; } +location = /gen_204 { return 302 /; } + +# iOS/macOS captive check +location = /hotspot-detect.html { return 200 'SuccessOK'; add_header Content-Type text/html; } +location = /library/test/success.html { return 302 /; } + +# Windows NCSI check +location = /ncsi.txt { return 302 /; } +location = /connecttest.txt { return 302 /; } + +# Optional: Android “portal” URL +location = /captiveportal { return 302 /; } + diff --git a/drive/etc/nginx/snippets/drive.conf b/drive/etc/nginx/snippets/drive.conf index 07fa354..d28c671 100644 --- a/drive/etc/nginx/snippets/drive.conf +++ b/drive/etc/nginx/snippets/drive.conf @@ -1,6 +1,6 @@ - location ^~ /drive/ { - alias /opt/helva-robot/drive/var/www/drive/; + location ^~ /drive { + alias /opt/helva-robot/drive/var/www/drive; try_files $uri $uri/ /drive/index.html; } diff --git a/drive/opt/drive-ctl/server.py b/drive/opt/drive-ctl/server.py index 9f15229..1586e77 100644 --- a/drive/opt/drive-ctl/server.py +++ b/drive/opt/drive-ctl/server.py @@ -5,6 +5,28 @@ import serial from fastapi import FastAPI, WebSocket, WebSocketDisconnect from fastapi.responses import HTMLResponse +import time +import logging + +log = logging.getLogger("drive") +logging.basicConfig(level=logging.INFO) + +_last_send_t = None + +def log_send_timing(note: str = ""): + global _last_send_t + now = time.perf_counter() # monotonic + hochauflösend + if _last_send_t is None: + _last_send_t = now + return + dt_ms = (now - _last_send_t) * 1000.0 + _last_send_t = now + + # Nur loggen wenn "auffällig" + if dt_ms > 120: + log.warning("SERIAL SEND GAP %.0f ms %s", dt_ms, note) + + SERIAL_PORT = "/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0" # ggf. /dev/ttyUSB0 BAUD = 115200 @@ -24,6 +46,7 @@ def send_lr(l: int, r: int): l = clamp255(l) r = clamp255(r) line = f"L {l} R {r}\n".encode("ascii") + log_send_timing("(before write)") ser.write(line) @app.get("/health") diff --git a/face/etc/nginx/sites-available/face b/face/etc/nginx/sites-available/face index f8d47c7..d3b742c 100644 --- a/face/etc/nginx/sites-available/face +++ b/face/etc/nginx/sites-available/face @@ -2,6 +2,10 @@ server { listen 80; server_name _; + # captive portal to face + include /opt/helva-robot/drive/etc/nginx/snippets/captive-portal.conf; + + # gives access to drive control include /opt/helva-robot/drive/etc/nginx/snippets/drive.conf; root /opt/helva-robot/face/var/www/html; diff --git a/face/var/www/html/index.html b/face/var/www/html/index.html index 211cfed..bacabd8 100755 --- a/face/var/www/html/index.html +++ b/face/var/www/html/index.html @@ -18,8 +18,10 @@
neutral
+ + 🎮 Steuerung öffnen diff --git a/face/var/www/html/style.css b/face/var/www/html/style.css index 92fa059..cec81fd 100755 --- a/face/var/www/html/style.css +++ b/face/var/www/html/style.css @@ -284,3 +284,17 @@ body.emotion-sleepy .eye { opacity: calc(var(--mouth-line-opacity) + 0.10 * var(--mouth-open)); } + +.control-link{ + position: fixed; + right: 16px; + bottom: 16px; + padding: 12px 16px; + background: rgba(0,0,0,0.6); + color: white; + text-decoration: none; + border-radius: 12px; + font-family: system-ui, sans-serif; + font-size: 16px; +} +.control-link:active{ transform: scale(0.98); } diff --git a/network/etc/dnsmasq.conf b/network/etc/dnsmasq.conf new file mode 100644 index 0000000..6f3eccd --- /dev/null +++ b/network/etc/dnsmasq.conf @@ -0,0 +1,6 @@ +interface=wlan0 +dhcp-range=10.42.0.50,10.42.0.150,255.255.255.0,12h +bind-interfaces + +# Captive Portal DNS +address=/#/10.42.0.1 diff --git a/network/etc/hostapd/hostapd.conf b/network/etc/hostapd/hostapd.conf new file mode 100755 index 0000000..e2f5100 --- /dev/null +++ b/network/etc/hostapd/hostapd.conf @@ -0,0 +1,14 @@ +interface=wlan0 +driver=nl80211 +ssid=Helva +hw_mode=g +channel=6 +# wmm_enabled=1 +auth_algs=1 +# wpa=2 +wpa=0 +# wpa_passphrase=Helva +# wpa_key_mgmt=WPA-PSK +# rsn_pairwise=CCMP +country_code=AT +ieee80211n=1 diff --git a/network/etc/systemd/network/10-wlan0-ap.network b/network/etc/systemd/network/10-wlan0-ap.network new file mode 100644 index 0000000..fa05f6c --- /dev/null +++ b/network/etc/systemd/network/10-wlan0-ap.network @@ -0,0 +1,6 @@ +[Match] +Name=wlan0 + +[Network] +Address=10.42.0.1/24 +ConfigureWithoutCarrier=yes diff --git a/network/etc/systemd/system/hostapd.service.d/override.conf b/network/etc/systemd/system/hostapd.service.d/override.conf new file mode 100644 index 0000000..0767180 --- /dev/null +++ b/network/etc/systemd/system/hostapd.service.d/override.conf @@ -0,0 +1,6 @@ +[Unit] +After=network-online.target +Wants=network-online.target + +[Service] +ExecStartPre=/sbin/ip link set wlan0 up diff --git a/network/var/www/captive/index.html b/network/var/www/captive/index.html new file mode 100644 index 0000000..1a18979 --- /dev/null +++ b/network/var/www/captive/index.html @@ -0,0 +1 @@ +