I found it would be convenient if I could easily store my board or other device objects within the flow variable available to all "function" node sandboxes. e.g.:
// this is a j5 node
const left = new five.Relay({pin: 11, type: 'NC'});
left.on();
const relays = flow.get('relays') || {};
relays.left = left;
flow.set('relays', relays);
node.send({
payload: {
relay: 'left'
}
});
Later, a "function" node:
// this is a plain old function node
const relay = flow.get('relays').left;
const data = msg.payload.data = {};
const isOn = relay.isOn;
data[`${msg.payload.relay}_on`] = isOn;
if (isOn) {
node.status({fill: 'green', shape: 'dot', text: 'on'});
} else {
node.status({fill: 'red', shape: 'ring', text: 'off'});
}
return msg;
Caveats:
this may break compatibility with certain versions of Node-Red, but I couldn't say for sure
this may break backwards compatibility in general (I'd recommend a "major" bump here)
the code was mainly copypasta from the core function node source in Node-Red.
Howdy,
I found it would be convenient if I could easily store my
board
or other device objects within theflow
variable available to all "function" node sandboxes. e.g.:Later, a "function" node:
Caveats: