Open source · MIT license
LunaLink™
A lightweight binary protocol that moves data between field nodes and a central master. When the network drops, nothing is lost: data waits on the device and arrives in order once the link returns.
Node to Master, and back
A node collects data from local equipment and sends it to the master. The master centralizes it and sends authorized write commands back.
- PLCs and sensors: Local equipment on site
- Node: Edge device: collects, buffers, sends
- Master: Server: accepts, acknowledges, routes
- SCADA and historian: Central monitoring and records
One frame, byte by byte
Every message travels in one frame: a 15-byte header, a MessagePack payload and a 2-byte CRC. Below is the real Ping frame from the specification. Hover or tap a field.
4c 4c 4e 4b 01 0c 00 00 00 00 01 00 00 00 0a 91 cf 00 00 01 9b 76 da a8 00 84 d227 bytes in total: 17 bytes of framing, 10 bytes of data.
- Magic (Offset 0 · 4 B):
4c 4c 4e 4b - "LLNK". Every frame starts with these 4 bytes. Any other value means the stream is broken, and the connection is closed.
- Version (Offset 4 · 1 B):
01 - 1. Version of the frame layout. New features never change it: they are negotiated, so older nodes keep working.
- Message type (Offset 5 · 1 B):
0c - 0x0C · Ping. One of 21 message types. A receiver simply ignores a type it does not know.
- Flags (Offset 6 · 1 B):
00 - 0x00. Bit 0: the payload is LZ4 compressed. Bit 1: the receiver must answer with an Ack. The other bits are reserved.
- Sequence (Offset 7 · 4 B):
00 00 00 01 - 1. Frame counter within the connection, used only to match Acks. Telemetry order is kept separately by the durable NodeSequence.
- Length (Offset 11 · 4 B):
00 00 00 0a - 10. Payload size in bytes, at most 4 MiB. A small device announces its own limit with max-payload, and the master splits data to fit.
- Payload (Offset 15 · 10 B):
91 cf 00 00 01 9b 76 da a8 00 - [1767225600000]. A MessagePack array: fields travel by index, not by name. Here it is the Ping timestamp, 1 January 2026, 00:00 UTC, in milliseconds.
- CRC-16 (Offset 25 · 2 B):
84 d2 - 0x84D2. CRC-16/CCITT-FALSE over header and payload. A damaged frame is dropped and the stream stays aligned. On TLS both sides can agree to skip it.
The life of a session
The node always opens the connection. Once the master has verified it, telemetry, heartbeats and write commands share the same TCP connection.
TCP + TLS 1.3(Node → Master): the node opens the connectionHello(Node → Master): NodeId, token and capabilitiesHelloAck(Master → Node): accepted, agreed capabilitiesTagDelta(Node → Master): values, NodeSequence = 42TagDeltaAck(Master → Node): processed, next expected 43Heartbeat(Node → Master): every 5 secondsHeartbeatAck(Master → Node): master clockTagWriteCmd(Master → Node): with CommandId and expiryTagWriteAck(Node → Master): result: SucceededGoodbye(Node → Master): planned stop
Why data is never lost
The node writes every batch to disk before sending it and deletes it only after the master confirms it was processed. The master remembers the last sequence it processed for each node.
Node outbox
Every batch gets the next NodeSequence and stays in SQLite until its TagDeltaAck arrives.
A delivery window keeps up to 16 batches in flight per round trip, so a backlog drains more than ten times faster on a slow link. Order is still enforced batch by batch.
Master inbox
The last processed batch is 41. The decision depends on the incoming sequence (s):
s = 42Next batch: Processed, answer: next expected 43.s ≤ 41Duplicate: Not applied again, but confirmed so the node removes it from its outbox.s ≥ 43Gap: Rejected. The node sends its current state as a resync baseline and the master continues from there.
Message types
All messages share the same frame and differ only in the type byte. Unknown types are ignored, so older peers do not break when the protocol grows.
0x01Hello: Node → Master0x02HelloAck: Master → Node0x03TagDelta: Both directions0x04TagWriteCmd: Master → Node0x05TagWriteAck: Node → Master0x06Heartbeat: Node → Master0x07HeartbeatAck: Master → Node0x08SnapshotReq: Node → Master0x09SnapshotResp: Master → Node0x0ASubscribe: Node → Master0x0BError: Both directions0x0CPing: Node → Master0x0DPong: Master → Node0x0EAck: Both directions0x0FTagDeltaAck: Master → Node0x10HistoryBatch: Node → Master0x11HistoryBatchAck: Master → Node0x12Goodbye: Node → Master0x13BrowseReq: Master → Node0x14BrowseResp: Node → Master0x15EventAck: Master → Node
Capability negotiation
The node states in Hello what it can receive, and the master returns what it agrees to in HelloAck. This is how new features are added: an unknown token is simply ignored.
no-compression: The master never sends this node a compressed frame. For microcontrollers without an LZ4 decoder.max-payload=<n>: The node's receive buffer. The master splits snapshots and broadcasts to fit it.window=<n>: How many batches may be in flight without an ack, up to 256.lz4-block: A portable LZ4 container that any language can decode.no-crc: No CRC on a TLS connection, because TLS already checks every byte.goodbye: Goodbye before a planned stop, so the master knows why the node left.events-v1: Events and alarms travel the same durable path as values, and operator acknowledgements go back.browse-v1: The master lists a node's tags without prior configuration.arrays-v1: Array and blob types: Int64Array, Float64Array, StringArray, Blob.master-delta: A node receives tags of other nodes it subscribed to, through the master.
The specification is open
The full specification, test vectors, a conformance tool and a Wireshark dissector are on GitHub. Write your own node and check it against the conformance suite.
Built for unreliable networks
- Durable outbox: Changes are written to a local SQLite outbox before they are sent. Unacknowledged data survives network outages and restarts.
- Sequence and ACK: Every batch carries a sequence number. Duplicates are recognized and gaps are detected, so no record is applied twice or lost silently.
- Snapshot sync: After a long outage, the current state is synchronized in one snapshot instead of replaying every change.
- Efficient on the wire: MessagePack serialization, LZ4 compression for large payloads and subscription filtering keep traffic small on 4G, radio and metered links.
- Secure by design: Token authentication, TLS 1.3, mutual TLS with X.509 certificates, CRC-16 frame checks and size limits.
- Remote write and health: The master sends write commands to authorized tags. Heartbeats report node status, CPU, memory and backlog.
One protocol, four platforms
The master runs on .NET. Nodes run on ESP32 microcontrollers, Raspberry Pi and Linux edge devices.
- Master: .NET: For the server, SCADA and gateway side.
dotnet add package LunaLinkNuGet package - Node: ESP32: An ESP-IDF component for the device side.
idf.py add-dependency "lunasoft/lunalink"ESP Component Registry - Node: Python: For Raspberry Pi gateways and quick integrations. Early release (0.1).
pip install lunalinkPyPI package - Node: Go: A library and a static gateway binary for Linux edge devices. Early release (0.1).
go get github.com/lunasoft-llc/lunalink-goGo package
Where it fits
- Multi-site manufacturing
- Water and wastewater pumping stations
- Substations and energy monitoring
- Oil, gas and pipelines
- Remote irrigation
- Building and facility monitoring
- Mobile and containerized units
- Edge gateways and IoT platforms