# Protocol support

| Protocol | Supported | Boundaries |
| --- | --- | --- |
| MQTT 3.1.1 | Native async TCP, QoS0 subscription, wildcard filter, clean session, username/password, retained payloads, keepalive, reconnect/resubscribe | No TLS, QoS1/2 ingestion, durable session, broker or publishing adapter |
| Modbus TCP | FC03 holding / FC04 input registers, unit 0..255, address 0..65535, quantity 1..125, transaction correlation | Writes, coils, pipelining and Modbus Security are outside scope |
| [Modbus RTU](modbus-rtu.md) | FC03/FC04, serial framing and CRC, unit 1..247, Windows and Linux | One configured device per port. Writes, broadcast and shared-bus scheduling are outside scope |
| CoAP | Read-only GET to a configured unicast IPv4 endpoint, asynchronous UDP, confirmable and separate responses, JSON Content-Format 50 | No DTLS, Observe, blockwise transfer, query parameters or message retransmission |
| Mock | Deterministic finite temperature sequence with interval | Test/example data only |

MQTT frame size includes fixed header and body (32..65536 bytes). Payload must
be a valid UTF-8 flat JSON object containing up to 256 scalar fields. Duplicate
keys, non-finite numbers and nested values are rejected as individual readings.
Malformed protocol frames close the connection.
The adapter requests QoS0 and rejects a nonzero subscription grant. Reconnection
uses a new clean session; no continuity or loss-free delivery is promised.
Repeated application measurements are retained, not globally deduplicated.

The broker may send a retained PUBLISH before SUBACK (MQTT section 3.8.4).
Up to 64 such normalized events are buffered with an overall SUBACK deadline.
The client schedules PINGREQ after one third of `keep_alive_s` (ten seconds by
default), even while deliveries continue. The PINGRESP deadline is the smaller
of that interval and `timeout_ms`. A missed response closes the session so the
runtime can reconnect.
Any timeout after a partial frame closes the socket to avoid stream desynchronization.

Modbus validates MBAP transaction, protocol=0, unit, declared size, function and
byte count before decoding. Exceptions surface with their numeric code. Each
connection has one outstanding read. A transaction increments modulo 65536.
U16/I16 use one register; U32/I32/F32 use two, high-word-first by default.
Float NaN/Infinity are rejected as individual readings on the same connection.
Address numbers are zero-based wire addresses,
not human-facing 40001-style register notation.

CoAP sends one confirmable GET per poll. It accepts a matching piggybacked
response or a separate response, acknowledging confirmable responses.
Datagrams are capped at 1152 bytes. Poll timeouts close the socket and use
the normal runtime reconnect budget. Invalid JSON counts as a rejected
reading without closing the socket. Run the gateway against a configured
device with `moon run cmd/moonedge --target native -- run examples/config/coap.json`
after adjusting the example endpoint and resource path.

References: [OASIS MQTT 3.1.1](https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html),
[Modbus specifications](https://www.modbus.org/modbus-specifications),
and [CoAP RFC 7252](https://www.rfc-editor.org/rfc/rfc7252).
No specification documents or third-party test datasets are redistributed.
