

'Declaration<ExceptionContractAnnotationAttribute(True)> <CLSCompliantAttribute(True)> <TypeConverterAttribute(OpcLabs.BaseLib.Implementation.ResourceDescriptorConverter)> <ValueControlAttribute("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.83.473.1, Culture=neutral, PublicKeyToken=6faddca41dacb409", DefaultReadWrite=False, Export=True, PageId=10001)> <SerializableAttribute()> Public Class SparkplugBrokerDescriptor Inherits OpcLabs.BaseLib.ResourceDescriptor Implements LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.Aliasing.ComTypes._Aliasable, OpcLabs.BaseLib.Aliasing.IAliasable, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, OpcLabs.BaseLib.ComTypes._ResourceDescriptor, OpcLabs.BaseLib.Text.IStringListSerializable, System.ComponentModel.INotifyPropertyChanged, System.ICloneable, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
'UsageDim instance As SparkplugBrokerDescriptor
[ExceptionContractAnnotation(true)] [CLSCompliant(true)] [TypeConverter(OpcLabs.BaseLib.Implementation.ResourceDescriptorConverter)] [ValueControl("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.83.473.1, Culture=neutral, PublicKeyToken=6faddca41dacb409", DefaultReadWrite=false, Export=true, PageId=10001)] [Serializable()] public class SparkplugBrokerDescriptor : OpcLabs.BaseLib.ResourceDescriptor, LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.Aliasing.ComTypes._Aliasable, OpcLabs.BaseLib.Aliasing.IAliasable, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, OpcLabs.BaseLib.ComTypes._ResourceDescriptor, OpcLabs.BaseLib.Text.IStringListSerializable, System.ComponentModel.INotifyPropertyChanged, System.ICloneable, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
[ExceptionContractAnnotation(true)] [CLSCompliant(true)] [TypeConverter(OpcLabs.BaseLib.Implementation.ResourceDescriptorConverter)] [ValueControl("OpcLabs.BaseLib.Forms.Common.ObjectSerializationControl, OpcLabs.BaseLibForms, Version=5.83.473.1, Culture=neutral, PublicKeyToken=6faddca41dacb409", DefaultReadWrite=false, Export=true, PageId=10001)] [Serializable()] public ref class SparkplugBrokerDescriptor : public OpcLabs.BaseLib.ResourceDescriptor, LINQPad.ICustomMemberProvider, OpcLabs.BaseLib.Aliasing.ComTypes._Aliasable, OpcLabs.BaseLib.Aliasing.IAliasable, OpcLabs.BaseLib.ComTypes._Info, OpcLabs.BaseLib.ComTypes._Object2, OpcLabs.BaseLib.ComTypes._ResourceDescriptor, OpcLabs.BaseLib.Text.IStringListSerializable, System.ComponentModel.INotifyPropertyChanged, System.ICloneable, System.Runtime.Serialization.ISerializable, System.Xml.Serialization.IXmlSerializable
Sparkplug broker descriptor is used both with the Sparkplug consumer model (EasySparkplugConsumerCore) and with the Sparkplug provider model ().
The SparkplugBrokerDescriptor class provides a way to describe and configure a connection to the broker used in the Sparkplug system (MQTT broker). It extends OpcLabs.BaseLib.ResourceDescriptor to include additional properties for Sparkplug-specific configuration, such as custom property values for the broker connection.
Instances of this class can be created from a descriptor string, a System.Uri, or by copying another SparkplugBrokerDescriptor. The class also provides static methods and implicit operators for convenient conversion from strings and URIs. This means that (in languages that support implicit conversions, such as C# or VB.NET), you can conveniently use a URL string, such as "mqtt://myhost.mydomain.com", in place of the Sparkplug broker descriptor.
The CustomPropertyValueDictionary property allows specifying additional key-value pairs for broker configuration, which can be used for advanced scenarios such as MQTT 5 user properties.
Sparkplug is a trademark of Eclipse Foundation, Inc. "MQTT" is a trademark of the OASIS Open standards consortium. Other related terms are trademarks of their respective owners. Any use of these terms on this site is for descriptive purposes only and does not imply any sponsorship, endorsement or affiliation.
// This example shows how to subscribe to all metrics of a given edge node, with authentication. // // In order to publish or observe messages for this example, start the SparkplugEdgeNodeConsoleDemo program first. // The username and password must match the ones used by the MQTT broker. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html . // Sparkplug examples in C# on GitHub: https://github.com/OPCLabs/Examples-ConnectivityStudio-CSharp . // Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own // a commercial license in order to use Online Forums, and we reply to every post. using System; using OpcLabs.EasySparkplug; using OpcLabs.EasySparkplug.OperationModel; namespace SparkplugDocExamples.Consumer._EasySparkplugConsumer { partial class SubscribeEdgeNodeMetric { public static void Authentication() { // The username and password can be specified in the broker descriptor, as below. // Note that the default port for the "mqtt" scheme is 1883. var brokerDescriptor = new SparkplugBrokerDescriptor("mqtt://localhost") { UserName = "admin", Password = "password" }; var hostDescriptor = new SparkplugHostDescriptor(brokerDescriptor); // Alternatively, if you do not mind, the MQTT broker URL can directly include the username and password, // as below. // Note that regardless of how the broker descriptor is constructed, the username and password are transferred // in plain text on the wire, unless encryption is used (e.g., using TLS or WSS - see other examples). var hostDescriptor2 = new SparkplugHostDescriptor("mqtt://admin:password@localhost"); // Instantiate the consumer object and hook events. var consumer = new EasySparkplugConsumer(); consumer.MetricNotification += consumer_Authentication_MetricNotification; Console.WriteLine("Subscribing..."); // In this example, we specify the precise Sparkplug group ID and edge node ID, but allow any metric name. consumer.SubscribeEdgeNodeMetric(hostDescriptor, // or hostDescriptor2, if you prefer the alternative method "easyGroup", "easySparkplugDemo", "#"); Console.WriteLine("Processing notifications for 20 seconds..."); System.Threading.Thread.Sleep(20 * 1000); Console.WriteLine("Unsubscribing..."); consumer.UnsubscribeAllMetrics(); Console.WriteLine("Waiting for 5 seconds..."); System.Threading.Thread.Sleep(5 * 1000); Console.WriteLine("Finished."); } static void consumer_Authentication_MetricNotification(object sender, EasySparkplugMetricNotificationEventArgs eventArgs) { // Handle different types of notifications. Console.WriteLine(); switch (eventArgs.NotificationType) { case SparkplugNotificationType.Connect: Console.WriteLine($"Connected to Sparkplug host, client ID: {eventArgs.ClientId}."); break; case SparkplugNotificationType.Disconnect: Console.WriteLine("Disconnected from Sparkplug host."); break; case SparkplugNotificationType.Data: Console.WriteLine("Received data from Sparkplug host."); Console.WriteLine($"Metric name: {eventArgs.MetricName}"); Console.WriteLine($"Value: {eventArgs.MetricData?.Value}"); break; case SparkplugNotificationType.Birth: Console.WriteLine("Received birth message from Sparkplug host."); Console.WriteLine($"Metric name: {eventArgs.MetricName}"); Console.WriteLine($"Value: {eventArgs.MetricData?.Value}"); break; case SparkplugNotificationType.Death: Console.WriteLine("Received death message from Sparkplug host."); Console.WriteLine($"Metric name: {eventArgs.MetricName}"); break; } if (!eventArgs.Succeeded) Console.WriteLine($"*** Failure: {eventArgs.ErrorMessageBrief}"); } } }
' This example shows how to subscribe to all metrics of a given edge node, with authentication. ' ' In order to publish or observe messages for this example, start the SparkplugEdgeNodeConsoleDemo program first. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html . ' Sparkplug examples in C# on GitHub: https://github.com/OPCLabs/Examples-ConnectivityStudio-CSharp . ' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own ' a commercial license in order to use Online Forums, and we reply to every post. Imports OpcLabs.EasySparkplug Imports OpcLabs.EasySparkplug.OperationModel Namespace Global.SparkplugDocExamples.Consumer._EasySparkplugConsumer Partial Class SubscribeEdgeNodeMetric Public Shared Sub Authentication() ' The username and password can be specified in the broker descriptor, as below. ' Note that the default port for the "mqtt" scheme is 1883. Dim brokerDescriptor = New SparkplugBrokerDescriptor("mqtt://localhost") With { .UserName = "admin", .Password = "password" } Dim hostDescriptor = New SparkplugHostDescriptor(brokerDescriptor) ' Alternatively, if you do not mind, the MQTT broker URL can directly include the username and password, ' as below. ' Note that regardless of how the broker descriptor is constructed, the username and password are transferred ' in plain text on the wire, unless encryption is used (e.g., using TLS or WSS - see other examples). Dim hostDescriptor2 = New SparkplugHostDescriptor("mqtt://admin:password@localhost") ' Instantiate the consumer object and hook events. Dim consumer = New EasySparkplugConsumer() AddHandler consumer.MetricNotification, AddressOf consumer_Authentication_MetricNotification Console.WriteLine("Subscribing...") ' In this example, we specify the precise Sparkplug group ID and edge node ID, but allow any metric name. consumer.SubscribeEdgeNodeMetric(hostDescriptor, ' or hostDescriptor2, if you prefer the alternative method "easyGroup", "easySparkplugDemo", "#") Console.WriteLine("Processing notifications for 20 seconds...") Threading.Thread.Sleep(20 * 1000) Console.WriteLine("Unsubscribing...") consumer.UnsubscribeAllMetrics() Console.WriteLine("Waiting for 5 seconds...") Threading.Thread.Sleep(5 * 1000) Console.WriteLine("Finished.") End Sub Private Shared Sub consumer_Authentication_MetricNotification(ByVal sender As Object, ByVal eventArgs As EasySparkplugMetricNotificationEventArgs) ' Handle different types of notifications. Console.WriteLine() Select Case eventArgs.NotificationType Case SparkplugNotificationType.Connect Console.WriteLine($"Connected to Sparkplug host, client ID: {eventArgs.ClientId}.") Case SparkplugNotificationType.Disconnect Console.WriteLine("Disconnected from Sparkplug host.") Case SparkplugNotificationType.Data Console.WriteLine("Received data from Sparkplug host.") Console.WriteLine($"Metric name: {eventArgs.MetricName}") Console.WriteLine($"Value: {eventArgs.MetricData?.Value}") Case SparkplugNotificationType.Birth Console.WriteLine("Received birth message from Sparkplug host.") Console.WriteLine($"Metric name: {eventArgs.MetricName}") Console.WriteLine($"Value: {eventArgs.MetricData?.Value}") Case SparkplugNotificationType.Death Console.WriteLine("Received death message from Sparkplug host.") Console.WriteLine($"Metric name: {eventArgs.MetricName}") End Select If Not eventArgs.Succeeded Then Console.WriteLine($"*** Failure: {eventArgs.ErrorMessageBrief}") End If End Sub End Class End Namespace
// This example shows different ways of constructing the EasySparkplugEdgeNode object. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html . // Sparkplug examples in C# on GitHub: https://github.com/OPCLabs/Examples-ConnectivityStudio-CSharp . // Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own // a commercial license in order to use Online Forums, and we reply to every post. using System; using OpcLabs.EasySparkplug; namespace SparkplugDocExamples.EdgeNode._EasySparkplugEdgeNode { class Construction { static public void Main1() { // The toolkit provides a ready-made shared instance of the edge node object which you can use without even // having to construct it. Not recommended for use in library code, because it is a shared instance, and its // usage may therefore conflict with other code using the same instance. var edgeNode0 = EasySparkplugEdgeNode.SharedInstance; // The simplest way to construct the edge node object is to use the default constructor. The edge node will // connect to the default broker URL "mqtt://localhost". Group ID is "easyGroup", edge node ID and primary host // ID will be auto-generated. var edgeNode1 = new EasySparkplugEdgeNode(); // The edge node object can be constructed with a specific broker URL string passed as an argument to the // constructor. This relies on the implicit conversion from string to SparkplugBrokerDescriptor. var edgeNode2 = new EasySparkplugEdgeNode("mqtt://localhost:1883"); // The broker URL can also be specified using the Uri object. var edgeNode3 = new EasySparkplugEdgeNode(new Uri("mqtt://localhost:1883")); // You can construct the edge node object with a specific broker descriptor, which allows you to set all its // parameters; var edgeNode4 = new EasySparkplugEdgeNode( new SparkplugBrokerDescriptor { Host = "localhost", Password = "password", Port = 1883, UserName = "admin", }); // The sparkplug group ID and edge node ID can be specified as additional arguments to the constructor. var edgeNode5 = new EasySparkplugEdgeNode("mqtt://localhost:1883", "myGroup", "myEdgeNode"); // The primary host ID of the application can also be specified, using a different constructor overload (when // not specified, i.e. left empty, the component will not use the primary host application logic). var edgeNode6 = new EasySparkplugEdgeNode("mqtt://localhost:1883", "myPrimaryHost", "myGroup", "myEdgeNode"); // You do not have to specify everything in the constructor. The basic properties can be set later - but before // the edge node is started. var edgeNode7 = new EasySparkplugEdgeNode(); edgeNode7.SystemDescriptor = new SparkplugSystemDescriptor("mqtt://localhost:1883"); edgeNode7.GroupId = "myGroup"; edgeNode7.EdgeNodeId = "myEdgeNode"; // If the language supports property initializers (such as C# or VB.NET), the above code can be written more // concisely. var edgeNode8 = new EasySparkplugEdgeNode { GroupId = "myGroup", EdgeNodeId = "myEdgeNode", SystemDescriptor = new SparkplugSystemDescriptor("mqtt://localhost:1883"), }; // For more advanced scenarios, a SparkplugSystemDescriptor can be passed to the constructor instead of the // SparkplugBrokerDescriptor. In the example below, this allows you to specify the Sparkplug version. var edgeNode9 = new EasySparkplugEdgeNode( new SparkplugSystemDescriptor("mqtt://localhost:1883", SparkplugVersions.PayloadA), "myPrimaryHost", "myGroup", "myEdgeNode"); // If the language supports collection initializers (such as C# or VB.NET), the edge node object can be // constructed with its metrics (the contents of the Metrics collection), in a single statement. var edgeNode10 = new EasySparkplugEdgeNode("myPrimaryHost", "myGroup", "myEdgeNode") { new SparkplugMetric("Constant1").ConstantValue(42), new SparkplugMetric("Constant2").ConstantValue("abc") }; } } }
' This example shows different ways of constructing the EasySparkplugEdgeNode object. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-ConnectivityStudio/Latest/examples.html . ' Sparkplug examples in C# on GitHub: https://github.com/OPCLabs/Examples-ConnectivityStudio-CSharp . ' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own ' a commercial license in order to use Online Forums, and we reply to every post. Imports OpcLabs.EasySparkplug Namespace Global.SparkplugDocExamples.EdgeNode._EasySparkplugEdgeNode Class Construction Public Shared Sub Main1() ' The toolkit provides a ready-made shared instance of the edge node object which you can use without even ' having to construct it. Not recommended for use in library code, because it is a shared instance, and its ' usage may therefore conflict with other code using the same instance. Dim edgeNode0 = EasySparkplugEdgeNode.SharedInstance ' The simplest way to construct the edge node object is to use the default constructor. The edge node will ' connect to the default broker URL "mqtt://localhost". Group ID is "easyGroup", edge node ID and primary host ' ID will be auto-generated. Dim edgeNode1 = New EasySparkplugEdgeNode() ' The edge node object can be constructed with a specific broker URL string passed as an argument to the ' constructor. This relies on the implicit conversion from string to SparkplugBrokerDescriptor. Dim edgeNode2 = New EasySparkplugEdgeNode("mqtt://localhost:1883") ' The broker URL can also be specified using the Uri object. Dim edgeNode3 = New EasySparkplugEdgeNode(New Uri("mqtt://localhost:1883")) ' You can construct the edge node object with a specific broker descriptor, which allows you to set all its ' parameters; Dim edgeNode4 = New EasySparkplugEdgeNode( New SparkplugBrokerDescriptor With { .Host = "localhost", .Password = "password", .Port = 1883, .UserName = "admin" }) ' The sparkplug group ID and edge node ID can be specified as additional arguments to the constructor. Dim edgeNode5 = New EasySparkplugEdgeNode("mqtt://localhost:1883", "myGroup", "myEdgeNode") ' The primary host ID of the application can also be specified, using a different constructor overload (when ' not specified, i.e. left empty, the component will not use the primary host application logic). Dim edgeNode6 = New EasySparkplugEdgeNode("mqtt://localhost:1883", "myPrimaryHost", "myGroup", "myEdgeNode") ' You do not have to specify everything in the constructor. The basic properties can be set later - but before ' the edge node is started. Dim edgeNode7 = New EasySparkplugEdgeNode() edgeNode7.SystemDescriptor = New SparkplugSystemDescriptor("mqtt://localhost:1883") edgeNode7.GroupId = "myGroup" edgeNode7.EdgeNodeId = "myEdgeNode" ' If the language supports property initializers (such as C# or VB.NET), the above code can be written more ' concisely. Dim edgeNode8 = New EasySparkplugEdgeNode With { .GroupId = "myGroup", .EdgeNodeId = "myEdgeNode", .SystemDescriptor = New SparkplugSystemDescriptor("mqtt://localhost:1883") } ' For more advanced scenarios, a SparkplugSystemDescriptor can be passed to the constructor instead of the ' SparkplugBrokerDescriptor. In the example below, this allows you to specify the Sparkplug version. Dim edgeNode9 = New EasySparkplugEdgeNode( New SparkplugSystemDescriptor("mqtt://localhost:1883", SparkplugVersions.PayloadA), "myPrimaryHost", "myGroup", "myEdgeNode") ' If the language supports collection initializers (such as C# or VB.NET), the edge node object can be ' constructed with its metrics (the contents of the Metrics collection), in a single statement. Dim edgeNode10 = New EasySparkplugEdgeNode("myPrimaryHost", "myGroup", "myEdgeNode") From { New SparkplugMetric("Constant1").ConstantValue(42), New SparkplugMetric("Constant2").ConstantValue("abc") } End Sub End Class End Namespace
System.Object
OpcLabs.BaseLib.Object2
OpcLabs.BaseLib.Info
OpcLabs.BaseLib.ResourceDescriptor
OpcLabs.EasySparkplug.SparkplugBrokerDescriptor