I believe the problem is here. If your code has been running for more than a week and you don’t have an else statement “zeroing” the dayadjustment… Down the line, lets say the following Monday:
thank you for your help @ldb
it will be right if I never have
if(weekday ()==1)
and I restarted nodemecu 15 times yesterday.
today is Monday, all runs well.
today, there is no issue with t.isWeekdaySelected(7)
I think I have to wait till next sunday and explore where is the bug.
there is necessarily a relationship between t.isWeekdaySelected(7) and the real time clock
You’re using if statements based on the time library plus an adjustment. Rather than doing that, map time library days to Blynk days and base your if statements on Blynk days.
to test the code, I would like to change the RTC date with rtc.setDay (day byte) (Sunday instead of Monday)
unfortunately, I have an error: ‘class WidgetRTC’ does not have a member named ‘setDay’
I went around the problem,
since Saturday and Sunday is the weekend,
Sunday will be day 6 too
I don’t care, but if anyone can explain to me why there is a problem with sunday, please do …
thank you @mikekgr
let me tell you that this skech run from monday to saterday , and crash a 0h01 on sunday
since I decided to modify by :
if (weekday() == 1) {
dayadjustment = 5;
there is no issue.
//**************** TIMER 1 ***********************
BLYNK_WRITE(V100) { // Scheduler #1 Time Input widget
Serial.println("timer1");
Serial.print("weekday ");
Serial.println(weekday());
if (weekday() == 1) {
dayadjustment = 5; // needed for Sunday, Time library is day 1 and Blynk is day 7
Serial.println("sunday");
Serial.print("dayadjustment");
Serial.println(dayadjustment);
}
TimeInputParam t(param);
nowseconds = ((hour() * 3600) + (minute() * 60) + second());
startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
if (t.isWeekdaySelected((weekday() + dayadjustment))) {
Serial.println(weekday() + dayadjustment);
if (nowseconds >= startseconds && nowseconds <= stopseconds) {
Timer1 = true;
Blynk.virtualWrite(V114, 255); // turn on virtual LED
}
else {
Timer1 = false;
Blynk.virtualWrite(V114, 0); // turn OFF virtual LED
}
}
else {
Timer1 = false;
Blynk.virtualWrite(V114, 0); // turn OFF virtual LED
}
}
//**************** TIMER 2 ***********************
BLYNK_WRITE(V102) { // Scheduler #1 Time Input widget
Serial.println("timer2");
TimeInputParam t(param);
nowseconds = ((hour() * 3600) + (minute() * 60) + second());
startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
if (t.isWeekdaySelected((weekday() + dayadjustment))) {
if (nowseconds >= startseconds && nowseconds <= stopseconds) {
Timer2 = true;
Blynk.virtualWrite(V115, 255); // turn on virtual LED
}
else {
Timer2 = false;
Blynk.virtualWrite(V115, 0); // turn OFF virtual LED
}
}
else {
Timer2 = false;
Blynk.virtualWrite(V115, 0); // turn OFF virtual LED
}
}