Hi,
I have multiple devices that can connect via MQTT into my node-red application. Every device has a unique ID (let's name it devID
). I need to keep a bunch of state information for every device separately, and the states are the same for all devices. State examples: IDLE, TXING_DATA, RXING_DATA, etc.
I have been using global context to manage those instances, for example:
// [...]
// msg.devID contains the device ID that came from MQTT.
var state;
var devObject;
// get device global state
devObject = global.get(msg.devID);
if (devObject.state)
state = devObject.state;
else
state = IDLE; // default state
// do something with device state
// [...]
// save device global state
devObject.state = state;
global.set(msg.devID, devObject);
// [...]
However, it's getting difficult for me to organize my flows and nodes as the application grows. Also, the built-in nodes like Switch and Change don't allow the usage of a variable (msg.devID) within the expressions.
In my search for node-red FSM libraries, I haven't found any that would allow me to use multiple separate instances of the same FSM for every device.
I appreciate any suggestions,
Thank you very much.