LunaLink.OpcUa
2.0.0-preview.1
dotnet add package LunaLink.OpcUa --version 2.0.0-preview.1
NuGet\Install-Package LunaLink.OpcUa -Version 2.0.0-preview.1
<PackageReference Include="LunaLink.OpcUa" Version="2.0.0-preview.1" />
<PackageVersion Include="LunaLink.OpcUa" Version="2.0.0-preview.1" />
<PackageReference Include="LunaLink.OpcUa" />
paket add LunaLink.OpcUa --version 2.0.0-preview.1
#r "nuget: LunaLink.OpcUa, 2.0.0-preview.1"
#:package LunaLink.OpcUa@2.0.0-preview.1
#addin nuget:?package=LunaLink.OpcUa&version=2.0.0-preview.1&prerelease
#tool nuget:?package=LunaLink.OpcUa&version=2.0.0-preview.1&prerelease
LunaLink.OpcUa
An OPC UA server facade for LunaLink. It runs next to a LunaLink master and publishes every tag of every connected node as an OPC UA variable, so SCADA clients, historians and any OPC UA client can read, subscribe to and (where allowed) write LunaLink tags without knowing the LunaLink protocol.
Status: preview (2.0.0-preview.1). Tested with the OPC Foundation .NET client in-process and with asyncua, an independent OPC UA client (see interop). Not yet verified with UaExpert.
Address space
Objects
LunaLink (folder, name configurable)
<NodeId> (object, one per LunaLink node)
Online Boolean, true while the node is connected
LastSeen DateTime (UTC), last time the master heard from the node
<path segment> (folder, from the tag Path "Site/Area/Device/Tag")
<Tag> variable
Each tag variable carries:
| OPC UA | From LunaLink |
|---|---|
DataType, ValueRank |
LunaLinkDataType: Bool = Boolean, Int16, UInt16, Int32, UInt32, Float32 = Float, Float64 = Double, String/Enum/Json = String, Int64Array = Int64[], Float64Array = Double[], StringArray = String[] (arrays have ValueRank 1), Blob = ByteString |
Description |
tag description |
EngineeringUnits property (EUInformation) |
tag unit (numeric tags). The unit text is the display name; no UNECE unit id is assigned (UnitId = -1) |
EURange property |
RangeLow / RangeHigh (numeric tags; the variable then has type definition AnalogItemType) |
AccessLevel / UserAccessLevel |
CurrentReadOrWrite for tags the node declares Writable, otherwise CurrentRead |
StatusCode |
LunaLinkQuality: Good = Good, Uncertain = Uncertain, Bad = Bad, NotConnected = BadNotConnected |
| source timestamp | timestamp of the value as sent by the node |
Until the first value of a tag arrives its status is BadWaitingForInitialData. When a node goes offline, Online becomes false and the last value of each of its tags stays readable with status UncertainLastUsableValue (the OPC UA stack does not deliver the value of a variable whose status is Bad, so an outage is not reported as Bad). After a reconnect the tags are refreshed when the node publishes again.
NodeIds are string NodeIds in the namespace urn:lunasoft:lunalink:opcua, for example ns=2;s=LunaLink/boiler-1/Plant/Line1/Temperature.
Values that arrive for a tag that is not in the node's inventory (or from a node that does not support browse-v1) get a variable named after the tag name, without metadata and read-only.
Setup
using LunaLink;
using LunaLink.OpcUa;
var builder = Host.CreateApplicationBuilder(args);
// Your normal LunaLink master registration, including your callback.
builder.Services.AddSingleton<LunaLinkNodeTracker>();
builder.Services.AddSingleton<ILunaLinkServerCallback, MasterCallback>();
builder.Services.AddHostedService<LunaLinkServer>();
// Add the OPC UA facade AFTER the callback is registered. It wraps your callback.
builder.Services.AddLunaLinkOpcUa(o =>
{
o.Port = 4840; // opc.tcp://0.0.0.0:4840/LunaLink
o.PkiPath = "/var/lib/myapp/opcua-pki"; // certificate stores
// Default security: Basic256Sha256 and Aes256_Sha256_RsaPss, signed and encrypted.
// For a lab network without certificates you can explicitly allow "None":
// o.AllowSecurityNone = true;
});
await builder.Build().RunAsync();
AddLunaLinkOpcUa replaces the registered ILunaLinkServerCallback with a decorator (LunaLinkOpcUaCallback). Every call is forwarded to your callback first, so your application behaves as before. If your callback throws, the OPC UA address space is not updated and the library delivers the batch again. A hosted service starts and stops the OPC UA server with the host. The LunaLinkNodeTracker must be a singleton shared with the LunaLinkServer.
Without dependency injection:
var opcUa = new LunaLinkOpcUaServer(tracker, Options.Create(new LunaLinkOpcUaOptions { Port = 4840 }));
var master = new LunaLinkServer(logger, masterOptions, tracker, opcUa.Decorate(myCallback));
await opcUa.StartAsync();
await master.StartAsync(ct);
Options (LunaLinkOpcUaOptions)
| Option | Default | Meaning |
|---|---|---|
Port / EndpointUrl |
4840 / null | Listen address. EndpointUrl overrides Port (for example opc.tcp://localhost:48400/LunaLink) |
SecurityPolicies |
Basic256Sha256 and Aes256_Sha256_RsaPss, SignAndEncrypt | Offered message security |
AllowSecurityNone |
false | Also offer an unsecured endpoint. Anyone who can reach the port can then read and write: use only on trusted networks |
PkiPath |
%LOCALAPPDATA%/LunaLink/OpcUa/pki |
Folders own, trusted, issuer, rejected |
AutoCreateCertificate |
true | Create a self-signed application certificate when none exists |
AutoAcceptUntrustedClientCertificates |
false | Trust any client certificate. Default: copy the client certificate from rejected to trusted |
AllowAnonymous / Users |
true / empty | Anonymous sessions and optional user name logins |
EnableWrites |
true | When false every variable is read-only |
RootFolderName |
LunaLink |
Folder under Objects |
WriteTimeout |
10 s | Longest wait for the node to confirm a write (the library itself gives up after 5 s) |
Writes
A client write to a writable tag sends a LunaLink TagWriteCmd to the node (through LunaLinkNodeTracker.SendWriteCommandWithResultAsync) and waits for the node's acknowledgement before answering the client. Results:
| Node result | OPC UA status |
|---|---|
| Succeeded | Good |
| tag not writable (also checked by the master) | BadNotWritable |
| Failed (node rejected) | BadInternalError |
| Expired, no answer in time | BadTimeout |
| node not connected | BadNotConnected |
| value cannot be converted to the tag type | BadTypeMismatch |
| write to part of an array (index range) | BadWriteNotSupported |
After a successful write the variable holds the written value until the node publishes its real value. A write to a read-only tag is refused with BadNotWritable and never reaches the node. Writes are applied one tag at a time; a node that does not answer holds the client request for up to WriteTimeout.
Not implemented
- HistoryRead. LunaLink 2.0 does not expose stored history to the master application:
ProcessHistoryBatchAsynconly hands samples to your callback, there is no read API. The variables are therefore not marked as historizing and HistoryRead is not served. It is not faked. - Events and alarms (LunaLink events are not mapped to OPC UA events).
- Methods, and writes to a part of an array.
- Tags removed from a node's inventory stay in the address space until the server restarts.
Licence of the OPC UA stack
This package (LunaLink.OpcUa) is MIT licensed like LunaLink. It depends on the NuGet package OPCFoundation.NetStandard.Opc.Ua.Server (and its dependencies Opc.Ua.Core, Opc.Ua.Types, Opc.Ua.Security.Certificates, Opc.Ua.Configuration) from the OPC Foundation, version 1.5.378.196 at the time of writing.
The OPC Foundation stack is dual licensed: the source on GitHub is available under the OPC Foundation MIT licence (the OPC Foundation MIT License 1.00, which is the text shipped in the LICENSE.txt inside the NuGet packages: permissive, free use, modification and redistribution provided the copyright and licence notice are kept) and, for OPC Foundation members, under the RCL. The NuGet packages are published under the MIT licence. Redistribution therefore needs only the copyright and licence notice of the OPC Foundation to be kept with your product (NuGet does this when the packages are restored; include the third party notice if you ship the binaries yourself). Check the LICENSE.txt of the exact package version you ship. This is not legal advice.
The newest major version of the stack at the time of writing is 2.0.x, with breaking API changes. This package currently targets 1.5.378.x.
Verification status
- Tested in-process with the OPC Foundation .NET client (
OPCFoundation.NetStandard.Opc.Ua.Client): browse (units, ranges, descriptions, data types, access levels), read with quality and source timestamp, subscription with change notification, write to a writable tag (reaches the node callback), write refused for read-only tags, node offline and reconnect, SignAndEncrypt session with an auto-created certificate, user name login, dependency injection wiring. - Tested with asyncua 2.1.0, a client independent of the OPC Foundation stack, over the network: endpoints, browse, data types, description,
EngineeringUnits,EURange,AnalogItemType, read with quality and source timestamp, subscription, writes (accepted, rejected by the node, refused as read-only), Security None and Basic256Sha256 SignAndEncrypt with a client certificate, user name login and a wrong password. 36 of 36 checks passed (extensions/interop/opcua_check.py). - Not yet verified with UaExpert or against the OPC UA conformance test tool. Expect small interoperability issues (for example units shown without a UNECE unit id).
- Performance under thousands of tags and many subscriptions has not been measured.
| Product | Versions 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. |
-
net10.0
- LunaLink (>= 2.0.1)
- OPCFoundation.NetStandard.Opc.Ua.Server (>= 1.5.378.196)
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 | 47 | 12/3/2026 |