Problem with Time Input widget

I am working on an IOT project using a Sparkfun ESP8266 with WiFi and Blynk as the smartphone user interface. The app supports a notification time window which I am using the TimeInput widget to support.

I have much of the app working and the time notification is the last thing I need to include. I have searched and read everything I can find and am still unable to make it work. I still don’t understand something. I am trying to read start time and end time from the widget

The included code is what I am using to test the function before I add the code to my base program.

My main problem, I think, is that I don’t know how the call the BLYNK_WRITE function.

Any help would be appreciated very much.

Rick Diederich




 *************************************************************

  App project setup:
    Time Input widget on V12.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "xxxxxxxxxx";
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxx";

String startTime;

BLYNK_CONNECTED(){
 Serial.println("Blynk Connected");
 Serial.println("start: ")+(startTime);
}  

void setup(){
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}

void loop()
{
  Blynk.run();
}


  

BLYNK_WRITE(V12) {
  TimeInputParam t(param);

  // Process start time

  if (t.hasStartTime())
  {
    Serial.println(String("Start: ") +
                   t.getStartHour() + ":" +
                   t.getStartMinute() + ":" +
                   t.getStartSecond());
    startTime = t.getStartHour() + ":";               
  }
  else if (t.isStartSunrise())
  {
    Serial.println("Start at sunrise");
  }
  else if (t.isStartSunset())
  {
    Serial.println("Start at sunset");
  }
  else
  {
    // Do nothing
  }

  // Process stop time

  if (t.hasStopTime())
  {
    Serial.println(String("Stop: ") +
                   t.getStopHour() + ":" +
                   t.getStopMinute() + ":" +
                   t.getStopSecond());
  }
  else if (t.isStopSunrise())
  {
    Serial.println("Stop at sunrise");
  }
  else if (t.isStopSunset())
  {
    Serial.println("Stop at sunset");
  }
  else
  {
    // Do nothing: no stop time was set
  }

  // Process timezone
  // Timezone is already added to start/stop time

  Serial.println(String("Time zone: ") + t.getTZ());

  // Get timezone offset (in seconds)
  Serial.println(String("Time zone offset: ") + t.getTZ_Offset());

  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)

  for (int i = 1; i <= 7; i++) {
    if (t.isWeekdaySelected(i)) {
      Serial.println(String("Day ") + i + " is selected");
    }
  }
  Serial.println();
}

The Time Input Widget calls that function once, after you set the desired times and press OK.

From that time on, the sketch works with that pre-supplied data and reacts at the proper times, repeatedly… or until you change the settings and press OK again, then the function gets called again and works with the updated info.

Here is a good topic all about how that works… with a few examples.

1 Like

Gunner, Thanks very much. Your explanation made this very easy to understand. I appreciate this very much.

This does, however, leave me with the question of how do I read the start and stop time from the Time Input Widget at startup of the code in the ESP8266. I have tested running the code in the BLYNK_READ(V12) when manually changing the time and it works great.

At startup, you can call a sync command and the server will supply the last sent vPin data…

http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynksyncall

And this effectively triggers the BLYNK_WRITE() functions as if done via the App.

Great, thanks a bunch