Email Us at [email protected]

Download N3uron

Back to videos

MQTT Client / MQTT Client Custom Payload

MQTT Client Custom Payload

Description

In this video of our N3uron Academy, we’ll show you how to configure a Custom Payload for the N3uron MQTT Client module. Let’s get started!

  • [04:07] MQTT Client Custom Payload

Transcription

[00:00] Hello everyone! In this video, we’ll show you how to configure a Custom Payload for the N3uron MQTT Client module. While the MQTT Client Publisher comes with preconfigured serialization formats for JSON, InfluxDB, and Protobuf, we’ll demonstrate how to create a custom serialization for your Custom Payload using the broker configuration connection we established in the MQTT Client Configuration video. First, let’s walk through our objective. On the screen, you can see we’re receiving real-time data from an OPC-UA Client subscription connected to an OPC-UA Server at a Photovoltaic Plant. As depicted in this diagram, our goal is to format the MQTT Publisher payload for all the events generated by these tags. Notice how the tag paths, which are typically separated by forward slashes, have been converted to use dots instead.

[01:04] The payload contains key-value pairs for tagName, value, quality, and timestamp. The quality field is a string that indicates the status, either GOOD or BAD, along with its code, while the timestamp is shown as a localized date string. To get started, navigate to the “Config” tab under “System,” select “Modules,” and locate the Mosquitto connection we set up earlier. Right-click on the connection, select “New Publisher,” assign it a name such as “CustomPublisher,” and configure it within the existing Mosquitto broker connection. Now, let’s configure the publisher’s topic as PV-PLANT and set the message format. While the MQTT Client Publisher supports JSON, InfluxDB, and Protobuf, we’ll use “Custom” to define our own payload. We’ll keep the encoding as UTF-8 and disable compression. With this setup, we can now script the payload structure to format event data before publishing it to the MQTT broker.

[02:02] A default script template is provided, but we will modify it. Now, let’s break down how our custom payload script processes the data before publishing it. First, the script logs the raw input events for debugging. It then reformats each event by adjusting the tag name—removing the first forward slash and replacing the rest with dots—before assigning the event value to the value key. Next, it formats the quality field by categorizing it as “GOOD” or “BAD” based on its value, appending the corresponding quality code for clarity. The timestamp is also converted into a localized ISO-String format. Once all transformations are complete, the script logs the modified output for debugging, converts the response into a JSON string, and sets it as the final output. Finally, we save the script changes and create a tag filter for the publisher, which, in this case, is set to include the entire data model. Once everything is configured, save and apply the changes.

[03:01] Then, navigate to Diagnostics, enable Real-Time Logs, select the MQTT Client module, and verify that messages are being published. To ensure everything is working, use a third-party MQTT client to subscribe to the topic and inspect the published messages. You should see the Custom Payload formatted exactly as intended. And that’s it! We’ve successfully set up a Custom Payload for the N3uron MQTT Client, allowing for a more tailored publishing payload beyond the pre-configured options. Thanks for watching!

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from - Youtube
Vimeo
Consent to display content from - Vimeo
Google Maps
Consent to display content from - Google
Spotify
Consent to display content from - Spotify
Sound Cloud
Consent to display content from - Sound