Reputation: 21
I have built a simple application which connects to my IoT temp sensor device and sends an email based on the temp--warm, just right, and cold. To do this I've used the IBM IoT node for connecting to my IoT device, and then processed the data with case statements to fall into the three buckets: warm, just right, and cold. From there I generate an email and send the temp category to my email address.
However, my temp sensor is measuring and sending data every 1 second so my app is sending an email every 1 second--which is too often. Instead I'd like to only send an email when there is a transition between the three temperature states. Naturally, I'd like to implement this with a state machine or the case statement processing block. This requires that I have both data points: the current temp measurement and the last recorded measurement. What is the best way to go about storing the last recorded temp measurement and are there any tips on the node flow I should use?
Upvotes: 1
Views: 592
Reputation: 6826
As well as rbe you can use a delay node (third in the Function palette) to rate limit to e.g 5 messages a minute (programmable number and period), with a choice of whether to discard the excess messages. Presumably you might not discard when messages arrive in short bursts with long gaps between bursts.
Upvotes: 0
Reputation: 59608
The is a report by exception (rbe) node in the default pallet that will do this for you.
It only allows messages to pass if their msg.payload
field is different from the last message.
A flow would look something like this:
I've used a MQTT input instead of a IoTf node, but it's near enough the same.
The function node set's the email body (msg.payload) and the rbe node will deal with the only sending once per change.
One thing to note is that the rbe node filters on a per topic basis so all the messages same topic, but the email-out node uses the topic to set the email subject.
Upvotes: 1
Reputation: 15246
If we have a look at this article:
http://noderedguide.com/index.php/2015/11/06/node-red-lecture-5-the-node-red-programming-model/
We find a section called "context". This allows us to maintain state data between instances of a message flow either globally or just locally to a particular node. What that means is that a value received at an earlier time can be saved and compared against the current value. You have to use the JavaScript language in a Function
node but I am hoping that isn't too complicated and there are lots of examples around.
Upvotes: 1