Protocol messages
Machine-readable version: docs/api/asyncapi.yaml
in the repo (AsyncAPI 2.6 — used instead of OpenAPI because the interaction
is connection-oriented, binary, and server-initiated: the server polls, the
device never calls anything on its own, which OpenAPI/REST has no way to
express).
The server listens on DEVICE_PORT (default 9000). Devices dial in; the
server never dials out (cmd/probe dials out, but only as a development
test client — see Server behavior).
The modbus/* channels below are for the Modbus models (Nexus, Yorker). The
IP20 3K6/5K speaks a text command protocol instead: the same steps
(health check, serial, telemetry, read, write) are text queries answered by
one line each (F\r → #230.0 015 024.0 50.0\r), with no batching. Its
at/* channels are unchanged, since the DTU answers those itself. See
IP20 3K6/5K.
Channels
In the order they occur on a connection:
| Channel | When | Publish (server → device) | Subscribe (device → server) |
|---|---|---|---|
at/identity | First, once per connection — before any Modbus traffic (skipped when tcpserver has no device database) | AT+DTUPN? — plain text, not Modbus-framed | The logger's own part number, which is the devices primary key. A failure leaves the connection unidentified, not closed |
modbus/health-check | Once for a forced or remembered profile, else once per candidate during DetectProfile | Single-register read at the profile's first readable telemetry register | Accepted only if structurally valid and the decoded value passes a per-unit plausibility check |
modbus/identity | Once per connection, after the profile is known (the address is model-specific) | Read of the profile's declared identity_register (Aotai Hybrid: 0x0564, 10 registers) | The inverter's serial as packed ASCII. A failure costs verification of the pairing, not service |
at/dispose | Only for a logger whose device was erased, instead of serving it | AT+WFLKAP=… — overwrites the logger's WiFi association | Silence means applied, and the connection is closed. A refusal (W003) or failed send leaves it served as an ordinary unidentified connection and is retried on its next connection; only commands actually delivered count toward the 3-attempt limit. See below |
modbus/batch-discovery | Once per registered device, ever — only when no batch limit is remembered | Binary-search read at increasing/decreasing quantity, same start address | A valid, correlated response narrows the search upward; any failure narrows it downward |
at/heartbeat | Every PollInterval (30s), every connection, registered or not | AT+HTBT? — plain text, not a Modbus read | Any error closes the connection. This is the DTU firmware's own mandated keep-alive: per the vendor guide the cloud server must send it every ~30s or the DTU tears the connection down itself. A Modbus read on the same cadence is not a substitute |
modbus/telemetry-batch | After a successful heartbeat, when telemetry is due: every 5 min, or 30s while watched. Never for an unidentified connection | One batch read per contiguous register range, sized to the device's batch limit | Each register in the batch decoded per its data_type/scale; batch failures mark their registers failed and the cycle continues |
modbus/register-write | On a device_write command from ws-gateway | Function 0x06, or 0x10 with quantity 1 — whichever the register's spec declares. Retried once on a corrupted reply, never on a timeout or exception | Must echo the exact address + value (0x06) or address + quantity (0x10). Preceded and followed by a single-register read (when readable) to report the previous and read-back value |
modbus/register-read | On a read_registers command, and around each write | Function 0x03/0x04 reads, coalesced; function 0x03 for a register whose only declared code is a write code | Decoded like telemetry |
AT commands
Two channels are plain text rather than Modbus. They are terminated \r\n
and answered on the same socket, and the DTU — not the inverter — handles
them.
The vendor manual's documented reply formats are not reliable: it gives
AT+HTBT's reply as AT+HTBT\r\n while the same hardware actually sends
AT+HTBT:. Everything below is captured from a real unit (DTU type
WFBLE.DTU.Module-x02, firmware 8.50.18.3), not transcribed from the
manual. Parse defensively and match on the AT+<CMD>: prefix.
| Request | Bytes | Observed reply |
|---|---|---|
AT+DTUPN? | 41 54 2B 44 54 55 50 4E 3F 0D 0A | AT+DTUPN:I30000252761006466 |
AT+HTBT? | 41 54 2B 48 54 42 54 3F 0D 0A | AT+HTBT: (nothing after the colon) |
AT+DTUTYPE? | 41 54 2B 44 54 55 54 59 50 45 3F 0D 0A | AT+DTUTYPE:WFBLE.DTU.Module-x02 |
AT+FWVER? | 41 54 2B 46 57 56 45 52 3F 0D 0A | AT+FWVER:8.50.18.3 |
AT+HWVER? | 41 54 2B 48 57 56 45 52 3F 0D 0A | AT+HWVER:8.0.0.1 |
AT+WFLKAP=disposed,… | — | no reply when applied; W003 when refused; R001 for an unknown command |
AT+DTUPN? returned the identical value across repeated reads and answered
before any Modbus traffic. AT+DTUPN?, AT+HTBT? and AT+WFLKAP= are used
in production; the other three are recorded because they are the cheap path
to fleet-wide firmware and hardware-revision visibility.
AT+WFLKAP= is how an erased device's logger is disposed of: it replaces the
stored WiFi association with a network named disposed that does not
exist, so the real credentials are gone and the logger can no longer reach
us. Recovery is re-provisioning over BLE, like any new installation. Its
reply convention is backwards from the others, measured on the bench unit:
a write the firmware applies produces no reply at all (the device leaves
the network), so a read timeout is the expected success and only an
explicit W003 is a failure. The candidates that were rejected, each
measured on real hardware:
| Command | What it actually did |
|---|---|
AT+RESTORE | Only reboots — back in 1.9s with cloud, server and WiFi settings intact |
AT+ENCLDSRV1=OFF | Stops the device dialling in, but leaves the previous owner's WiFi credentials readable in plain text |
AT+WFLKAP= (empty) | Refused, W003 |
Every AT reply is read as one short text line whose first byte must be A;
anything else means the socket is out of sync (for example the tail of an
earlier Modbus frame) and fails the exchange rather than being parsed.
:::danger The reported part number's case differs from the database
The DTU answers I30000252761006466 (capital I) for a device registered
from its QR label as i30000252761006466 (lowercase i). Same 18 characters,
one character of case apart.
A plain WHERE logger_id = $1 against the device-reported value matches
nothing — every device would silently resolve as unregistered. The
server therefore converts the reported part number to lowercase, its
canonical spelling, the moment it is read (internal/deviceid), and the
inverter serial read over Modbus to uppercase; the database refuses any
other spelling (migration 0031). See
Server behavior's connect flow.
:::
Reading the inverter's serial
The serial is not carried by anything: a Modbus response contains register values and nothing else — no envelope, no header. It has to be asked for, which is why identity is resolved once per connection rather than per telemetry message.
Its address is model-specific, declared per profile as identity_register
rather than discovered by matching register names — the three vendor specs
in this repo call it three different things (sn,
serial_number_sn_code, sn_number).
| Profile | Register | Address | Width | Verified value |
|---|---|---|---|---|
| Nexus | sn | 0x0564 | 10 registers | Y24C16070610 |
| Yorker | serial_number_sn_code | 0x0000 (mirrored at 0x1020) | 10 registers | M25060017-1H00465 |
| IP20 3K6/5K | inverter_sn | ASCII query I (not Modbus) | 27 characters | placeholder: 27 repeated 2s, treated as no serial (see IP20 3K6/5K) |
Both widths were settled on real hardware, not taken from the documents.
Reading 20 registers from the IP20 address is refused with Modbus exception
0x04, which fixes the field at 10 registers / 20 bytes.
:::warning Both vendor workbooks model these fields wrongly
Aotai's sn is documented as U16, length 1 — a single 16-bit number, for a
field its own notes describe as 20 bytes of ASCII. The IP20 serial is
documented as ten separate one-register entries, which is what a 20-byte
ASCII field looks like when each register gets its own row in a spreadsheet.
Modelled either way the serial cannot be read at all, and the failure is
silent: the register decodes to a meaningless number rather than erroring.
Both are corrected in server/internal/modbus/specs/*.json, with the
verified bytes recorded in each register's notes.
The IP20 entries are additionally marked RW with function code 16, so the
hardware will let a serial be overwritten. This platform forces them to R:
identity rests on trusting what the device reports, and an API that can
rewrite it undermines exactly that.
:::
Request (Aotai Hybrid, Modbus RTU, slave 1, read 10 registers at 0x0564):
01 03 05 64 00 0A 84 DE
Response (20 bytes of packed ASCII, two characters per register, high byte
first, terminating at the first non-printable byte):
01 03 14 59 32 34 43 31 36 30 37 30 36 31 30 00 … → "Y24C16070610"
▲ ─────────────────────────────────────
│ Y 2 4 C 1 6 0 7 0 6 1 0 padding
byte count = 0x14 = 20
Message shapes
Every Modbus channel above uses these shapes, chosen per transport
(MODBUS_TRANSPORT=rtu or tcp). A response is always read as one
complete frame — sized from its header, then read to exactly that length —
because a transparent serial bridge delivers a large response across several
TCP segments:
ReadRequestRTU — 8 bytes
[slaveAddr][functionCode][startAddrHi][startAddrLo][qtyHi][qtyLo][crcLo][crcHi]
ReadRequestTCP — 12 bytes (7-byte MBAP header + 5-byte PDU)
[transactionIdHi][transactionIdLo][protocolId=0x0000][lengthHi][lengthLo][unitId][functionCode][startAddrHi][startAddrLo][qtyHi][qtyLo]
ReadResponseRTU
[slaveAddr][functionCode][byteCount][data...][crcLo][crcHi]
Rejected if the CRC doesn't match, or if functionCode doesn't match the
request just sent.
ReadResponseTCP
[transactionIdHi][transactionIdLo][protocolId=0x0000][lengthHi][lengthLo][unitId][functionCode][byteCount][data...]
Rejected if the MBAP length field is inconsistent with the frame size, the
transaction ID doesn't match the in-flight request, or functionCode
doesn't match.
WriteSingleRegister (function 0x06) — 8 bytes RTU
[slaveAddr][0x06][addrHi][addrLo][valueHi][valueLo][crcLo][crcHi]
Same shape as a read request, with the value in place of the quantity. A successful response echoes the request verbatim; anything else is a failure, because a device that silently ignored the write would otherwise look like one that applied it.
WriteMultipleRegisters (function 0x10), quantity 1 — 11 bytes RTU
[slaveAddr][0x10][addrHi][addrLo][0x00][0x01][byteCount=0x02][valueHi][valueLo][crcLo][crcHi]
Needed because every writable register on the Yorker profile documents function 16, even for a single scalar setting. The response echoes address and quantity only — not the value — which is why every write is followed by a read-back. The TCP variants of both carry the usual MBAP header in place of the CRC.
ExceptionResponse
A function code with the high bit set (0x80 | requestedFn) plus one
exception-code byte (standard Modbus: 0x01 Illegal Function, 0x02
Illegal Data Address, 0x03 Illegal Data Value, 0x04 Slave Device
Failure). Always treated as a request failure — the specific code is
currently only logged, not branched on.
Response correlation
Every response is validated against what was actually just requested, not merely accepted because it parsed: the MBAP transaction ID for TCP framing, and the function code for both transports. A mismatch is treated as a stale answer to an earlier, already-abandoned request (for example one that timed out and arrived late) and rejected rather than silently stored under the wrong register. See Connection lifecycle for the full round-trip diagram, or build one of these frames yourself in the Sandbox.