When implementing a Sparkplug edge node with Rapid Toolkit for Sparkplug, your code needs to perform the following basic steps:
Steps 1 to 3 prepare the edge node instance for subsequent operations. The properties and the contents of the edge node object must be defined before the edge node is started in Step 4.
The example shows a very simple Sparkplug edge node implementation with a single metric, and all the steps described above.
Before the edge node can be started, it has to be created and configured. You need at least:
For more information and code examples to this part, see Rapid Toolkit for Sparkplug Producer Data Model.
Simply creating the edge node object, setting its properties and defining contents does not make the edge node "live". The edge node must be started first, using the Start Method. After the node is started, it connects to the Sparkplug system (MQTT broker), publishes data and receives commands. It also automatically reconnects in case the connection to the broker is lost. Your code will eventually also stop the edge node, e.g. when the program is instructed to terminate.
For more information about starting and stopping the edge node, see Sparkplug Edge Node Object Operations And Notifications.
Sparkplug has a concept of Primary Host Application that can (optionally) be configured for an edge node, and it controls when the edge node (and its devices) can publish data.
The choice between these two approaches is up to you or the users of your application, and depends on the project requirements.
In Rapid Toolkit for Sparkplug, the primary host application ID is set using the PrimaryHostId Property on the EasySparkplugEdgeNode Class. When this property contains an empty string (the default), no primary host application is configured for this edge node. When this property contains a non-empty string, the string is the host ID of the application that will be the primary host for this edge node.
The PrimaryHostId Property can be set using an assignment statement in the code after the edge node object has been created. For shorter code, there are also constructors overloads on the EasySparkplugEdgeNode Class that take the primary host ID as their argument.
In the following example, the edge node is configured to use "easyApplication" as its primary host.
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.