There are two WebSocket servers:
-
Terminal WebSocket used to stream data to WebUI and exchange internal data
-
Data WebSocket used to exchange data with external clients (not used by WebUI)
Terminal WebSocket
Section titled “Terminal WebSocket”use subprotocol webui-v3 the port depends on the firmware. Please refer to the firmware documentation
text mode
Section titled “text mode”Reserved
Messages between WebUI / ESP
Format: <label>:<message>
-
from ESP to WebUI
-
currentID:<id>Sent when client is connecting, it is the last ID used and become the active ID -
activeID:<id>Broadcast current active ID, when new client is connecting, client without this is<id>should close, ESP WS Server close all open WS connections but this one also -
PING:<time left>:<time out>It is a response to PING from client to inform the time left if no activity (see below) -
ERROR:<code>:<message>If an error raise when doing upload, it informs client it must stop uploading because sometimes the http answer is not possible, or cannot cancel the upload, this is a workaround as there is no API in current webserver to cancel active upload -
NOTIFICATION:<message>Forward the message sent by [ESP600] to webUI toast system -
SENSOR: <value>[<unit>] <value2>[<unit2>] ...The sensor connected to ESP like DHT22
-
-
from WebUI to ESP
PING:<current cookiesessionID / none >if any, or “none” if none
binary mode
Section titled “binary mode”Reserved
-
from ESP to WebUI stream data from ESP to WebUI
-
from WEBUI to ESP
[-> File transfer from WebUI to ESP: not implemented yet]
Data WebSocket
Section titled “Data WebSocket”use sub protocol arduino the port depends on the firmware. Please refer to the firmware documentation
text mode
Section titled “text mode”This mode is used to transfer all G-code commands and their responses from the printer/CNC.
binary mode
Section titled “binary mode”This mode is used to transfer files to/from the ESP board. (not implemented yet)
It uses frames of 1024 bytes and can be increased after testing.
The frame format is: 2 bytes: for frame type 2 bytes: for frame size to check some integrity, currently as already part of frame no checksume is used x bytes : extra data according frame type
Frame types
Section titled “Frame types”Query status frame
Section titled “Query status frame”type: client -> esp Status Request:
S | R | 0 | 0 |
with hexadecimal values:
| 0x53 | 0x52 | 0 | 0 |
Response frame uses an inverted header: Response Status:
R | S | 0 | 1 | A |
with hexadecimal values:
| 0x52 | 0x53 | 0 | 1 | 0x41 |
The first byte of the response indicates the state:
| Code | Hexa | Meaning |
|---|---|---|
B | 0x42 | busy |
O | 0x4F | idle/ok |
E | 0x45 | error |
A | 0x41 | abort |
|D | 0x44|download ongoing
|U | 0x55|upload ongoing
Extra data may be added:
For Error:
Section titled “For Error:”error code and string, 1 byte : error code: 0->255 1 byte : string size 0->255 XX bytes for the string:
R | S | x | x | C | 4 | X | .. | .. |
For Upload:
Section titled “For Upload:”Upload information: 1 byte : path size 0->255 XX bytes : the path string 1 byte : the filename size 0->255 xx bytes : filename string 4 bytes : total file size 4 bytes : currently processed bytes 4 bytes : last packet id processed
R | S | x | x | U | X | .. | .. | X | .. | .. | S1 | S1 | S1 | S1 | S2 | S2 | S2 | S2 |
For Download:
Section titled “For Download:”Download information: 1 byte : path size 0->255 XX bytes : the path string 1 byte : the filename size 0->255 xx bytes : filename string 4 bytes : total file size 4 bytes : currently processed bytes 4 bytes : last packet id processed
R | S | x | x | D | X | .. | .. | X | .. | .. | S1 | S1 | S1 | S1 | S2 | S2 | S2 | S2 |
Start upload frame
Section titled “Start upload frame”Header is:
S | U | 0 | 0 |
The content is: 1 byte : path size 0->255 XX bytes : the path string 1 byte : the filename size 0->255 xx bytes : filename string 4 bytes : total file size
S | U | x | x | D | X | .. | .. | X | .. | .. | S1 | S1 | S1 | S1 |
If the answer is:
U | S | 0 | 1 | O |
It means transfer can start.
Transfer upload frame
Section titled “Transfer upload frame”Header is:
U | P | x | x | ID | ID | ID | ID | .. | .. |
4 bytes is packet id XXXX bytes is data
if packet is received the answer is:
P | U | 0 | 5 | O | ID | ID | ID | ID |
Start download frame
Section titled “Start download frame”Header is:
S | D | 0 | 0 |
The content is: 1 byte : path size 0->255 XX bytes : the path string 1 byte : the filename size 0->255 xx bytes : filename string 4 bytes : total file size
S | D | x | x | D | X | .. | .. | X | .. | .. | S1 | S1 | S1 | S1 |
If the answer is:
D | S | 0 | 1 | O |
It means transfer can start.
Transfer download frame
Section titled “Transfer download frame”Header is:
D | P | x | x | ID | ID | ID | ID | .. | .. |
4 bytes is packet id XXXX bytes is data
if packet is received the answer is :
P | D | 0 | 5 | O | ID | ID | ID | ID |
Command frame
Section titled “Command frame”Header is:
C | M | 0 | 1 | X |
Commands:
| Code | Hexa | Meaning |
|---|---|---|
A | 0x41 | abort |
Abort command frame
C | M | 0 | 1 | A |