How adcuelloa/rovelink works
Purpose and Topology
RoveLink is a low-latency Internet teleoperation platform for differential-drive robots. A browser controller and ESP32 device each initiate outbound secure WebSocket connections; Cloudflare relay rooms forward control traffic without requiring a public device IP. Video uses a separate relay plane. Workspace packages are coordinated from package.json and pnpm-workspace.yaml.
Shared Protocol Contract
The TypeScript protocol package defines versioned JSON messages, codecs, authentication, control semantics, video tickets, and the shared differential-drive mixer. This contract is the boundary between browser, relays, and firmware behavior.
• protocol/src/protocol.ts
• protocol/src/codec.ts
• protocol/src/control.ts
• protocol/src/mix.ts
Browser Control Application
The Vite browser app starts at web/src/main.ts, presenting login/control views and selecting either an in-browser simulated transport or relay WebSocket transport. Input capture normalizes keyboard, gamepad, and touch into control state; the engine applies ownership, arming, emergency-stop, and profile rules before sender/rhythm logic emits latest-state control frames. Telemetry and PWM visualization feed the dashboard.
• web/src/main.ts
• web/src/control/engine.ts
• web/src/transport/websocket.ts
• web/src/transport/sender.ts
Control Relay Plane
The control relay is a Cloudflare Worker front door plus Durable Object room implementation. Routes upgrade authenticated browser/device connections and bind them to a robot room; the room forwards messages between peers rather than implementing robot motion. It is the Internet-facing rendezvous and session-routing boundary.
• relay/src/index.ts
• relay/src/route.ts
• relay/src/room.ts
• relay/wrangler.jsonc
Dedicated Video Relay Plane
Video traffic is intentionally isolated from safety-sensitive control traffic in its own Worker and Durable Object implementation. Publisher/viewer room handling, ticket authorization, and WebSocket routing live independently, while the browser manages ticket sourcing, transport, pairing, renderer selection, and stream statistics.
• video-relay/src/index.ts
• video-relay/src/room.ts
• video-relay/src/route.ts
• web/src/video/video-transport.ts
• web/src/video/renderer.ts
ESP32 Device Runtime and Safety Loop
The Arduino sketch is the device entry point. It joins Wi-Fi, validates WSS TLS roots, reconnects with backoff, authenticates to the control relay, decodes incoming commands, and drives a hardware abstraction. The runtime enforces safe output behavior around arm/disarm, emergency stop, stale-frame watchdogs, and disconnects; hardware can be real or simulated.
• firmware/rovelink_device/rovelink_device.ino
• firmware/rovelink_device/network.cpp
• firmware/rovelink_device/transport.cpp
• firmware/rovelink_device/hardware_real.cpp
• firmware/rovelink_device/hardware_sim.cpp
End-to-End Flow and External Boundaries
1. Browser authenticates as controller and connects to a Cloudflare control room over WSS.
2. ESP32 connects outbound over Wi-Fi/WSS to the same room; relay forwards protocol frames.
3. Browser sends current control state rather than a queued command history; firmware acknowledges/applies valid fresh state and reports telemetry.
4. Firmware converts throttle/steering through the shared differential mix to wheel PWM and actuates hardware only while armed.
5. Optional video publisher/viewers use the separate Cloudflare video Worker/DO and ticket-based authorization.
Material runtimes are browser/Vite TypeScript, Cloudflare Workers with Durable Objects, and Arduino/ESP32 C++. External services are Cloudflare’s Worker/DO platform and Wi-Fi Internet access; TLS CA material is embedded in firmware/rovelink_device/cloudflare_ca_certs.h.
Main entry points: transport.cpp Device WSS transport · protocol.ts Versioned protocol · index.ts Control Worker · mix.ts Differential mixer
Components 18
Shared contract
- Versioned protocol · Messages, codecs, auth, control semantics, and video tickets.
protocol/src/protocol.ts - Differential mixer
protocol/src/mix.ts
Browser controller
- Controller app
web/src/main.ts - Control safety engine · Applies ownership, arming, e-stop, and profile rules.
web/src/control/engine.ts - Latest-state sender
web/src/transport/sender.ts - Control WSS transport
web/src/transport/websocket.ts - Video transport · Sources tickets and pairs publisher/viewer connections.
web/src/video/video-transport.ts - Video renderer · Selects rendering path and reports stream statistics.
web/src/video/renderer.ts
Control relay plane
- Control Worker · Authenticates and upgrades peer connections into robot rooms.
relay/src/index.ts - Control routes
relay/src/route.ts - Robot room · Forwards frames between controller and device peers.
relay/src/room.ts
Video relay plane
- Video Worker · Independent video WebSocket front door.
video-relay/src/index.ts - Video room · Authorizes tickets and handles publisher/viewer sessions.
video-relay/src/room.ts
ESP32 runtime
- Device runtime · Coordinates network, transport, safety, and hardware output.
firmware/rovelink_device/rovelink_device.ino - Wi-Fi and TLS · Joins Wi-Fi and validates WSS TLS roots.
firmware/rovelink_device/network.cpp - Device WSS transport · Reconnects, authenticates, decodes frames, and reports telemetry.
firmware/rovelink_device/transport.cpp - Motor hardware · Applies armed wheel PWM to physical hardware.
firmware/rovelink_device/hardware_real.cpp - Simulated hardware
firmware/rovelink_device/hardware_sim.cpp
Connections 22
- Controller app → Control safety engine: captures input
- Control safety engine → Latest-state sender: approved current state
- Latest-state sender → Control WSS transport: control frames
- Control WSS transport → Control Worker: authenticated WSS
- Control Worker → Control routes: routes upgrade
- Control routes → Robot room: binds robot room
- Device runtime → Wi-Fi and TLS: initializes
- Wi-Fi and TLS → Device WSS transport: Wi-Fi / TLS
- Device WSS transport → Control Worker: outbound WSS
- Robot room → Device WSS transport: forwarded frames
- Device WSS transport → Device runtime: commands and telemetry
- Device runtime → Differential mixer: throttle and steering
- Differential mixer → Motor hardware: wheel PWM
- Differential mixer → Simulated hardware: wheel PWM
- Versioned protocol → Latest-state sender: encodes frames
- Versioned protocol → Control Worker: auth and wire contract
- Versioned protocol → Device WSS transport: decodes wire contract
- Controller app → Video transport: manages video
- Video transport → Video Worker: ticketed WSS
- Video Worker → Video room: routes sessions
- Video transport → Video renderer: stream frames
- Versioned protocol → Video Worker: video tickets