Time Input widget not working as expected

Hi all,

I’m trying to create a POC using the Time Input Widget (on V10) to set V1 to 0 or 1.

Can anyone help me work out why V1 isn’t being updated?

The majority of the code below is copied and pasted from the examples.

Thanks

WidgetRTC rtc;

String currentDate;
String currentTime;
String startTime;
String stopTime;

void setup(){
  Blynk.begin(auth, ssid);
  Blynk.syncVirtual(V10);
}

void loop(){
  Blynk.run();

  currentTime = String(hour()) + ":" + minute() + ":" + second();
  currentDate = String(day()) + " " + month() + " " + year();


if (currentTime == startTime){
  Blynk.virtualWrite(V1, 1);
}
else if (currentTime == stopTime){
  Blynk.virtualWrite(V1, 0);
}

}//loop


BLYNK_WRITE(V10) {
  TimeInputParam t(param);

  if (t.hasStartTime())  {
    startTime = String(t.getStartHour())  + ":" + t.getStartMinute()  + ":" + t.getStartSecond();
  }

  else{
    // Do nothing
  }

  if (t.hasStopTime()){
    stopTime = String(t.getStopHour()) + ":" + t.getStopMinute() + ":" + t.getStopSecond();
  }

  else{
    // Do nothing: no stop time was set
  }

}

2 things, try moving your sync out of the setup, as you may call it before your device has been connected to the cloud, like this:

BLYNK_CONNECTED() {
Blynk.syncVirtual(V10);
}

Second, comparing ‘String’ as you’re doing is relying heavily on luck as you’re comparing seconds and it may not exactly match. You may want to convert everything to seconds and then compare the number, not the string.