In this Getting Started, you can create
In this Getting Started procedure, we will create a Sparkplug edge node in C# or VB.NET. 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 the Visual Studio IDE (Integrated Development Environment).
In this step, we will create a new .NET console application project.
Select -> -> from the menu. The Create a new project dialog appears. In the language selection drop-down (initially set to All languages), select either C# or Visual Basic. Type Console App into the search box. Select either Console App (for .NET 8+) or Console App (.NET Framework). Press the button. Go through the remaining steps of the wizard, making sure that you select a supported framework (see OPC Wizard Required .NET Runtimes).
In this step, we will add a reference to the OpcLabs.EasySparkplug NuGet package.
Switch to the Solution Explorer window, right-click on the project node (ConsoleAppn), and select command. In the NuGet: project window, switch to the Browse tab, and type OpcLabs.EasySparkplug into the search box. Select the OpcLabs.EasySparkplug package in the package list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "Latest stable 5.83.build" (where build is a build number). Press the button. If the Preview Changes dialog is displayed, press the button. Wait until the packages are installed.
In the Solution Explorer window of Visual Studio, open the Program.cs (or Program.vb, if your are developing in VB.NET) file, and add following code to the beginning of the file:
In Program.cs (or Program.vb, if your are developing in VB.NET), 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 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# or VB.NET. 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 the Visual Studio IDE (Integrated Development Environment).
In this step, we will create a new .NET console application project.
Select -> -> from the menu. The Create a new project dialog appears. In the language selection drop-down (initially set to All languages), select either C# or Visual Basic. Type Console App into the search box. Select either Console App (for .NET 8+) or Console App (.NET Framework). Press the button. Go through the remaining steps of the wizard, making sure that you select a supported framework (see OPC Wizard Required .NET Runtimes).
In this step, we will add a reference to the OpcLabs.EasySparkplug NuGet package.
Switch to the Solution Explorer window, right-click on the project node (ConsoleAppn), and select command. In the NuGet: project window, switch to the Browse tab, and type OpcLabs.EasySparkplug into the search box. Select the OpcLabs.EasySparkplug package in the package list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "Latest stable 5.83.build" (where build is a build number). Press the button. If the Preview Changes dialog is displayed, press the button. Wait until the packages are installed.
In the Solution Explorer window of Visual Studio, open the Program.cs (or Program.vb, if your are developing in VB.NET) file, and add following code to the beginning of the file:
In Program.cs (or Program.vb, if your are developing in VB.NET), 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.