LunaLink.Bridge.Mqtt 2.0.0-preview.1

This is a prerelease version of LunaLink.Bridge.Mqtt.
dotnet add package LunaLink.Bridge.Mqtt --version 2.0.0-preview.1
                    
NuGet\Install-Package LunaLink.Bridge.Mqtt -Version 2.0.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LunaLink.Bridge.Mqtt" Version="2.0.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LunaLink.Bridge.Mqtt" Version="2.0.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="LunaLink.Bridge.Mqtt" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LunaLink.Bridge.Mqtt --version 2.0.0-preview.1
                    
#r "nuget: LunaLink.Bridge.Mqtt, 2.0.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LunaLink.Bridge.Mqtt@2.0.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LunaLink.Bridge.Mqtt&version=2.0.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=LunaLink.Bridge.Mqtt&version=2.0.0-preview.1&prerelease
                    
Install as a Cake Tool

LunaLink.Bridge.Mqtt

An MQTT bridge for LunaLink. It runs next to your LunaLink master and mirrors everything the nodes report to an MQTT broker, either as plain JSON topics or as Sparkplug B edge nodes that an Ignition (MQTT Engine), HiveMQ or similar host application can discover.

Verification status. This package is tested against an in-process MQTT broker (MQTTnet) and a protobuf decoder built from the Eclipse Tahu sparkplug_b.proto, and against Eclipse Mosquitto with pysparkplug, an independent Sparkplug B implementation, acting as the host application. The pysparkplug check covers NBIRTH, NDATA sequence numbers, rebirth, NCMD writes and the NDEATH will (20 of 20 passed, see interop). It has not yet been verified with Ignition MQTT Engine. Treat the Sparkplug B mode as a preview until you have run it against your own host.

How it fits in

The bridge is a decorator of your ILunaLinkServerCallback. LunaLink calls the bridge, the bridge calls your callback first and unchanged, then mirrors the call to the broker. Broker problems (unreachable, slow, rejecting) are logged and never reach the master or your callback; values that cannot be sent while the broker is down are dropped, not queued without limit.

node ──LunaLink──> master ──> LunaLinkMqttBridge ──> your ILunaLinkServerCallback
                                     │
                                     └──MQTT──> broker ──> Ignition / JSON consumers

Installation and setup

dotnet add package LunaLink.Bridge.Mqtt

With dependency injection, register your callback and the LunaLinkNodeTracker first, then add the bridge. AddLunaLinkMqttBridge takes the existing ILunaLinkServerCallback registration, keeps it as the wrapped callback and registers the bridge (and its hosted service) in its place.

builder.Services.AddSingleton<LunaLinkNodeTracker>();
builder.Services.AddSingleton<ILunaLinkServerCallback, MyServerCallback>();

builder.Services.AddLunaLinkMqttBridge(o =>
{
    o.Host = "broker.plant.local";
    o.Port = 8883;
    o.UseTls = true;
    o.Username = "lunalink";
    o.Password = builder.Configuration["Mqtt:Password"];

    o.Mode = LunaLinkMqttMode.SparkplugB;
    o.GroupId = "Plant1";
});

Without dependency injection, create the bridge yourself and hand it to the LunaLinkServer as its callback:

var bridge = new LunaLinkMqttBridge(myCallback, tracker, Options.Create(bridgeOptions), loggerFactory);
var server = new LunaLinkServer(logger, serverOptions, tracker, bridge);
await bridge.StartAsync();   // and bridge.StopAsync() on shutdown

The bridge only needs the LunaLinkNodeTracker that the master uses, because it asks the nodes for their tag list (browse, browse-v1) and sends writes through it.

Options

Option Default Meaning
Host, Port localhost, 1883 Broker address.
UseTls, AllowUntrustedCertificates false, false TLS to the broker. Do not accept untrusted certificates in production.
Username, Password none Broker credentials.
ClientIdPrefix lunalink-bridge Prefix of the MQTT client ids.
KeepAliveSeconds, ReconnectDelaySeconds 30, 5 Connection upkeep.
Mode Json Json or SparkplugB.
TopicPrefix lunalink JSON mode: first topic segment.
QualityOfService 1 JSON mode: QoS of messages.
Retain false JSON mode: retain value messages.
GroupId LunaLink Sparkplug B group id. Must not contain +, / or #.
EdgeNodeIdFactory NodeId with + / # and white space replaced by _ Maps a LunaLink NodeId to the Sparkplug edge node id.
SparkplugQualityOfService 0 QoS of NBIRTH and NDATA (the Sparkplug specification says 0). NDEATH always uses QoS 1.
HostApplicationId none Sparkplug primary host id. When set, the bridge waits for spBv1.0/STATE/{id} to say online before it publishes.
MaxMetricsPerMessage 1000 Larger batches are split into several NDATA messages.
QueueCapacity 10000 Queued value batches per node before new ones are dropped.
BrowseAttempts, BrowseTimeoutMs, BrowseRetryDelayMs 4, 3000, 500 How the bridge reads a node's tag list.

JSON mode

