Skip to content

Web Sockets

There are two WebSocket servers:

  • Terminal websocket — streams data to WebUI and exchanges internal messages
  • Data websocket — exchanges data with an external client (not used by WebUI)

Uses subprotocol webui-v3. Port is web port + 1 (e.g. 80 → 81).

Reserved messages between WebUI and ESP. Format: <label>:<message>

ESP → WebUI:

  • currentID:<id> Sent when client connects. It is the last used ID and becomes the active ID.

  • activeID:<id> Broadcast when a new client connects. Clients without this ID should close. The ESP WS server closes all open WS connections except this one.

  • PING:<time left>:<time out> Response to a PING from client, informing the time remaining before inactivity timeout.

  • ERROR:<code>:<message> Raised during upload when the HTTP answer cannot cancel it. This is a workaround: there is no API in the current webserver to cancel an active upload.

  • NOTIFICATION:<message> Forwards the message sent by [ESP600] to the WebUI toast system.

  • SENSOR: <value>[<unit>] <value2>[<unit2>] ... Sensor data (e.g. DHT22 temperature/humidity).

WebUI → ESP:

  • PING:<cookieSessionID | none> Keepalive ping. Sends the current session cookie ID, or none if not authenticated.

ESP → WebUI: stream data from ESP to WebUI. WebUI → ESP: file transfer — not implemented yet.


Uses subprotocol arduino. Port is configurable (e.g. 8282).

Used to transfer all G-code commands and their responses from the CNC/printer.

Used to transfer files to/from the ESP board.

Every binary frame uses the same fixed 4-byte header:

Byte 0Byte 1Byte 2–3Byte 4+
Opcode MSBOpcode LSBPayload length (uint16_t LE)Payload
  • Opcode: 2 ASCII bytes identifying the frame type (e.g. SR, UP).
  • Payload length: number of bytes that follow the header, little-endian uint16_t.
  • All multi-byte integer fields in the payload are little-endian.
  • Maximum data payload per packet: 1024 bytes (may be increased after testing).

Client → ESP (no payload):

SR0x000x00

ESP → Client (1-byte payload: status code):

RS0x000x01STATUS

Status codes:

CodeHexMeaning
O0x4FIdle / OK
B0x42Busy
E0x45Error
A0x41Abort
U0x55Upload ongoing
D0x44Download ongoing

Additional payload for E (Error):

After the status byte: 1 byte error code, 1 byte string length, then the string.

RSPL_LOPL_HIEERR_CODESTR_LENSTR…

Additional payload for U (Upload ongoing):

After the status byte: path size (1 byte), path, filename size (1 byte), filename, total file size (uint32_t LE), processed bytes (uint32_t LE), last packet ID (uint32_t LE).

RSPL_LOPL_HIUPATH_SZPATH…NAME_SZNAME…TOTAL(4)DONE(4)LAST_ID(4)

Additional payload for D (Download ongoing):

Same layout as Upload ongoing, with D status byte.

RSPL_LOPL_HIDPATH_SZPATH…NAME_SZNAME…TOTAL(4)DONE(4)LAST_ID(4)

Client → ESP:

Payload: path size (1 byte), path, filename size (1 byte), filename, total file size (uint32_t LE).

SUPL_LOPL_HIPATH_SZPATH…NAME_SZNAME…FILE_SIZE(4)

ESP → Client (OK — transfer can start):

US0x010x00O

ESP → Client (Error — transfer rejected):

US0x010x00E

Client → ESP:

Payload: packet ID (uint32_t LE), then data bytes.

UPPL_LOPL_HIID(4)DATA…

ESP → Client (ACK):

PU0x050x00OID(4)

Sent by the client after the last upload packet.

Client → ESP (no payload):

EU0x000x00

ESP → Client (OK):

UE0x010x00O

ESP → Client (Error):

UE0x010x00E

Client → ESP:

Payload: path size (1 byte), path, filename size (1 byte), filename.

SDPL_LOPL_HIPATH_SZPATH…NAME_SZNAME…

ESP → Client (OK — transfer can start):

Payload: status O, then total file size (uint32_t LE).

DS0x050x00OFILE_SIZE(4)

ESP → Client (Error):

DS0x010x00E

ESP → Client:

Payload: packet ID (uint32_t LE), then data bytes.

DPPL_LOPL_HIID(4)DATA…

Client → ESP (ACK):

PD0x050x00OID(4)

Sent by the ESP after the last download packet.

ESP → Client (no payload):

ED0x000x00

Client → ESP (ACK):

DE0x010x00O

Sent by either side when a packet is missing or corrupted. The sender must retransmit starting from the requested packet ID.

NK0x040x00ID(4)

Client → ESP (1-byte payload: command code):

CM0x010x00CMD

Command codes:

CodeHexMeaning
A0x41Abort current transfer

Abort frame:

CM0x010x00A

Client ESP
|--- SU (path, name, size) --->|
|<-- US (O) -------------------|
|--- UP (id=0, data) --------->|
|<-- PU (O, id=0) -------------|
|--- UP (id=1, data) --------->|
|<-- PU (O, id=1) -------------|
| ... |
|--- EU ---------------------->|
|<-- UE (O) -------------------|
Client ESP
|--- SD (path, name) -------->|
|<-- DS (O, file_size) -------|
|<-- DP (id=0, data) ---------|
|--- PD (O, id=0) ----------->|
|<-- DP (id=1, data) ---------|
|--- PD (O, id=1) ----------->|
| ... |
|<-- ED ----------------------|
|--- DE (O) ----------------->|
Client ESP
|--- CM (A) ----------------->|