MQTT publish inject credentials

Hello,

End goal is to be able to setup "MQTT Out" credentials via ENV_Variables

First, I'm trying to inject credentials via nodes.
Tried to follow @Steve-Mcl guide:

Notes I have from broker side:

  • Broker setup from IT side allows nodered only to publish messages. If I try to subscribe with the same credentials, I get disconnected immediately. I delete "MQTT In" node and "MQTT Out" node recovers to "Connected" state.

  • MQTT out works when the same credentials are inserted into the node statically.

As far as I understand option "Dynamic subscription" is only for "MQTT In" node and it doesn't transfer to MQTT out node.

Flow:

[{"id":"6a114e1f2c1941c4","type":"inject","z":"17544288b1b6c2c1","name":"inject","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":610,"y":2240,"wires":[["285ee8faf1b91503"]]},{"id":"285ee8faf1b91503","type":"change","z":"17544288b1b6c2c1","name":"dynamic setup","rules":[{"t":"set","p":"action","pt":"msg","to":"connect","tot":"str"},{"t":"set","p":"broker","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"broker.password","pt":"msg","to":"psw","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"data/e2e_pipeline/nodered","tot":"str"},{"t":"set","p":"broker.username","pt":"msg","to":"user","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":2240,"wires":[["79526e7c26285d53"]]},{"id":"79526e7c26285d53","type":"mqtt out","z":"17544288b1b6c2c1","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"9cdd6c4e996aa6eb","x":910,"y":2240,"wires":[]},{"id":"9cdd6c4e996aa6eb","type":"mqtt-broker","name":"test","broker":"192.168.246.2","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"6","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

You can simply specify the credentials in the MQTT config

image

https://nodered.org/docs/user-guide/environment-variables

You are misunderstanding the connection between the config and the -in/-out nodes. If the -in/-out nodes have the SAME -config node selected, the "dynamic" operations are performed against the -config of that -in or -out node. Only the "subscribe" action has an effect on the -in node.

In short:

The MQTT-IN node is used in the linked demo to perform the dynamic actions (connect/disconnect/subscribe)

The MQTT-out node is still used for publishing:
image

Either the -in or -out node can accept the dynamic commands - they just get pushed to the MQTT-config (and that config is shared with each -in and -out node that you have selected the -config for.

Good to know that I don't have to do anything with MQTT-IN.

I will try to check ENV_VAR suggestions when I get access to that machine.

That said, my MQTT publish works with statically typed setup:
image

When I delete credentials:
image

It is immediately disconnected (makes sense)
Broker setup stays the same:
image

But my inject doesn't establish connection:
image

Is there anything else I'm missing?

  1. where are you sending this message (to an -in or -out)? (hint try both)
  2. it is recommended you disable "connect automatically" to avoid the attempted connection with incomplete settings. use the connect action to switch it on.
  3. topic is not required (does nothing on the connect action)
1 Like

It worked after I disabled "Connect automatically"

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.