Advance time impunt

Hi, I have a problem with my project,
the timer does not go, it only compares with the current time and does not advance. do you have ideas?
for the days of the week I don’t care, it will have to be turned on every day

thank you!!!

#define BLYNK_PRINT Serial   
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

SimpleTimer timer;
WidgetRTC rtc;


char Date[16];
char Time[16];
int manual=0;

char auth[] = "xxxxxxxxxxxx";
char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxx"; 
long startsecondswd;            // weekday start time in seconds
long stopsecondswd;             // weekday stop  time in seconds
long nowseconds;                // time now in seconds
void setup() 
{
  while (Blynk.connect() == false) {     
      // Wait until connected              
    }                                      
  WiFi.mode(WIFI_STA);
  Serial.begin(115200); 
  Blynk.begin(auth, ssid, pass);
  rtc.begin();
  Blynk.virtualWrite(V0, 1);
  delay(10);
  timer.setInterval(100000L, sendWifi);
   timer.setInterval(1000,showCurrentTime);
   timer.setInterval(1000,reconnectBlynk);
}
BLYNK_WRITE(V0) {
  switch (param.asInt())
  {
    case 1: // Item 1
      manual=1;
      break;
    case 2: // Item 2
     manual=0;
      break;
    
   default:
      Serial.println("Unknown item selected");
 }
  }
BLYNK_WRITE(V1)
{  
    if (manual==1)
      { 
      sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
      sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
      TimeInputParam t(param);
      Serial.println(Time);
      Serial.println(Date);    
      nowseconds = ((hour() * 3600) + (minute() * 60) + second());
      startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
     
       Serial.println(nowseconds);
        Serial.println(startsecondswd); 
         if(nowseconds >= startsecondswd){    
               Serial.println("test start");
              
      }
      else
      {
      }
      stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
     
      if(nowseconds >= stopsecondswd){
        
          Serial.println("test stop");
        
        if(nowseconds <= stopsecondswd ){ 
           Serial.println("test stop");
         
        }              
      }
      else{
        if(nowseconds >= startsecondswd){  
          Serial.println("test start");
          }          
      }
   }
}

void showCurrentTime()
{
  String CurrentDate = String(day()) + '-' + monthShortStr(month()) + '-' + year();
   String CurrentTime = String(hour()) + ':' + minute() + ':' + second();
    String formattedDate = CurrentDate + String(" | ") + CurrentTime;
     Blynk.virtualWrite(V3,formattedDate);
}
void reconnectBlynk () { 
if (! Blynk.connected ()) { 
if (Blynk.connect ()) { 
BLYNK_LOG ("Reconnected"); 
} else { 
BLYNK_LOG ("Non riconnessa"); 
} 
} 
}


void sendWifi() 
{
  Blynk.virtualWrite(V4, map(WiFi.RSSI(), 192, 168, 1, 3) );
}
void loop() 
{
  Blynk.run();
  timer.run();
}

You have a habit of posting code without the triple backticks at the beginning and end so that it displays correctly.
I’ve edited your post to correct this, but in future please add the backticks yourself otherwise your code will be deleted.

Pete.

Ok, thank you!

Nobody can help me?

Which timer does not “go”? And what are you wanting to compare?

1 Like

The widget compares the instantaneous moment with the date I entered, the timer does not make subsequent comparisons

I’m still not fully 100% what you are referring to, but \I think it is to do with the code here:

if (manual==1)
      { 
      sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
      sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
      TimeInputParam t(param);
      Serial.println(Time);
      Serial.println(Date);    
      nowseconds = ((hour() * 3600) + (minute() * 60) + second());
      startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
     
       Serial.println(nowseconds);
        Serial.println(startsecondswd); 
         if(nowseconds >= startsecondswd){    
               Serial.println("test start");
              
      }
      else
      {
      }
      stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
     
      if(nowseconds >= stopsecondswd){
        
          Serial.println("test stop");
        
        if(nowseconds <= stopsecondswd ){ 
           Serial.println("test stop");
         
        }              
      }
      else{
        if(nowseconds >= startsecondswd){  
          Serial.println("test start");
          }          
      }
   }

If so, this will only get called once, when V1 changes state etc.

What do you have V1 set to in your app? - If you want to check this more regularly, then you need to move this code to its own function and run it in a timer.

Now i try, thank you very much

1 Like