Retaining the data format when using MQTT?

#1

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.

{"data":{"timestamp":1544489107519,
"rawByte":"55000707017af600002d092e2001ffffffff49005d",
"packetType":1,
"senderId":"002d092e",
"choice":"f6",
"subTelNum":1,
"destinationId":"ffffffff",
"rssi":73,
"securityLevel":0,
"raw":"00",
"packetTypeString":"RPS"}}

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?

0 Likes

#2

Try a json node between debug and your function

0 Likes

#3

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.

0 Likes

#4

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.

0 Likes