Device protocol v1
For developers - how a board claims a pairing code and talks to EDEXTRON Cloud over a TLS WebSocket.
This page describes what the standard firmware does. You only need it if you write your own firmware or debug the connection.
1. Claim (pairing)
POST https://iot.edextron.com/device/claim
Content-Type: application/json
{"v":1,"code":"7K2M-QX9D","hardware_id":"edx-7ce8b1d66a54","model":"USB-JST V1.2 + ESP32-C3 Super Mini","fw":"1.1.2"}
code: 4 decimal digits (0000-9999, e.g.1234). Valid for 2 minutes, single use. The gateway never issues a code that another device currently holds.hardware_id:edx-plus the 12 lower-case hex digits of the eFuse MAC.- Body limit 4 KB. At most 10 claims per minute per IP address.
| HTTP | Body | Meaning |
|---|---|---|
| 200 | {"device_key":"edxd_<43 base64url>"} |
Paired. Store the key; the code is used up |
| 400 | INVALID_REQUEST |
Malformed body |
| 409 | HARDWARE_ALREADY_LINKED |
Board belongs to another account. Remove it there first |
| 422 | PAIRING_CODE_INVALID |
Wrong, expired or used code, or the code belongs to a board record linked to different hardware |
| 429 | RATE_LIMITED |
Wait 60 s |
Error bodies look like {"ok":false,"error":{"code":"PAIRING_CODE_INVALID","message":"Invalid, expired, or already used pairing code."}}. On 4xx (except 408/429) the firmware drops the code and stops retrying. Pairing again replaces the board's previous key.
2. WebSocket connection
wss://iot.edextron.com/ws/device
Authorization: Device edxd_<43 base64url characters>
Sec-WebSocket-Protocol: edextron.v1
- Verified TLS only. The firmware pins the expected root CAs and needs correct time (NTP) first.
- Exactly one
Authorizationheader and one subprotocol, no query string, and noOriginheader. Otherwise the upgrade is refused (401, 403, 404 or 503). - UTF-8 JSON text frames, one object per message, at most 2048 bytes, no binary, no fragmentation, no compression. Every message has
"v":1.
3. Messages
t |
Direction | Purpose |
|---|---|---|
hello |
board → cloud | First message, within 5 s: identity, firmware, relay snapshot |
welcome |
cloud → board | Connection accepted; gives connection_id |
set |
cloud → board | Switch one relay before expires_at_ms |
ack |
board → cloud | Result of a set, with the full relay snapshot |
state |
board → cloud | A relay changed (src: cloud, local_web, mqtt, button, boot) |
report |
board → cloud | Full status every 25 s |
io |
board → cloud | Live project data: every output and input by its project id, analog readings (0-100 % of the ADC range) and the active rules. Sent when something changes (at most every 1.5 s) and at least every 10 s. Firmware C3 1.1.5 / DevKit 1.3.1 and newer |
out |
cloud → board | Switch any project output (relay or buzzer) by id before expires_at_ms. Not acknowledged: the next io shows the result. Older firmware ignores it |
error |
cloud → board | SUPERSEDED: another connection for this board took over; retry after 300 s |
{"v":1,"t":"hello","hardware_id":"edx-7ce8b1d66a54","boot_id":"0123456789abcdef0123456789abcdef","seq":0,"fw":"1.1.2","model":"USB-JST V1.2 + ESP32-C3 Super Mini","outputs":[{"index":1,"on":false},{"index":2,"on":false}],"rssi":-45,"ip":"192.168.8.200"}
{"v":1,"t":"welcome","connection_id":"<uuid>","device_id":"<uuid>","server_time_ms":1790000000000,"heartbeat_ms":25000,"ack_timeout_ms":5000,"max_message_bytes":2048}
{"v":1,"t":"set","connection_id":"<uuid>","boot_id":"<32 hex>","cid":"<uuid>","index":1,"state":"TOGGLE","expires_at_ms":1790000005000}
{"v":1,"t":"io","connection_id":"<uuid>","boot_id":"<32 hex>","status":"ok","project_version":3,"outputs":[{"id":"relay1","on":true},{"id":"buzzer1","on":false}],"inputs":[{"id":"water1","active":true,"level":42}],"rules":[0],"uptime_s":300,"free_heap":150000}
{"v":1,"t":"out","connection_id":"<uuid>","boot_id":"<32 hex>","id":"buzzer1","state":"ON","expires_at_ms":1790000005000}
{"v":1,"t":"ack","connection_id":"<uuid>","boot_id":"<32 hex>","cid":"<uuid>","ok":true,"seq":7,"outputs":[{"index":1,"on":true},{"index":2,"on":false}]}
{"v":1,"t":"ack","connection_id":"<uuid>","boot_id":"<32 hex>","cid":"<uuid>","ok":false,"code":"EXPIRED","seq":7,"outputs":[{"index":1,"on":true},{"index":2,"on":false}]}
{"v":1,"t":"state","connection_id":"<uuid>","boot_id":"<32 hex>","seq":8,"outputs":[{"index":1,"on":false},{"index":2,"on":false}],"src":"button"}
{"v":1,"t":"report","connection_id":"<uuid>","boot_id":"<32 hex>","seq":8,"outputs":[{"index":1,"on":false},{"index":2,"on":false}],"rssi":-46,"ip":"192.168.8.200","uptime_s":300,"free_heap":90000}
{"v":1,"t":"error","code":"SUPERSEDED","retry_after_ms":300000}
4. Rules
boot_idis 128 random bits (32 lower-case hex) generated at every boot.seqis a 32-bit counter that increases after every output operation.- The board executes
setonly ifconnection_idandboot_idmatch, its clock is synchronised, andexpires_at_mshas not passed. It checks the deadline again right before touching the GPIO. - Negative ACK codes:
EXPIRED,BUSY,INVALID_OUTPUT,CLOCK_UNSYNCED. - The board remembers the last 32
cids of the current boot. A repeatedcidgets the same ACK again and is never executed twice. - The cloud waits 5 s for an ACK. With no ACK the command becomes
unknownand the cloud closes the socket so the next connection starts from a fresh snapshot. - Heartbeat: the cloud pings every 25 s. It closes the connection after 75 s without a matching pong or without a
report. The board also pings. - Reconnect delay: random between half and all of
min(60 s, 2^attempt s). Attempts reset after 120 s of healthy connection. - Disconnecting never changes relay states, and the cloud never queues commands. At boot all relays start OFF.
Close codes
| Code | Reason |
|---|---|
| 1002 | Unknown message type or version, or hello missing/repeated |
| 1003 | Binary or fragmented message |
| 1008 | Invalid message, rate limit (120 messages/min), hello timeout, or board removed |
| 1009 | Message larger than 2048 bytes |
| 1012 | Service restarting, or ACK timeout |
| 4003 | Device key replaced or revoked |
| 4009 | Superseded by a newer connection |