I am developing an application with several stepper motors on Raspberry Pi. Each stepper motor has its own sub-flow with inject node to update its state and handle commands (home, move, reset). Various nodes can use link out/in to send a msg COMMAND to a stepper sub-flow. The question is how to best receive a response that the command is complete. In other languages, one would just use call and return.
- Use link out/in to connect the msg output of the motor sub-flow to all interested nodes. These nodes will need to screen out messages not relevant to their request, perhaps by adding a field to the original message (e.g. msg.source). I do see that there are contributed flows to provide subroutine like features (action flows and components), so that is an option.
- Have the motor sub-flow set a global variable with its status and then the "calling" function node can poll this variable. This will require a bit of handshaking since the calling node cannot be sure when the sub-flow has received the command.
- Ditch the messages and have the calling node set a global variable with the command and then poll a global variable that is set by the motor sub-flow. The polling can be triggered using setInterval or an inject node. While this seems un-NodeRed like, there are built-in nodes that are essentially doing just that (e.g. digital in, watch, serial in).
Opinions? Other options?
Thanks,
Tom