Protocol Specification
Raina Link Protocol (RLP v1)
Binary socket transport specification between microcontrollers and the Raina Gateway.
Design Goals
RLP was designed specifically to eliminate the overhead of MQTT and HTTP on low-power IoT controllers (ESP8266, ESP32, STM32, RP2040):
- Zero Broker Overhead: Connects directly via persistent TCP/TLS stream.
- Numeric Channel Mapping: Variable names are mapped to 16-bit numeric channels in the initial HELLO handshake. Subsequent telemetry transmissions use only 2 bytes per variable.
- Zero Dynamic JSON Allocations: Packets are encoded in raw binary format, eliminating heap fragmentation.
1. Network Ports
| Port | Transport | Target Environment |
|---|---|---|
| 9000 | Raw TCP (Plaintext) | Local development, LAN, or VPN-secured microcontrollers |
| 8883 | TLS 1.2 / 1.3 | Production internet deployments with CA verification |
2. Frame Header Format (4 Bytes)
Every packet begins with a standard 4-byte header:
+-------------+-------------+---------------------------+
| Type (1B) | Flags (1B) | Length (2B, Big-Endian) | Header (4 Bytes)
+-------------+-------------+---------------------------+
| Payload (0 to 65535 Bytes) |
+-------------------------------------------------------+
| Type (1B) | Flags (1B) | Length (2B, Big-Endian) | Header (4 Bytes)
+-------------+-------------+---------------------------+
| Payload (0 to 65535 Bytes) |
+-------------------------------------------------------+
3. Packet Types
| Opcode | Name | Sender | Description |
|---|---|---|---|
| 0x01 | HELLO | Device | Initial authentication with deviceId, token, and channel map. |
| 0x02 | WELCOME | Server | Authentication accepted; acknowledges device session. |
| 0x03 | DATA | Device | Single metric telemetry update. |
| 0x04 | BATCH | Device | Multi-metric batch update sent in a single atomic transmission. |
| 0x05 | COMMAND | Server | Downlink actuator command to device with unique 32-bit Command ID. |
| 0x06 | ACK | Device | Confirmation acknowledging COMMAND execution. |
| 0x07 | PING | Both | Heartbeat liveness check with nonce. |
| 0x08 | PONG | Both | Heartbeat reply mirroring PING nonce. |