Time Input Sync after drop in connection

t.isWeekdaySelected(x) is an array with seven members, numbered 1-7.

For each member of he array you are trying to find the value (true or false) but you’re trying to use an array called weekday(x) to select each of the members of the t.isWeekdaySelected() array.

t.isWeekdaySelected(weekday(1))
versus
t.isWeekdaySelected(1)

Can you see the difference?

Pete.

:man_facepalming:
I always feel dumb in this forum !!
ok Now changed to

  MonWeekDay = t.isWeekdaySelected(1);// Check if Monday is selected or not (1 = Yes, 0 = No)
  TuesWeekDay = t.isWeekdaySelected(2);
  WedWeekDay = t.isWeekdaySelected(3);
  ThuWeekDay = t.isWeekdaySelected(4);
  FriWeekDay = t.isWeekdaySelected(5);
  SatWeekend = t.isWeekdaySelected(6);
  SunWeekend = t.isWeekdaySelected(7);

I have serial print out put as selected in the app

[760515] Time sync: OK
Wed V1

if i select multiple days it will reflect on the serial monitor…
But the problem is if i set the time and select monday it will trigger the function even though today is saturday :roll_eyes:

EDIT
Because as soon as i select Mon in the app it will send 1 and the condition is met. So the function will be triggered !! :man_facepalming:

Is there a way to trigger only on selected days ?

Your void checkdays function contains a three if/else pairs, and a stand-alone if statement.

