Demo: Sparkplug Primary Host Application in SparkplugCmd
From OPC Labs Knowledge Base
This article demonstrates the concept of Sparkplug Primary Host Application using the SparkplugCmd utility.
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.
Prerequisites
- MQTT broker. We assume one at mqtt://localhost:1883.
- SparkplugCmd utility.
Demo Procedure
Note that we will be using two separately running instances of the SparkplugCmd utility, one for the edge node and one for the host application.
- Start the MQTT broker.
- Start the first instance of the SparkplugCmd utility. This will be our edge node instance.
- At the SparkplugCmd> prompt in the edge node instance, enter command edgeNode mqtt://localhost:1883 --primaryHostId easyApplication.
- At the edgeNode> prompt, enter command start. The edge node will start. However, the primary host application is not online, and you will see repeated PublishingError events with the message "The Sparkplug producer is offline".
- Start the second instance of the SparkplugCmd utility. This will be our host application instance.
- At the SparkplugCmd> prompt in the host application instance, enter command consumer mqtt://localhost:1883 --hostId easyApplication.
- At the consumer> prompt, enter command subscribePayload !wait Infinite. The host application will go online and subscribe to the payloads from the edge node.
- In the edge node instance, you will see Birth events for the edge node and its devices, indicating that the edge node has detected that the primary host application is now online. The PublishingError events will stop, and the edge node and its devices will be publishing data payloads.
- In the host application instance, you will see payloads with the data coming from the edge node and its devices.
- Switch to the host application instance, and press X. This disconnects the host application from the MQTT broker. Since the host application has registered the "Last Will and Testament (LWT)" message with the MQTT broker, the MQTT broker will send the LWT message on behalf of the host application to the topic prescribed by the Sparkplug specification, and the edge node that has its primary host application configured appropriately will detect that the host application is now offline.
- In the edge node instance, you will Death events, indicating that the edge node has detected that the primary host application is now offline.[1] You will start seeing repeated PublishingError events with the message "The Sparkplug producer is offline" again.
- The host application instance will return to the consumer> prompt.
- If you like, you can now repeat steps 7 - 9.
- For full shutdown, you can stop the edge node by pressing X. Then, terminate the edge node and host application instances using the quit command in each of them (or simply close their windows). Stop the MQTT broker.
- ↑ The edge node will also disconnect from the MQTT broker and reconnect again. This behavior is required by the Sparkplug specification.
