If I send a command to a device using the name set
and following payload:
{
"on": true,
"relay": "left"
}
The result on my end is something like this:
{
"topic": "structure/xxxxx/command",
"payload": "{\"name\":\"set\",\"payload\":{\"on\":true,\"relay\":\"left\"},\"time\":{\"$date\":\"2016-04-13T20:46:19.768Z\"}}",
"qos": 0,
"retain": false,
"_msgid": "a4f3545b.5b0ca8" }
}
Why is the payload stringified? This is somewhat unexpected, and requires extra work on my end. FWIW, “my end” is Node-Red, and I need to use a parse node (to call JSON.parse()
on the payload
field), followed by a change node to normalize the data.
Granted, JSON is not the only thing you can send over MQTT, so this makes sense, but since the UI requires a valid JSON object, I’d expect the command to be parsed before publishing. From the MQTT specification, payload
can be anything, yes? I’m an MQTT novice, so pardon my ignorance.
I would expect this message to look something like this:
{
"topic": "structure/xxxxx/command",
"payload": {
"name": "set",
"data": {
"on": true,
"relay": "left"
},
"time": {
"$date": "2016-04-13T20:46:19.768Z"
}
},
"qos": 0,
"retain": false,
"_msgid": "a4f3545b.5b0ca8"
}