Take a look at this if/else pair…

  if (MonWeekDay == 1) {
    Serial.println("Mon Selected");
  } else if (TuesWeekDay == 1) {
    Serial.println("Tue Selected");

If just Monday or just Tuesday we’re selected then the correct result would be printed to the serial monitor.
However, if both Monday and Tuesday were selected then only Monday would print to the serial monitor.

If you had 7 single if statements then the correct results would be printed in the serial monitor.

However, you don’t currently have any functionality to use these Boolean values in any sensible way (other than printing something to the serial monitor).

Also, you don’t have to use the “==1” bit of the if statement. Simply saying if (logical test) is enough.

I’d write the statement like this…

void checkdays() 
{
  if (MonWeekDay) 
  {
     Serial.println("Mon Selected");
  }

  if (TuesWeekDay) 
  {
     Serial.println("Tue Selected");
  }

  if (WedWeekDay) 
  {
     Serial.println("Wed Selected");
  }

  if (ThuWeekDay) 
  {
     Serial.println("Thu Selected");
  }

  if (FriWeekDay) 
  {
     Serial.println("Fri Selected");
  }

  if (SatWeekend)
  {
     Serial.println("Sat Selected");
  }

  if (SunWeekend)
  {
     Serial.println("Sun Selected");
  }
}

Pete.

Yes this did not work… so i changed to

if (MonWeekDay == 1) {
     Serial.println("Mon V1");
  } else {
  Serial.println("Nothing to do mon");

But the problem is as soon as we select the day required on the app it sends 1 and the condition will be met… if the app had sent 1 only at ex: 12:00AM of monday then it would have worked as i am thinking !! But now it sends 1 as soon i select the day !!

I don’t have time to stay here for longer to read and understand this thread, but I’ve experienced long time ago some thing similar to this.
This is a snippet of code, can you look at it to see if there anything similar to what you’re looking for.


int isTimeInputActivated(const unsigned int scheduleNo, int &lastAction, const TimeInputParam t)
{
  int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60) + t.getStartSecond();  
  int stopseconds  = (t.getStopHour() * 3600) + (t.getStopMinute() * 60) + t.getStopSecond();

  //In case of inactive timer 
  if (startseconds == stopseconds)
    return DO_NOTHING;
    
  int retVal = DO_NOTHING;
  int nowseconds   = ((hour() * 3600) + (minute() * 60) + second());

  int blynkWeekDay = weekday();
  
  if(blynkWeekDay == 1)
    blynkWeekDay = 7; // needed for Sunday Time library is day 1 and Blynk is day 7
  else
    blynkWeekDay--;
    
  if (t.isWeekdaySelected(blynkWeekDay))  
  { 
    //Time library starts week on Sunday, Blynk on Monday  
    //Schedule is ACTIVE today 
    if ((lastAction != TURN_ON) && (nowseconds >= (startseconds - (BLYNK_SCHEDULE_ACCURACY + 1)) && nowseconds <= (startseconds + BLYNK_SCHEDULE_ACCURACY)))
    { 
      #if (DEBUG_BLYNK_RTC > 0)  
        sprintf(activatedTime, "%s %02d/%02d/%04d", dayOfWeek[weekday()-1], day(), month(), year());              
        Serial.printf("Schedule %d started at %s on %s\n", scheduleNo, currentTimeAM_PM(currentTime), activatedTime);
      #endif
      retVal = TURN_ON;
      
      #if (DEBUG_BLYNK_RTC > 1)
        Serial.printf("Last Action = %s, Action = %s, Now = %d, startsec = %d, stopsec = %d\n", 
                      lastActionStr[lastAction], lastActionStr[retVal], nowseconds, startseconds, stopseconds);
      #endif        
    }
                      
    if ((lastAction != TURN_OFF) && (nowseconds >= (stopseconds - (BLYNK_SCHEDULE_ACCURACY + 1)) && nowseconds <= (stopseconds + BLYNK_SCHEDULE_ACCURACY)))
    {   
      #if (DEBUG_BLYNK_RTC > 0)
        sprintf(activatedTime, "%s %02d/%02d/%04d", dayOfWeek[weekday()-1], day(), month(), year());     
        Serial.printf("Schedule %d stopped at %s on %s\n", scheduleNo, currentTimeAM_PM(currentTime), activatedTime);
      #endif
      //If both startSeconds and stopSeconds falls in the same 2 * (BLYNK_SCHEDULE_ACCURACY) range, DO_NOTHING
      if (retVal == TURN_ON)
        retVal = DO_NOTHING;
      else
        retVal = TURN_OFF;
      #if (DEBUG_BLYNK_RTC > 1)
        Serial.printf("Last Action = %s, Action = %s, Now = %d, startsec = %d, stopsec = %d\n", 
                      lastActionStr[lastAction], lastActionStr[retVal], nowseconds, startseconds, stopseconds);        
      #endif        
    }
    
    if (retVal != DO_NOTHING)
      lastAction = retVal;                   
  }
    
  return retVal;  
}

If necessary, I’ll put the full code on GitHub later.

@khoih
Actually i need to trigger a function only on say mon, wed and sun… but it will trigger the function as soon the time has arrived… Because the app has already sent 1 and the if condition is met… This is the problem…

You seem to be saying that the app sends data, triggering the BLYNK_WRITE(V1) callback, as soon as a day is selected in the app.
I can’t reproduce this in either the iOS or Android versions of the app. For me, the data is only sent when the OK button in the Set the time toolbar is pressed.

Your current code is simply printing-out which days have been selected. No test of whether the start or optional end time has been met, or whether the current day is an active day is being done within your code. This is what I was saying earlier.
You need to add to the logic that you’re using and compare the current time and day number values from the RTC widget with the start and end time values and active day values that you’ve received from the time input widget.
The Time Input widget doesn’t do this for you, it’s simply a method to allow the user to select active days and start/stop times. You need to do the rest in your code, but you don’t currently have any code to do that. Your existing code simply prints out which active days have been selected.

Pete.

Yes as i mentioned earlier, if i get this day selecting business done then later i will add an digital write function after the condition is met…

I mean the same… Once the day and time as been set we press ok… So the app will send 1 for selecting monday… But today will be sunday, and our condition is only to proceed if if (MonWeekDay == 1) but as the app has already sent 1 after pressing “ok” the condition is met. If the app had sent 1 on monday itself then this problem wouldn’t have arrived…

Is there a way to track what day is today from RTC widget ? just like we do with the time !!

:point_down:

once i get this right!! then a function can be called

When you press OK in the app, all of the parameters are updated on the Blynk server and the BLYNK_WRITE(V1) callback is triggered. You can then read the required parameters within your code.
The server doesn’t just send a random “1” as you’ve described.

I think you need to study and understand the documentation for the Time Input widget and the RTC widget, as well as reading-up on the Time library.

I’m leaving you to it on this topic, as you appear to what it all to work without adding to the code, but that will never work.

Pete.

If you search ezy scheduler you will find some very good examples of how to use the time input widget with the rtc

I have not said it throws random “1” anywhere. May be my bad English!!!

Again i am no where saying I am strictly adding no code , everything should work by itself…

‘ if (t.isWeekdaySelected((weekday() + dayadjustment))) { …} ‘ (No back ticks available on my phone :face_with_monocle:

This will do the trick…Now i get “1” only if i select monday and today is also monday. But what is was saying was just an idea what i was saying earlier…

Before learning coding i need to go for English speaking and communication course probably :face_with_monocle: