Best Way to Trigger Node-RED Flow from PAC Control?

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.

@Beno: no, I don’t need sub 1 second response, so your solution is probably the simplest. Guess I was just wondering if there was a solution different than polling.

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.

One final question: is there some reason I wouldn’t want to use an HTTP In node since it’s pretty simple to perform a simple GET request from within PAC Control?

You could have a UDP listener in Node-Red and send off a UDP packet from PAC Control when you want the flow to run.

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.

@philip: I’m not too familiar with using UDP in this way. When you say send off a packet, is this more than sending a character to a UDP communication handle:

SetCommunicationHandleValue(handle, "udp:55555");
OpenOutgoingCommunication(handle);
TransmitChar('x', handle);
CloseCommunication(handle);

Then allowing UDP traffic on the chosen port number and setting up the UDP listener in Node-RED?

No, that is pretty much it.

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.

1 Like

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.

1 Like

@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.

3 Likes