Dayadjustment

hi !

I’m having an issue each Sundays :smile:

my serial monitor :
sunday
ayadjustment 6

Exception (28):
epc1=0x40211674 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000
ctx: cont 
sp: 3ffffcc0 end: 3fffffd0 offset: 01a0
>>>stack>>>
3ffffe60:  00000000 00000000 4bc6a7f0 00000000  
3ffffe70:  3ffefcd8 00000001 4010682c 00027e73  
3ffffe80:  00000000 3ffffee0 3ffffee0 4020ea3f  

now, I 'm sure it is only when dayadjustment= 6

BLYNK_WRITE(V100) {   // Scheduler #1 Time Input widget
   if (weekday() == 1) {
    dayadjustment =  6; // needed for Sunday, Time library is day 1 and Blynk is day 7
    Serial.println("sunday");
    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))) {
    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
  }
}

same issue with

if (t.isWeekdaySelected((7))) {
    if (nowseconds >= startseconds && nowseconds <= stopseconds) {
      Timer1 = true;
      Blynk.virtualWrite(V114, 255);  // turn on virtual LED

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:

t.isWeekdaySelected((weekday() + dayadjustment) = 2+6 = Crash.

1 Like

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.

@ldb

the same issue if I use “7” instead of weekday

if (t.isWeekdaySelected(7)) {

Well hard to tell. I use somthing very similiar and works fine.

If you do something like:

if (t.isWeekdaySelected(7))  serial.println("I'll print");

does it crash? It may be crashing somewhere else.

I’ll try now , give me 5 minutes :smile:

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
:smile:

thank you @Gunner
it is more readable now
:wink:

I was going to try running it through the stack trace decoder… but I can’t figure out how to run the decoder :stuck_out_tongue:

1 Like

Maybe the map() function would be a better way of translating time library days into Blynk days, or vice versatility?

Pete.

1 Like

very interresting tool but I think I’m a noob :smile:
15-024520

1 Like

Please see:

  /// TimeLib format 1 = Sun . 2 = Mon . 3 = Tue . 4 = Wed . 5 = Thu . 6 = Fri . 7 = Sat ///
  /// Blynk is       1 = Mon . 2 = Tue . 3 = Wed . 4 = Thu . 5 = Fri . 6 = Sat . 7 = Sun ///
int dayadjustment = -1;
 if(weekday() == 1){
  dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
  }
  if(t.isWeekdaySelected((weekday() + dayadjustment))){  //Time library starts week on Sunday, Blynk on Monday
...

alternatively you can use:

char* WeekDays[8]={"Not", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; /// TimeLib format 1 = Sun, 2 = Mon ... ///
1 Like

thanks @PeteKnight
but how can I use map() function with time library ?
I have no issue with the real time

15-024521

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.

Pete.

1 Like

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 guess WidgetRTC can not support this function :face_with_raised_eyebrow:

I change blynk server date to sunday 14 :smile:

17:57:29.421 -> weekday 1
17:57:29.421 -> sunday
17:57:29.421 -> dayadjustment  6
17:57:29.455 -> weekday  + dayadjustment  7
activetoday1

17:57:29.901 -> Exception (28):
17:57:29.901 -> epc1=0x402116ac epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000004 depc=0x00000000
17:57:29.901 -> 
17:57:29.901 -> ctx: cont 
17:57:29.901 -> sp: 3ffffcc0 end: 3fffffd0 offset: 01a0
17:57:29.901 -> 
17:57:29.901 -> >>>stack>>>
17:57:29.901 -> 3ffffe60:  00000000 00000000 4bc6a7f0 00000000  
17:57:29.935 -> 3ffffe70:  3ffefcf8 00000001 4010682c 00016c67  
17:57:29.935 -> 3ffffe80:  00000000 3ffffee0 3ffffee0 4020ea77

I went around the problem,
since Saturday and Sunday is the weekend,
Sunday will be day 6 too :smile:
I don’t care, but if anyone can explain to me why there is a problem with sunday, please do …

if (weekday() == 1) {
    dayadjustment =  5; 
    }

Please give us a code snippet to see how this can be implemented. Thanks.

thank you @mikekgr
let me tell you that this skech run from monday to saterday , and crash a 0h01 on sunday :wink:
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
  }
}