Connectivity Software User's Guide and Reference
EdgeNodeId Property (IEasySparkplugEdgeNode)
Example 



OpcLabs.EasySparkplug Assembly > OpcLabs.EasySparkplug Namespace > IEasySparkplugEdgeNode Interface : EdgeNodeId Property
The Sparkplug edge node ID of this edge node.
Syntax
'Declaration
 
<JetBrains.Annotations.NotNullAttribute()>
Property EdgeNodeId As String
'Usage
 
Dim instance As IEasySparkplugEdgeNode
Dim value As String
 
instance.EdgeNodeId = value
 
value = instance.EdgeNodeId
[JetBrains.Annotations.NotNull()]
string EdgeNodeId {get; set;}
[JetBrains.Annotations.NotNull()]
property String^ EdgeNodeId {
   String^ get();
   void set (    String^ value);
}

Property Value

The value represents a Sparkplug edge node ID. It must be a string with valid UTF-8 characters except for the reserved characters of '+' (plus), '/' (forward slash), and '#' (number sign).

The value of this property cannot be null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

 

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.

Example
// This example shows how to implement reading from edge node metrics using a single overriden method.
//
// You can use any Sparkplug application, including our SparkplugCmd utility and the SparkplugApplicationConsoleDemo
// program, to subscribe to the edge node data. 
//
// 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.EdgeNode._EasySparkplugEdgeNode
{
    class OnRead
    {
        /// <summary>
        /// A sparkplug edge node, with specialized read behavior for its metrics.
        /// </summary>
        class EdgeNodeWithOnRead : EasySparkplugEdgeNode
        {
            /// <summary>
            /// Obtains the data for Sparkplug read.
            /// </summary>
            /// <param name="eventArgs">The event arguments.</param>
            protected override void OnRead(SparkplugMetricReadEventArgs eventArgs)
            {
                // Obtain the state associated with the metric that is being read.
                object state = eventArgs.Metric.State;

                // The state is null in metrics that we have not created, such as the "node rebirth" metric.
                if (state is null)
                    return;

                // Use the state as the offset for the random value, so that each metric generates values in a unique range.
                int offset = (int)state * 100;

                // Generate a random value, indicate that the read has been handled, and return the generated value.
                eventArgs.HandleAndReturn(Random.Next(offset, offset + 100));
            }

            static private readonly Random Random = new Random();
        }
        
        static public void Main1()
        {
            // Note that the default port for the "mqtt" scheme is 1883.
            var hostDescriptor = new SparkplugHostDescriptor("mqtt://localhost");

            // Instantiate our derived edge node object and hook events.
            var edgeNode = new EdgeNodeWithOnRead
            {
                EdgeNodeId = "easySparkplugDemo",
                GroupId = "easyGroup",
                SystemDescriptor = hostDescriptor
            };
            edgeNode.SystemConnectionStateChanged += (sender, eventArgs) =>
            {
                // Display the new connection state (such as when the connection to the broker succeeds or fails).
                Console.WriteLine($"{nameof(EasySparkplugEdgeNode.SystemConnectionStateChanged)}: {eventArgs}");
            };

            // Create metrics in the folder. Distinguish them by their state.
            edgeNode.Add(new SparkplugMetric("MyMetric1").ValueType<int>().SetState(1));
            edgeNode.Add(new SparkplugMetric("MyMetric2").ValueType<int>().SetState(2));
            edgeNode.Add(new SparkplugMetric("MyMetric3").ValueType<int>().SetState(3));
            edgeNode.Add(new SparkplugMetric("MyMetric4").ValueType<int>().SetState(4));
            edgeNode.Add(new SparkplugMetric("MyMetric5").ValueType<int>().SetState(5));

            // Start the edge node.
            Console.WriteLine("The edge node is starting...");
            edgeNode.Start();

            Console.WriteLine("The edge node is started.");
            Console.WriteLine();

            // Let the user decide when to stop.
            Console.WriteLine("Press Enter to stop the edge node...");
            Console.ReadLine();

            // Stop the edge node.
            Console.WriteLine("The edge node is stopping...");
            edgeNode.Stop();

            Console.WriteLine("The edge node is stopped.");
        }
    }
}
' This example shows how to implement reading from edge node metrics using a single overriden method.
'
' You can use any Sparkplug application, including our SparkplugCmd utility and the SparkplugApplicationConsoleDemo
' program, to subscribe to the edge node data.
'
' 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.EdgeNode._EasySparkplugEdgeNode
    Class OnRead
        ''' <summary>
        ''' A sparkplug edge node, with specialized read behavior for its metrics.
        ''' </summary>
        Class EdgeNodeWithOnRead
            Inherits EasySparkplugEdgeNode

            ''' <summary>
            ''' Obtains the data for Sparkplug read.
            ''' </summary>
            ''' <param name="eventArgs">The event arguments.</param>
            Protected Overrides Sub OnRead(eventArgs As SparkplugMetricReadEventArgs)
                ' Obtain the state associated with the metric that is being read.
                Dim state As Object = eventArgs.Metric.State

                ' Use the state as the offset for the random value, so that each metric generates values in a unique range.
                Dim offset As Integer = CInt(state * 100)

                ' Generate a random value, indicate that the read has been handled, and return the generated value.
                eventArgs.HandleAndReturn(Random.Next(offset, offset + 100))
            End Sub

            Private Shared ReadOnly Random As Random = New Random()
        End Class

        Public Shared Sub Main1()
            ' Note that the default port for the "mqtt" scheme is 1883.
            Dim hostDescriptor = New SparkplugHostDescriptor("mqtt://localhost")

            ' Instantiate our derived edge node object and hook events.
            Dim edgeNode = New EdgeNodeWithOnRead With
            {
                .EdgeNodeId = "easySparkplugDemo",
                .GroupId = "easyGroup",
                .SystemDescriptor = hostDescriptor
            }
            AddHandler edgeNode.SystemConnectionStateChanged,
                Sub(sender, eventArgs)
                    ' Display the new connection state (such as when the connection to the broker succeeds or fails).
                    Console.WriteLine($"{NameOf(EasySparkplugEdgeNode.SystemConnectionStateChanged)}: {eventArgs}")
                End Sub

            ' Create metrics in the folder. Distinguish them by their state.
            edgeNode.Add(New SparkplugMetric("MyMetric1").ValueType(Of Integer)().SetState(1))
            edgeNode.Add(New SparkplugMetric("MyMetric2").ValueType(Of Integer)().SetState(2))
            edgeNode.Add(New SparkplugMetric("MyMetric3").ValueType(Of Integer)().SetState(3))
            edgeNode.Add(New SparkplugMetric("MyMetric4").ValueType(Of Integer)().SetState(4))
            edgeNode.Add(New SparkplugMetric("MyMetric5").ValueType(Of Integer)().SetState(5))

            ' Start the edge node.
            Console.WriteLine("The edge node is starting...")
            edgeNode.Start()

            Console.WriteLine("The edge node is started.")
            Console.WriteLine()

            ' Let the user decide when to stop.
            Console.WriteLine("Press Enter to stop the edge node...")
            Console.ReadLine()

            ' Stop the edge node.
            Console.WriteLine("The edge node is stopping...")
            edgeNode.Stop()

            Console.WriteLine("The edge node is stopped.")
        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
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also