Retaining the data format when using MQTT?


I have a second Raspberry Pi3 acting as a node for an Enocean switch located in another room and I need to be able to pass the Enocean data packet to the primary Node-red running on a Pi3. I am trying to do this via the MQTT server running on the primary Pi3.

The data appears as such from the Enocean receiver on the secondary Pi3 as below and I output this payload to MQTT.


I have tried to use a function on the output of the MQTT at the primary node but this is not accepted by the switch node that receives the data from the primary Enocean node.

return msg.payload;

The debug shows this as a string and not an object. The attached image shows the received data on the second Pi3 on the left and the right side shows the received data from the MQTT output on the primary Pi3.

How can I retain the same data format so that the primary nodes can handle the data?



Try a json node between debug and your function



That didn't work. The preceding function cannot decode the data. It is still not being seen as a valid javescript object for some reason.



OK. I got it to work. I have to put a JSON on the input to the MQTT connection on the second Pi3 and then a second JSON on the MQTT output on the first Pi3 and now it works.