Every value is published to {TopicPrefix}/{nodeId}/{tag}, where {tag} is the tag path (for example Plant/Line1/Temp, giving the topic lunalink/node-a/Plant/Line1/Temp), else the tag name, else the tag id. The path comes from browsing the node, so a node that does not support browse-v1 is published under the tag name or id. A value published before the browse has finished also uses the name or id.

{
  "value": 21.5,
  "quality": "Good",
  "timestamp": "2026-12-03T09:14:07.123+00:00",
  "dataType": "Float32",
  "tagId": "6f1c9a52-3c1e-4f3a-9b21-8a0d5d0b6c11",
  "name": "Temp",
  "unit": "°C"
}

Status topics (always retained): {TopicPrefix}/{nodeId}/$status carries {"online":true} when a node connects and {"online":false,"reason":"Goodbye"} when it goes (the reason is the LunaLinkDisconnectReason). {TopicPrefix}/$bridge/status carries {"online":false} as the bridge's last will and {"online":true} while it is connected.

Sparkplug B mode

Every LunaLink node appears as one Sparkplug edge node (group = GroupId, edge node = the NodeId). There are no devices: the tags of a node are node metrics. Because each edge node needs its own last will, the bridge opens one MQTT connection per LunaLink node (client id {ClientIdPrefix}-{edgeNodeId}).

  • NBIRTH (spBv1.0/{group}/NBIRTH/{edge}, seq 0) is sent when a node connects and after every MQTT reconnect. It holds bdSeq, Node Control/Rebirth, and one metric per tag read by browsing the node. The metric name is the tag path, else the tag name. Metric properties: Quality, engUnit, engLow, engHigh, documentation (the tag description) and writable. The last known value is included.
  • NDATA carries changed values with seq 1, 2, ... 255, 0, 1 (wrapping), the value timestamp and a Quality property (192 good, 64 uncertain, 0 bad or not connected). A tag that was not part of the birth (for example from a node without browse-v1) is introduced by a new NBIRTH, as the specification requires.
  • NDEATH is the MQTT will of every edge node connection (QoS 1, not retained, carrying the same bdSeq as the NBIRTH), so the broker announces the death if the bridge process dies. In addition the bridge publishes NDEATH itself and then disconnects cleanly when a node's session ends, whatever the LunaLinkDisconnectReason (Goodbye, ConnectionLost, HeartbeatTimeout, ProtocolError, ServerStopping) and when the bridge stops. A disconnect notification of a connection that was already replaced by a newer connection of the same node is ignored, so a reconnecting node does not flap.
  • bdSeq counts the MQTT connections of an edge node (0 to 255, wrapping) and increases on each new connection of the same edge node within the life of the bridge process.
  • NCMD (spBv1.0/{group}/NCMD/{edge}): a write to a metric is sent to the node as a LunaLink write command, but only for tags the node reports as writable. Writes to other tags, unknown metrics and values that do not fit the tag's type are refused and logged. Node Control/Rebirth = true makes the bridge send a new NBIRTH (same bdSeq).
  • STATE: with HostApplicationId set, the bridge subscribes to spBv1.0/STATE/{id}, publishes nothing until the host is online, sends a new NBIRTH when the host comes back, and stops publishing when it goes offline. The JSON payload {"online":true} and the plain strings ONLINE and OFFLINE are understood.

Data type mapping: Bool to Boolean, Int16, UInt16, Int32, UInt32, Float32 to Float, Float64 to Double, String, Enum and Json to String, Int64Array to Int64Array, Float64Array to DoubleArray, StringArray to StringArray, Blob to Bytes. Int16 and Int32 values travel in int_value as the two's complement of their width, arrays in bytes_value (little endian, strings null terminated), as in the Sparkplug payload definition.

Not implemented: DBIRTH and device level topics, metric aliases, DataSets and Templates, Sparkplug Node Control/Next Server, events (ProcessEventsAsync is only forwarded to your callback), and history (ProcessHistoryBatchAsync is not mirrored).

Sparkplug B payload definition

The generated protobuf classes come from the Eclipse Tahu sparkplug_b.proto, included as Protos/sparkplug_b.proto with its original header (Eclipse Public License 2.0, copyright Cirrus Link Solutions and others; only an attribution comment was added at the top). Source: https://github.com/eclipse/tahu/blob/master/sparkplug_b/sparkplug_b.proto. Sparkplug is a trademark of the Eclipse Foundation. This package is MIT licensed; the proto file keeps its own licence.

Testing and known limits

The test project runs fully in process: an MQTTnet broker, a real LunaLink master and node, and a protobuf decoder that checks births (metrics with units and ranges), data, seq order and wrap, bdSeq matching between NBIRTH and NDEATH, death on Goodbye and on a cut connection, the broker will when the bridge connection is lost, NCMD writes reaching the node, rebirth, STATE handling and JSON mode.

What that does not cover: interoperability with Ignition's MQTT Engine or other hosts, TLS and authenticated brokers, MQTT 5, long-running soak behaviour, and very large tag counts (tens of thousands of tags per node produce a large NBIRTH).

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-preview.1 49 12/3/2026