-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Node-RED Global environment variables #64
Comments
Can you provide a bit more information about what the outcome is? |
I have tested both options for selecting the global context and environment variable. Unfortunately, neither of them seems to work as expected. When I choose one option among them, the provided input value for that field isn't being set. Instead, the default value, for example for host input default 127.0.0.1 is assigned. Additionally, I've tested using string type inputs, which appear to be the only ones functioning correctly. |
I have just made a quick test, which seems to work fine for me. Here is my test for global context, changing only the name of the table: Flow...[
{
"id": "433b5368aae90a2b",
"type": "debug",
"z": "d9a661f4.ef966",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1410,
"y": 400,
"wires": []
},
{
"id": "d174581733ef232d",
"type": "postgresql",
"z": "d9a661f4.ef966",
"name": "",
"query": "SELECT * FROM test\nWHERE device_id = '2'\nLIMIT 10;",
"postgreSQLConfig": "1d61b6d2fc877349",
"split": false,
"rowsPerMsg": 1,
"listen": false,
"outputs": 1,
"x": 1230,
"y": 400,
"wires": [
[
"433b5368aae90a2b"
]
]
},
{
"id": "96318ea597018065",
"type": "inject",
"z": "d9a661f4.ef966",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1060,
"y": 360,
"wires": [
[
"1dd60ae4d6f64665"
]
]
},
{
"id": "1dd60ae4d6f64665",
"type": "change",
"z": "d9a661f4.ef966",
"name": "",
"rules": [
{
"t": "set",
"p": "postgresdb",
"pt": "global",
"to": "iot",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1260,
"y": 360,
"wires": [
[]
]
},
{
"id": "48f62bdaf022041f",
"type": "inject",
"z": "d9a661f4.ef966",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1060,
"y": 400,
"wires": [
[
"d174581733ef232d"
]
]
},
{
"id": "1d61b6d2fc877349",
"type": "postgreSQLConfig",
"name": "admin@timescale:5432/global-variable",
"host": "timescale",
"hostFieldType": "str",
"port": "5432",
"portFieldType": "num",
"database": "postgresdb",
"databaseFieldType": "global",
"ssl": "false",
"sslFieldType": "bool",
"applicationName": "",
"applicationNameType": "str",
"max": "10",
"maxFieldType": "num",
"idle": "1000",
"idleFieldType": "num",
"connectionTimeout": "10000",
"connectionTimeoutFieldType": "num",
"user": "demo",
"userFieldType": "str",
"password": "example",
"passwordFieldType": "str"
}
] Regarding global variables, could you please double-check that the Node-RED flow can access your environment variables? Example with Flow...[
{
"id": "4f0274e4dd629542",
"type": "debug",
"z": "d9a661f4.ef966",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1810,
"y": 920,
"wires": []
},
{
"id": "7f99f90663124bde",
"type": "inject",
"z": "d9a661f4.ef966",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1480,
"y": 920,
"wires": [
[
"3b4f008de378cc96"
]
]
},
{
"id": "3b4f008de378cc96",
"type": "change",
"z": "d9a661f4.ef966",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "PWD",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1640,
"y": 920,
"wires": [
[
"4f0274e4dd629542"
]
]
}
] |
i have tested again configuring postgres using environment variable doesn't seems to work hear is my flow: -
|
I have tested printing environment variables using the change node. Additionally, I attempted to set a default type for the PostgreSQL configuration inputs, hoping that the getField function would return the value of the corresponding environment variable. However, the issue persists, and the default value of '127.0.0.1' continues to be set. |
node-red.7.mp4 |
Ah, there seems to be a confusion on the terminology. I was not even aware that Node-RED has recently (in version 3.1) added support for Global environment variables node-red/designs#76 Those are not environment variables, though. Environment variables, as understood in standard Linux or Windows, are defined before calling Node-RED, at OS or process level. Here is an example in Docker Compose: nodered:
image: nodered/node-red
environment:
- PG_DB=iot I have just tested and it seems to work as expected. It should be possible to change the syntax to support both types, though: |
@Alkarex if you use the utility function RED.util.evaluateNodeProperty instead of accessing
Admittingly, that ^ is generally intended for evaluating inside of alternatively, you may simply be able to call evaluateEnvProperty (not 100% certain this takes the new global env into account) |
@Steve-Mcl Thanks! Would you feel like sending a PR? |
The Node currently has an option to configure the node using environment variables, but that doesn't work as expected.
The text was updated successfully, but these errors were encountered: