8

I am experimenting with node-red, connecting it to my MQTT broker.

The input (listening to a topic) works fine.

I also would like to send to a topic some payload ipon some triggers. In the example below, this would be on a query to a webservice:

enter image description here

I did not have a place to add the payload to the published message, where can I set it up?

The documentation mentions in the inputs section:

payload

most users prefer simple text payloads, but binary buffers can also be published.

and later

msg.payload is used as the payload of the published message. If it contains an Object it will be converted to a JSON string before being sent. If it contains a binary Buffer the message will be published as-is.

I tried to add {msg: {payload: 'on'}} or {payload: 'on'} in node settings -> inputs but the payload is not carried to the MQTT, which hows an incoming cmnd/home/room1/switch1/power {}

enter image description here

WoJ
  • 865
  • 1
  • 6
  • 14

1 Answers1

5

The payload comes from the incoming message. It does not make sense to define a static payload in the MQTT-out node.

The entry in the node-settings is just a mouse over label for the input, since nodes can only have 1 input it's not that useful, it's more for when nodes have multiple outputs to make it easier to identify which output is which.

In the case you have posted a screen shot ofit will take the msg.payload output from the http-in node, which would be the body of a HTTP POST.

If want to add a static payload to be published then the easiest way is to add a change node between the http-in and mqtt-out node.

e.g. to set the payload to "foo"

enter image description here

You can set JSON objects by selecting the type from the drop down on the left hand end of the to field.

hardillb
  • 12,813
  • 1
  • 21
  • 34