I did a quick search and didn’t see anything directly related, so I thought I’d ask here. What’s the “best” way to trigger a specific Node-RED flow from PAC Control?
I know that I can do time-based polling, but that’s not a great fit for my application. I’m wondering if my best option is to use PAC Control to write/touch a file and then have my Node-RED flow set up to run when it detects a change to the file.
Are you looking for sub 1 second response? If so I wonder what the rest of the flow looks like…
But if you can take 1 second, just poll with an inject node the PAC Control read node thats looking at an int32 and then follow that with a switch node that passes it onto the flow when the values is the ‘go-trigger’ value.
The one var in PAC Control could in this way fire off different flows pretty smoothly.
You are going to have some sort of poll regardless.
You can poll a var or you can poll the file read, but you are going to have to poll something.
I mean, if you really don’t want to poll and are ready to really look at a nice learning curve, there is always the Node-RED API.
Philip beat me to it… UDP would be better than TCP, you have to really manage those socket connections from PAC. The TTL (Time To Live) can bite you when you least expect it. Also opening and closing the HTTP stuff has a fair bit of overhead compared to UDP.
I would need to look up the docs / experiment to determine if you would want to open and close the handle on the UDP connection - they are technically connectionless. I would probably open it and never close it.
On UDP, the connection isn’t closed on errors - so you can leave it open. From PAC Control help:
Many applications never close a communication handle once they are opened. If a communication fault were to occur on an unbound communication handle, the handle continues to remain open and may still be used to resume communications. If the communication handle was bound, it too remains open and datagrams will be received once the network problem is corrected.
Use TransmitString instead of TransmitChar or call TransmitNewLine after using TransmitChar. TransmitChar only adds the character to the buffer.
@philip & @Beno: Thank you for the help. I got this UDP method set up, and I like it because I can send a string “command” to a Node-RED flow and branch off in a variety of different directions based on the command sent. That saves me from having to poll a number of different PAC variables.