2.4 KiB
2.4 KiB
Example Code/Flow/Design
🔒 Securing the communication
1. Restrict to localhost for kiosk
- The kiosk UI (
:8080) should only talk to the backend viaws://127.0.0.1:12345(orwss://if you enable TLS). - This ensures the touchscreen browser cannot be hijacked remotely.
2. TLS for remote UI
- For the remote UI (
:9090), expose a WebSocket server with TLS (wss://Pi_IP:12346). - Generate a self‑signed certificate or use Let’s Encrypt if the Pi is reachable externally.
- Qt supports
QWebSocketServer::SecureModewith SSL certificates.
server = new QWebSocketServer("SecureServer",
QWebSocketServer::SecureMode, this);
QSslConfiguration sslConfig;
sslConfig.setLocalCertificate(QSslCertificate::fromPath("server.crt"));
sslConfig.setPrivateKey(QSslKey(QFile("server.key"), QSsl::Rsa));
server->setSslConfiguration(sslConfig);
server->listen(QHostAddress::Any, 12346);
3. Authentication
- Require a token or password for remote clients.
- On connection, the client must send
{ "auth":"secret123" }before other commands. - Backend rejects unauthenticated clients.
🖥️ Serving two UIs
Option A: Two web servers
- Run a lightweight HTTP server (e.g.
QtHttpServerornginx) on the Pi. - Serve
dashboard_kiosk.htmlat port 8080. - Serve
dashboard_full.htmlat port 9090. - Both connect to the same backend WebSocket, but kiosk uses localhost only.
Option B: One server, two routes
- Serve both UIs from one server, but separate routes:
http://Pi_IP:8080/kioskhttp://Pi_IP:8080/full
- Use Chromium kiosk mode on the Pi to open
/kiosk.
🔄 Communication flow
- Kiosk UI (touchscreen)
→ Connects to
ws://127.0.0.1:12345(no TLS, local only). → Sends commands liketoggleSiren. → Receives sensor updates every few seconds. - Remote UI (PC browser)
→ Connects to
wss://Pi_IP:12346(TLS). → Authenticates with token. → Can send commands and receive updates, but with richer navigation.
🚀 Next Steps
- Generate TLS certs (
openssl req -new -x509 -days 365 -keyout server.key -out server.crt). - Configure Qt WebSocket server with
SecureModefor remote clients. - Serve two HTML versions (kiosk vs full) via nginx or QtHttpServer.
- Add authentication handshake for remote connections.