I am using the email notification triggered by an event (high temperature) The script. unfortunately sends multiple emails as long as the event is true.
I would like to send 3(only) notifications(email to text via my cell provider. You would then press a virtual button to reset the event until the event happened again. hope someone has an idea.
Post your code so we can take a look, and see if we spot anything or can give suggestions. Don’t forget to use the proper format when posting it.
Have you tried the example sketch in the SKETCH BUILDER? It looks like it should work, but isn’t exactly how I would do it.
You just create your own flag counter in code, and have it reset via a timer or another lower, change of temperature state.
Here is what i have come up with seems somewhat spotty performance
int pin;
I have a button with an assigned pin of V20. when an over temperature occurs it turns on the button and send a text message. If the condition changes lower to higher again it wont send a message. If you acknowledge the first page by pressing the button… the button goes off and a subsequent message will occur when the condition happens again. Seems to be a long delay between cycles…not sure if it is latency, the blyn mail function timeout or what. I am running on local server.
BLYNK_WRITE(V20)
{
if (param.asInt()){
digitalWrite(pin, HIGH);
} else {
digitalWrite(pin, LOW);
notified =0;
}
}
void loop()
{
if (((s1-s2) > 5) && (notified == 0 )) {
Blynk.virtualWrite(V20, 1);
notified = 1;
Blynk.email("555555555@msg.mycell.com", "Temp Alert", "Temp Above Alarm - Home Farm");
}
I would recommend using a timer loop instead of running in the main void loop()
(and you are missing Blynk.run();
which SHOULD be in the void loop()
Pseudo code for a timed and flagged loop would be like this
- Run the Check Temp loop every 10 min
- If temp is high and flag is clear then set flag and send 1st warning message
- Else if temp is high and flag is set then send 2nd warning message (repeat as necessary with a count of notifications instead of set/clear, if desired)
- Else if temp is low then clear flag
Your manual notification acknowledgement would be the same as you already have.
- Set a BLYNK_WRITE() function on a button to clear the flag if you wish not to receive any more messages.
This way you will get an initial notification followed by a secondary (even different message or receiver) notification until either your temp lowers, or you reach a set limit of notification you wish to send, or a response button triggers the flag to clear… either way the temp scan and notifications, if any, only occur every 10 minutes or whatever you set the interval timer for.
sorry for the short code…omitted a pile on the post… the timer idea is good… going to be used to check for temperature inversions on a farm(upper temp sensor and lower temp sensor) so that windmills can be turned on to take advantage of the inversion. wont be instantaneous temperature swings…
I settled on just one notification but seems my cell provider delays message…
will post a followup…Thank You for your insight…