First of all, your notification and email code needs to be executed when the device is connected to Blynk. As this only occurs when your send_to_Blynk function is executed, this is where your notification and email code should go.
I’m not sure why you’ve added a non-blocking timeout timer between the notification and email, it serves no purpose.
Also, the way that your notification code is written, you’ll get a notification and email every 3 minutes while the alarm condition exists.
You really need to add a flag which indicates that a notification has been sent for that alarm condition then don’t send another notification until the alarm condition has been cleared.
More on that here (this is written for Blynk IoT, which does notifications in a very different way, but the flag variable process is exactly the same)…
Secondly, your sketch is now very difficult to follow, especially when it comes to your if
statements, as you’ve not followed any sort of formatting protocol when it comes to indenting your code. If you take a look at the code examples I provided, you’ll see that it’s easy which if
statements are nested inside each other, and which are free standing.
But, your indents are all over the place with your other code too, which makes it extremely difficult to read.
Also, I’m not clear from this comment…
whether you’re referring to your LCD display, or the Blynk app, or both. Also, you’ve not really confirmed that this functionality worked as required before your code changes. Did you do sufficient testing to prove that it worked as required before making your changes?
Pete.