Publish data to external MQTT

Hi,

I’m trying to create virtual device using a workflow. And the generated payload from this device to be send to external MQTT.

In the end of the workflow I’m using a MQTT Message Node (Orange color) pointing to Integration where is configured the the 3rd party MQTT. The virtual device is generating a random data storing it in The Device: State Node before the MQTT. It also has a debug node after the state node where I can check the generated random device data.

In the 3rd party MQTT subscriber to the topic is getting [object Object]. If convert bytes to string I’m getting “W29iamVjdCBPYmplY3Rd” and is not a JSON. I’m trying to send JSON data in the message but not succeeding.
Is there a important configuration that has to be taken in account in order to send json to 3rd party MQTT?

Hi @Hristo_Gichev and welcome to the Losant forums!

It sounds like you have an object on your payload that you’re referencing in the MQTT Node message template. You’ll need to convert that object into a JSON string.

The easiest way to do this is with the {{jsonEncode}} helper, which can be used in the MQTT Node message template as shown below:

We also have a JSON Encode Node that essentially does the same thing, but might be helpful for testing or validation checks earlier in the workflow.

Give this a try and let us know how it goes!