(Yes, I'm probably a gluten for punishment.)
I'm messing around with sending a message over MQTT and need extra things in the message.
The basic system works, but when I try to add extra stuff on the message, it all falls over.
From memory, JSON
takes a complex message and builds a tree on the payload
part.
So: msg.something
becomes msg.payload.something
And so on.
This is the basic code, but the msg.delay
isn't getting through.
[{"id":"99948203.32add","type":"mqtt out","z":"cc585130.29b7e8","name":"","topic":"PFC_LCD","qos":"","retain":"","broker":"c97b6780.72589","x":710,"y":740,"wires":[]},{"id":"7bc183d.305aefc","type":"inject","z":"cc585130.29b7e8","name":"","topic":"","payload":"1,1:\"This is a test\"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":740,"wires":[["cceb8bff.745918"]]},{"id":"cceb8bff.745918","type":"change","z":"cc585130.29b7e8","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"5","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":740,"wires":[["99948203.32add"]]},{"id":"c97b6780.72589","type":"mqtt-broker","z":"","name":"MQTT Host","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"20","cleansession":true,"birthTopic":"SOM","birthQos":"2","birthPayload":"'Awaiting PiFace'","closeTopic":"","closePayload":"","willTopic":"EOM","willQos":"0","willPayload":"'PiFace telemetry failure'"}]
Because the msg.payload
is: {"_msgid":"a6ceb2a3.0ce5f","topic":"","payload":"1,1:\"This is a test\"","delay":5}
So putting a JSON
node in it like so:
[{"id":"99948203.32add","type":"mqtt out","z":"cc585130.29b7e8","name":"","topic":"PFC_LCD","qos":"","retain":"","broker":"c97b6780.72589","x":830,"y":740,"wires":[]},{"id":"7bc183d.305aefc","type":"inject","z":"cc585130.29b7e8","name":"","topic":"","payload":"1,1:\"This is a test\"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":740,"wires":[["cceb8bff.745918"]]},{"id":"cceb8bff.745918","type":"change","z":"cc585130.29b7e8","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"5","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":740,"wires":[["82472447.89f28","6beaafb2.b4312"]]},{"id":"6beaafb2.b4312","type":"json","z":"cc585130.29b7e8","name":"","property":"payload","action":"","pretty":false,"x":650,"y":740,"wires":[["99948203.32add"]]},{"id":"c97b6780.72589","type":"mqtt-broker","z":"","name":"MQTT Host","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"20","cleansession":true,"birthTopic":"SOM","birthQos":"2","birthPayload":"'Awaiting PiFace'","closeTopic":"","closePayload":"","willTopic":"EOM","willQos":"0","willPayload":"'PiFace telemetry failure'"}]
I get this error:
Unexpected token , in JSON at position 1
I know: I've been told before. And I have forgotten. Sorry.
How do I get around the problem?
Thanks in advance.