Hi,
I like to fetch an environment variable in oneditsave()
and wonder if this is possible. I think that the problem is, that we're on the browser, but need to get data from the NR-flow.
Something like:
//...
oneditsave: function () {
// ...
const e = $env.get('VARIABLE');
// ...
}
Is there a straightforward way?
You can add an admin endpoint in node-red (server-side) (in the JS) and call it from the front end (in the html script).
Look at the source for the serial node (and others) that already do this.
I'm on my lunch, so dropping by...
To enforce the above by @Steve-Mcl , here is what I do for my z-wave module:
Here is an http endpoint, that returns serial ports :
.start()
.catch((e) => {
self.error(e);
return;
})
.then(() => {
//
});
};
RED.httpAdmin.get('/zwave-js/ui/global/getports', RED.auth.needsPermission('flows.write'), (_, response) => {
Driver.enumerateSerialPorts()
.then((data) => {
response.json({ callSuccess: true, response: data });
})
.catch((Error) => {
response.json({ callSuccess: false, response: Error.message });
});
});
RED.nodes.registerType('zwavejs-runtime', init, {
Then in my node html (oneditprepare
)
'timeouts_response',
'timeouts_sendDataCallback',
'timeouts_report',
'timeouts_serialAPIStarted'
];
Numericle.forEach((K) => {
const Value = this[K] || K.startsWith('timeouts') ? 0 : '';
$(`#el-node-config-input-${K}`).val(Value.toString());
});
$.getJSON('zwave-js/ui/global/getports', (data) => {
if (data.callSuccess) {
data.response.forEach((SP) => {
$('#node-config-input-serialPort').append(new Option(SP, SP));
});
} else {
alert(data.response);
}
});
}
1 Like
uibuilder also has several examples and they are broken out into separate functions for convenience along with error handling and user-notification where needed.
Cool, works like charm. A little bit painful to search all these source code for solutions.
Maybe fresh eyes could document it and submit a PR against the node-red docs?
1 Like
system
Closed
3 February 2023 13:15
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.