Hello,
I’m working with Node-RED and trying to use the MQTT Dynamic Broker out node to connect to an MQTT broker using a dynamically provided flow-level IP address. The goal is to pass the IP address to the broker dynamically via a text input widget in the UI, but I’m encountering an issue where the connection fails. The terminal shows the following error:
**Connection failed to broker: mqtt://$undefined:1883**
Setup:
- UI Setup: I have a text input widget that lets the user input an IP address.
- Change Node: I use a Change node to update the flow context. Specifically, I set
msg.payload
(UI input)toflow.ip
. - Function Node: I use a Function node to get the IP address from the flow context and assign it to
msg.hostname2
. Thismsg.hostname2
is then used in a debug node to confirm the value.
Problem:
- Initially, when the flow starts, the IP address is empty, so the MQTT Dynamic Broker out node tries to connect with
mqtt://$undefined:1883
, which results in the connection failure. - After the user inputs the IP address (e.g.,
10.2.35.117
), the debug node correctly shows the updated value ofmsg.hostname2
. However, the MQTT Dynamic Broker out node still fails to connect, and the terminal message showsmqtt://$undefined:1883
instead ofmqtt://10.2.35.117:1883
.
What I’ve Tried:
- Hardcoding the IP Address: I hardcoded the IP address directly in the MQTT Dynamic Broker out node, and the connection works fine. However, I want to avoid hardcoding the IP and have it set dynamically by the user.
- Testing with Variables: I tested using
${msg.hostname2}
and${flow.ip}
in the MQTT Dynamic Broker out node to pass the IP address. Both attempts still result in the error, and I’m not sure which variable to use. - Debugging: The debug node shows that the flow-level variable
msg.hostname2
is correctly updated with the IP address once the user inputs it.
What I Expect:
I would like the MQTT connection to be established using the dynamic IP address that the user inputs via the UI. The MQTT Dynamic Broker out node should then use the updated value from the flow context and successfully connect to mqtt://<IP_ADDRESS>:1883
.
- Why does the MQTT Dynamic Broker out node still try to connect with
mqtt://$undefined:1883
even after the IP address has been set in the flow context? - Should I be using
msg.hostname2
orflow.ip
in the MQTT Dynamic Broker out node, and why isn’t it working?
Can anyone help identify what might be causing the connection failure or provide suggestions for how to resolve this issue?