Skip to content

A node that counts messages received in a specified time limit

License

Notifications You must be signed in to change notification settings

tomgidden/node-red-contrib-timed-counter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-red-contrib-timed-counter

A node that counts messages received in a specified time limit.

This node counts incoming messages while they are received in a configured time limit, or number of messages. When the first message comes in, a countdown timer is started. When subsequent messages arrive within the time limit the counter is incremented, so the first message gets msg.count == 1, the next msg.count == 2, and so on. When the time limit is reached, the counter is reset.

It can be configured in a couple of different ways:

  • Firstly, with a fixed timeout, so it only counts within a time limit from the first message received in a chain.
  • Alternatively, a non-fixed timeout will result in each subsequent message resetting the time limit but not the counter; so if messages continue to be received by a certain frequency, the timer will be restarted but the count kept. This allows messages to be counted without limit, as long as they keep coming in fast enough.
  • Finally, to send immediately once a number of messages are received, or the timeouts as above. ("Count limit")

"Final only" sets whether to allow each message to pass through (with their counts added) as they are received, or whether to withhold them and just send the last one. This is to allow for a single message to represent all of the messages in a chain. For example, if detecting a double- or triple-click of a button to determine an alternative function, the first click might not be desired if immediately followed by a second click.

So, for a typical mouse single-, double- and triple-click detector, set the "Time limit" to 350 milliseconds or so, untick "Fixed time", and tick "Final only". The message that is eventually received will have a msg.count value equal to 1, 2, 3, or more. A switch node or a function node may be used to decide how to process them.

If a message with msg.reset set, then the timer and count will be reset. If "Final message" is set, this reset message will be lost; if it isn't set then the reset message will flow through.

"Per-topic" will treat each different incoming topic as a separate counter so they're treated independently. If unticked, all messages are dealt with by the same counter regardless of topic.

About

A node that counts messages received in a specified time limit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published