Example JSON for Node-RED
Closed this issue · 2 comments
Hi
Sorry, not a bug as such, but I've spent the last couple of hours trying to send a well-formed JSON message to winthing using Node-RED and Mosquito on Debian and I'm getting nowhere.
Do you have a full example for the run message?
As an example, I have sent (plus tens of other variants) the following and always get the same errors from winthing; either "Inavlid JSON" or "Invalid Arguments";
{
"winthing/system/commands/run": [
"notepad.exe",
"c:/out.txt",
"c:/"
]
}
Sorry for posting as a bug but there's no discussion section for this project.
Hmm, I don't know much about Node RED, but are you sending the whole JSON you posted as the MQTT message payload? If so, that's not how it works. You're supposed to publish MQTT message with payload ["notepad.exe", "c:/out.txt"]
to the topic winthing/system/commands/run
So I came back to this tonight, and just sent the message as type "String" in Node-RED and it worked 👍
If anybody else is using Node-RED, the flow is very easy, you simply need an "Inject" node, configured as follows;
Payload Type (drop down - a-z icon): String
Payload Content: ["notepad.exe","c:\out.txt", "c:\"
Topic: winthing/system/commands/run
Then join that to an MQTT Out Node configured with your MQTT broker details.
Here's the Node-RED JSON for my simple example flow (this also includes a listener on winthing/+/+/+ to listen to all events from the winthing service);
[{"id":"4770787b.cc0578","type":"mqtt in","z":"e2a8b25b.6f56e","name":"","topic":"winthing/+/+/+","qos":"2","broker":"39cf662e.452d4a","x":241.5,"y":106,"wires":[["b6246eff.d4424"]]},{"id":"39cf662e.452d4a","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]
Amend to suit your configuration.