This guide is for Windows users who want low-latency, real-time control of their robot through Wi-Fi.

By using WebSocket, your PC and the robot driver board can exchange data in both directions instantly β€” without the delay or polling limitations of traditional HTTP requests.

πŸ“¦ GitHub Repository:

https://github.com/EffectsMachine/robot_driver_with_esp32s3_lite


1. Why WebSocket?

WebSocket is a full-duplex protocol built on TCP, allowing persistent, two-way communication between your computer (host) and the robot (device).

It’s ideal for robotics applications that require continuous state updates and fast command response β€” typically up to 60 messages per second.

Feature Description
βœ… Low latency & persistent connection The connection is established once, avoiding repeated handshakes like HTTP. Response latency can reach the millisecond level β€” perfect for motion control.
βœ… True bidirectional data flow Both sides can actively send data β€” commands from the PC and status feedback from the robot β€” with no need for polling.
βœ… Wide compatibility Uses the same ports as HTTP (80/ws, 443/wss), bypasses most firewalls, and is supported in all major languages (Python, JavaScript, etc.).
⚠️ Requires connection management You’ll need to handle reconnection if Wi-Fi drops β€” unlike HTTP’s one-shot model.
⚠️ Slightly harder to debug Standard browsers can’t test it directly; use tools like Postman (WebSocket mode) or scripts instead.

2. How It Works

The ESP32-based driver board runs a lightweight WebSocket server that shares the same port (80) as HTTP, with the fixed endpoint /ws.

Once powered on, the board automatically starts the WebSocket service.

Communication workflow:

  1. Connection β€” The PC sends a handshake request and establishes a persistent link.
  2. Data exchange β€”
  3. Disconnection β€” Either side can close the link, or it will drop automatically if the network disconnects (you may need to reconnect manually).

All commands use the same JSON format as HTTP, for example:

{"T":202,"line":1,"text":"webSocket msg","update":1}

3. Environment Setup