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.

View on GitHub

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.

  1. PLCs and sensors: Local equipment on site
  2. Node: Edge device: collects, buffers, sends
  3. Master: Server: accepts, acknowledges, routes
  4. 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 d2

27 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.

  1. TCP + TLS 1.3 (Node → Master): the node opens the connection
  2. Hello (Node → Master): NodeId, token and capabilities
  3. HelloAck (Master → Node): accepted, agreed capabilities
  4. TagDelta (Node → Master): values, NodeSequence = 42
  5. TagDeltaAck (Master → Node): processed, next expected 43
  6. Heartbeat (Node → Master): every 5 seconds
  7. HeartbeatAck (Master → Node): master clock
  8. TagWriteCmd (Master → Node): with CommandId and expiry
  9. TagWriteAck (Node → Master): result: Succeeded
  10. Goodbye (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 = 42 Next batch: Processed, answer: next expected 43.
  • s ≤ 41 Duplicate: Not applied again, but confirmed so the node removes it from its outbox.
  • s ≥ 43 Gap: 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.

  • 0x01 Hello: Node → Master
  • 0x02 HelloAck: Master → Node
  • 0x03 TagDelta: Both directions
  • 0x04 TagWriteCmd: Master → Node
  • 0x05 TagWriteAck: Node → Master
  • 0x06 Heartbeat: Node → Master
  • 0x07 HeartbeatAck: Master → Node
  • 0x08 SnapshotReq: Node → Master
  • 0x09 SnapshotResp: Master → Node
  • 0x0A Subscribe: Node → Master
  • 0x0B Error: Both directions
  • 0x0C Ping: Node → Master
  • 0x0D Pong: Master → Node
  • 0x0E Ack: Both directions
  • 0x0F TagDeltaAck: Master → Node
  • 0x10 HistoryBatch: Node → Master
  • 0x11 HistoryBatchAck: Master → Node
  • 0x12 Goodbye: Node → Master
  • 0x13 BrowseReq: Master → Node
  • 0x14 BrowseResp: Node → Master
  • 0x15 EventAck: 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 LunaLink NuGet 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 lunalink PyPI 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-go Go 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

Contact us