This guide explains how to use WebSocket to establish real-time, two-way communication between your computer and the robot driver board on Linux or macOS.

Unlike HTTP, WebSocket enables full-duplex communication with millisecond-level latency, making it ideal for real-time robot control, sensor monitoring, or telemetry visualization.

📦 GitHub Repository

https://github.com/EffectsMachine/robot_driver_with_esp32s3_lite


1. How It Works

The robot driver board includes a lightweight WebSocket server that runs on port 80, sharing the same port as its HTTP interface.

The WebSocket endpoint path is fixed at /ws.

When your PC connects to ws://<ESP32_IP>:80/ws, a persistent data channel is created:

  1. Handshake: The PC initiates a TCP connection and upgrades to WebSocket.
  2. Command Transmission: The PC can continuously send JSON-based control commands.
  3. Real-Time Feedback: The board actively pushes back telemetry, such as servo status, sensor readings, or warning messages.

Example message:

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

This message updates line 1 of the OLED with the text “webSocket msg”.


2. Setup Environment

2.1 Install Python

Make sure Python 3.10 or newer is installed.

Check your version:

python3 --version