Hi.
I've been running node-red on a BeagleBone Black Wireless for some time now and am trying to make some upgrades to the software, mainly to parameterize the MQTT connection.
I've set some shell variables
MQTT_BROKER
MQTT_CLIENT
MQTT_PORT
MQTT_QOS
MQTT_TOPIC
MQTT_NAME
to values that currently are known to work. I then changed the MQTT out node and its broker node to try to use these values as ${MQTT_BROKER}, etc. I've had several problems in this endeavor:
it's not clear how to set these variables before node-red starts automatically, so it's not clear to me whether these the values of these variables are even being set. To get past this problem for the time being, I've stopped node-red, set the variables, tested that they are indeed set by examining the output of
set | grep MQTT
and then restarted node-red.
Nevertheless, it doesn't appear that the values are used. Indeed, I can't even deploy with the broker's port set to ${MQTT_PORT}, so I have set it to 1883 for the time being.
After restarting node-red, the log shows
29 Feb 15:46:35 - [info] Starting flows
29 Feb 15:46:36 - [info] [wifiscan:e07da6ad.5061d8] wifiscan - Initialized
29 Feb 15:46:36 - [info] Started flows
29 Feb 15:46:36 - [info] serial port /dev/ttyO4 opened at 2400 baud 8N1
29 Feb 15:46:36 - [info] [mqtt-broker:BBBW] Connection failed to broker: {MQTT_CLIENTID}@mqtt://{MQTT_HOST}:1883
29 Feb 15:46:51 - [info] [mqtt-broker:BBBW] Connection failed to broker: {MQTT_CLIENTID}@mqtt://{MQTT_HOST}:1883
29 Feb 15:47:06 - [info] [mqtt-broker:BBBW] Connection failed to broker: {MQTT_CLIENTID}@mqtt://{MQTT_HOST}:1883
etc.
The failed attempts continue even after moving a node (to activate the "deploy" option) and then deploying.
Are you starting node red in the same environment that you have set the vars? Or to put it another way exactly how are you setting them then starting node-red?
Hi. Thanks for asking. Here's a listing of the session (with some obfuscation for privacy). The obscured values are ones known to work both before and after this experiment.
root@beaglebone:/home/me# set | grep MQTT
MQTT_BROKER=[---]
MQTT_CLIENT_ID=[---]
MQTT_PORT=1883
MQTT_QOS=1
MQTT_TOPIC=[---]
root@beaglebone:/home/me# service node-red stop
root@beaglebone:/home/me# service node-red start
root@beaglebone:/home/me# journalctl -f -u node-red -o cat
Oh, maybe I should mention that I ended up using neither the MQTT_PORT nor the MQTT_QOS value, as neither was possible.
Not quite. The editor side tries to validate the node configuration port value as a number, but the value is "${MQTT...}". That will cause it to flag it up as being invalid, but you can still deploy. But you'd have to manually edit the flow file to add that value anyway.
How are you setting the env vars in the first place? Just because they are set in your local root shell, it doesn't mean they will be set when running NR as a service.
You could add some console.log lines in your settings.js file to print out the values of process.env.MQTT_BROKER etc.
And to answer your question about how I'm setting the variables, I'm sourcing a file with lines like
export MQTT_BROKER=alpha.beta.com
export MQTT_CLIENT_ID=Whatever
and then I check that the settings took by running
I think the problem is that you are setting the env vars in your terminal session but the service gets a new environment so they are not set. This is as it should be because you wouldn't want a service start to behave differently dependent on what env vars happen to be set in the session you start it from. I think you will need to set them up in the service or settings, or read them from a file in the service start, or something else along those lines.
This might be the best way to do it, if it is appropriate. It overrides the service file in a way that will survive updates as the original service file is not changed.