In this Getting Started, you can create
In this Getting Started procedure, we will create a Sparkplug edge node in C#. The edge node will be hosted in a console application running in .NET Framework or .NET 8, 9, and will publish a metric with dynamic random value
Start Visual Code.
In the command palette box ( -> ), select the .NET: New Project... command.
In the "Search for templates" edit box under "Create a new .NET project", select the "Console App" project type.
In the Project Location dialog box, navigate to the location for your projects and then press the button.
In the edit box under "Name the new project", type HelloEdgeNode, and press Enter.
Finalize the project creation sequence. You can keep all defaults.
In the Terminal window, type the following:
cd HelloEdgeNode
dotnet add package OpcLabs.EasySparkplug .
This command adds Rapid Toolkit for Sparkplug package reference to the project file.
In the Explorer window, select the Program.cs file.
In the text editor window, add following code to the beginning of the Program.cs file:
In Program.cs, if there is a Main method, replace its body by the following code. If there is no Main method, just top-level statements, simply replace them all.
Select -> (F5) from the menu, or press the corresponding button on the toolbar.
This will build and launch the program. The server is now running. The edge node is now running, and publishing the Sparkplug data to the MQTT broker running on "mqtt://localhost", port 1883. Sparkplug host applications (consumers) can connect to the MQTT broker and subscribe to the Sparkplug data produced by the edge node. You can verify it using any configurable Sparkplug host application, or use the Getting Started procedure to create a simple Sparkplug host application of your own; see further below for instructions.
After you are done, press Enter to exit the program.
When the Sparkplug edge node is running and connected to an MQTT broker, any Sparkplug host application (consumer) can connect to the MQTT broker and subscribe to the value of the metric we have defined in the edge node. The Sparkplug host application can connect to the MQTT broker on "mqtt://localhost" to get the data, unless you have changed the source code to use a different URL.
If you have the SparkplugCmd utility (e.g. if you have installed Rapid Toolkit for Sparkplug using the Connectivity Software Setup program, or obtained the SparkplugCmd separately e.g. through ClickOnce deployment), you can use it for verification of the created Sparkplug edge node as follows:
consumer mqtt://localhost subscribePayload easyGroup easySparkplugDemo
The Rapid Toolkit for Sparkplug Application Console Demo is a simple Sparkplug host application which subscribes to edge node and device metrics on the given Sparkplug edge node, and displays the incoming data on the console. Its source code is included with the product in the Examples solution, and you can build it yourself and run. If you are on Windows, the pre-built application is also installed using the Setup program, and can be started from the Launcher program; you will find it under -> -> .
The Sparkplug Application Console Demo is pre-configured to connect to the MQTT broker on "mqtt://localhost", and use Sparkplug group easyGroup and edge node easySparkplugDemo. If you need to change any of this, these parameters can be given on the command line; the MQTT broker address is the first parameter.
The Getting Started procedure for creating a Sparkplug consumer (host application) is designed in such a way that it can be used to observe the data produced by the Sparkplug edge node Getting Started program, without any modification. Just remember to run the two programs in parallel.
If you have other Sparkplug host application that you want to use for verification, it should allow you to browse for the available Sparkplug data, or enter the configuration manually. The default MQTT broker address is "mqtt://localhost", the edge node that we have defined is located in the Sparkplug group with ID easyGroup, and the edge node ID is easySparkplugDemo. The metric name is Metric1.
For simplicity in configuration, the Sparkplug component created in this Getting Started uses an insecure connection, and does not use any authentication. A production Sparkplug component and/or its configuration should be secured appropriately. For more information, see Security in Sparkplug.
In this Getting Started procedure, we will create a Sparkplug host application (consumer) in C#. The consumer will be hosted in a console application running in .NET Framework or .NET 8, 9, and will display the data published by the edge node
Start Visual Code.
In the command palette box ( -> ), select the .NET: New Project... command.
In the "Search for templates" edit box under "Create a new .NET project", select the "Console App" project type.
In the Project Location dialog box, navigate to the location for your projects and then press the button.
In the edit box under "Name the new project", type HelloApplication, and press Enter.
Finalize the project creation sequence. You can keep all defaults.
In the Terminal window, type the following:
cd HelloApplication
dotnet add package OpcLabs.EasySparkplug .
This command adds Rapid Toolkit for Sparkplug package reference to the project file.
In the Explorer window, select the Program.cs file.
In the text editor window, add following code to the beginning of the Program.cs file:
In Program.cs, if there is a Main method, replace its body by the following code. If there is no Main method, just top-level statements, simply replace them all.
Select -> (F5) from the menu, or press the corresponding button on the toolbar.
This will build and launch the program. The host application is now running, and subscribing to Sparkplug data from the MQTT broker on "mqtt://localhost", port 1883. It will display any metrics published by edge node ID "easySparkplugDemo" in the group "easyGroup". You can verify it by starting a Sparkplug edge node (hardware or software) that will publish the Sparkplug data using these parameters, or use the Getting Started procedure to create a simple Sparkplug edge node of your own; see earlier in this article for instructions on how to create such an edge node.
After you are done, press Enter to exit the program.
When the Sparkplug host application is running and connected to an MQTT broker, it will show metric data published to the same broker by properly configured Sparkplug edge node. The Sparkplug edge node should connect to the MQTT broker on "mqtt://localhost" to publish the data, unless you have changed the source code to use a different URL.
If you have the SparkplugCmd utility (e.g. if you have installed Rapid Toolkit for Sparkplug using the Connectivity Software Setup program, or obtained the SparkplugCmd separately e.g. through ClickOnce deployment), you can use it for verification of the created Sparkplug consumer (host application) as follows:
edgeNode mqtt://localhost easyGroup easySparkplugDemo start
The Rapid Toolkit for Sparkplug Edge Node Console Demo is a simple Sparkplug edge node with simulated metrics and devices. Its source code is incldued with the product in the Examples solution, and you can build it yourself and run. If you are on Windows, the pre-built edge node is also installed using the Setup program, can cen be started from the Launcher program; you will find it under -> -> .
The Sparkplug Edge Node Console Demo is pre-configured to connect to the MQTT broker on "mqtt://localhost", and use Sparkplug group easyGroup and edge node easySparkplugDemo. If you need to change any of this, these parameters can be given on the command line; the MQTT broker address is the first parameter.
The Getting Started procedure for creating a Sparkplug edge node is designed in such a way that it publishes the data that can be observed by the Sparkplug consumer Getting Started program, without any modification. Just remember to run the two programs in parallel.
If you have other Sparkplug edge node (software or hardware) that you want to use for verification, it needs to be configured with following Sparkplug identification data: Use MQTT broker address "mqtt://localhost", Sparkplug group with ID easyGroup, and the edge node ID easySparkplugDemo. You can use any metric name(s), because the Getting Started consumer (host application) displays all metrics on the edge node.
For simplicity in configuration, the Sparkplug component created in this Getting Started uses an insecure connection, and does not use any authentication. A production Sparkplug component and/or its configuration should be secured appropriately. For more information, see Security in Sparkplug.
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.