Your sketch makes no sense to me.
It might make slightly more sense if you explained what type of widget was attached to each of the virtual pins, and what the operational function of that widget was meant to be.
I certainly can’t understand what you’re doing with the warnPin
variable as it’s value is set by whatever is attached to V1 and it’s then used to define which virtual datastream has a 0 written to it in this piece of code…
It then seems to be used in this function (which I’ve changed the formatting on so that I can make some sense of it) as the switch which turns notifications on and off…
void buttonLedWidget()
{
// Read button
// If state has changed... NOT CORRECT!!
if (digitalRead(doorPin) == HIGH)
{
lcd.print(0,0, "Porte Gar Fermee"); garage door closed
tick++;
}
else
{
lcd.print(0,0, "Porte Gar Ouvert"); garage door opened
tick = 0;
Blynk.virtualWrite(warnPin, LOW);
}
if (tick > warnThreshold)
{
if (warnPin == HIGH) // if Send Notifications widget is On?
{
Blynk.logEvent("test3");
//Blynk.notify("LE GARAGE EST OUVERT!")
tick = (tick - 500);
}
}
Blynk.virtualWrite(V2, tick);
}
As far as the code regarding sending notifications is concerned, you appear to be doing exactly the opposite of what you’ve described here…
There is no change detection for digital pin 2 (doorPin) and your tick
counter is being incremented by 1 only when the garage door is closed (doorPin == HIGH).
As the (oddly named) buttonLedWidget()
function is called once every second, and warnThreshold
is initially set to 100, the first notification will be sent when the garage door has been closed for 100 seconds and subsequent notifications will be sent every 500 seconds.
This means that your 500 events per 24 hour period will be used-up when your garage door is closed for around 83 minutes.
I suspect that when you say “events” you actually mean Notifications.
Blynk has two limits, 100 EVENTS per 24 hour period and 100 NOTIFICATIONS per 24 hour period.
As notifications are triggered by events, then this seems to imply that there is a one to one relationship between the two, but there is a setting in the Event Notifications tab which allows you to say how many events are ignored before a notification is sent.
I’d suggest that you read this tutorial…
Then wait 24 hours before powering-up your device again and turn-on the “Send event to timeline” option and check the Notificatiins Limit period is set to 1 minute and the Event Counter is set to 1
Pete.