node-red / cookbook.nodered.org

Node-RED Cookbook
http://cookbook.nodered.org
Apache License 2.0
84 stars 34 forks source link

Feedback on 'Trigger a flow if a message isn’t received after a defined time' #41

Closed Nokomis449 closed 5 years ago

Nokomis449 commented 5 years ago

Currently, the Trigger node can be configured to fire one time when an incoming message is not rec'd. I would like an option that it will continually trigger at the specified interval if a message is not rec'd (I. E., until a valid message is rec'd). My current need is to continue to send data to a graph until the actual data flow is rec'd again. The triggered data is to indicate on the graph that data was not rec'd during the indicated time frame. As it is, the graph line will be drawn between the last rec'd data point and the first resumed data point, without any indication that data was lost. Another example might be to ping a device every 5 minutes, and if the ping is unsuccessful use the Trigger node to send a reset command. The Trigger node would know when to send the first reset, but if a ping is not restarted I'd want the Trigger node to send another reset after 5 more minutes. I'm still new to NR and I'm sure there's a way to do what I need, but I think an additional option in the Trigger node would be a great place to put it. Thanks for listening.

knolleary commented 5 years ago

Hi, thanks for the feedback. This particular issue tracker is for feedback on the recipe from the cookbook. If you have feature suggestions for Node-RED itself, the forum is the best place to start a discussion about them - https://discourse.nodered.org

On this particular item, the Trigger node already does have the option to repeated send a message in absence of another one. Have a look at those options and see if they fit you needs. We've only just today published this recipe and no doubt there are others to write that cover more scenarios like you describe.

Nokomis449 commented 5 years ago

OK Thanks. It's not glaringly obvious to a newbie like me how to make it repeat until a valid msg appears but now that I know it can, I'm sure I can Google up an example.

knolleary commented 5 years ago

I've had a play and it is doable, but I agree it isn't obvious if you aren't familiar with the node. So much so, I'll add a recipe as I think its a useful scenario to cover - just need to find the succinct title to describe it.

local_node-red
[{"id":"9ccdf268.c96ff","type":"inject","z":"ac14500e.2c57d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":2020,"wires":[["38950a5.28d15f6","2c532f67.0330e","40589e4.eccb56"]]},{"id":"38950a5.28d15f6","type":"debug","z":"ac14500e.2c57d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":2020,"wires":[]},{"id":"2c532f67.0330e","type":"trigger","z":"ac14500e.2c57d","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"2","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":320,"y":2120,"wires":[["e4e42b96.97a338"]]},{"id":"e4e42b96.97a338","type":"trigger","z":"ac14500e.2c57d","op1":"0","op2":"0","op1type":"num","op2type":"str","duration":"-2","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":540,"y":2120,"wires":[["38950a5.28d15f6"]]},{"id":"40589e4.eccb56","type":"change","z":"ac14500e.2c57d","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":2080,"wires":[["e4e42b96.97a338"]]}]

The inject node simulates the feed of events you receive. The first Trigger node is setup as a Watchdog so it will only send something on if there's a 2 second gap in messages it receives. When it sends on a message, it triggers the second Trigger node. That node is configured to send 0 every two seconds - the value to signify no data received - which feeds back into the top branch. There is a third branch from the initial Inject that sets msg.reset and passes it to the second Trigger node. This stops it from sending the 0 when messages start flowing from the source again.

knolleary commented 5 years ago

Have now added this to the cookbook - https://cookbook.nodered.org/basic/trigger-placeholder - I think that covers your request. Going to close this issue.

Nokomis449 commented 5 years ago

Yes that should cover me, and after you told me it could be done I found a very similar flow you had discussed in a Node RED Google Groups from 2015. Thanks again for your time.