I am trying to expand the Blynk functionality of an IOT application I am writing. I am trying to use the TimeInputWidget and need to read the associated array variables.
I am starting by prototyping the function using the example included here in the documentation.
When I try using any of the time variables I get an error stating that ‘t’ was not declared in the scope. If I declare a ‘t’ array I get compile errors trying to use any of the array elements.
There is something I am missing in the example and the whole function of reading from the time input widget.
The only change I made to was to support Wifi connection. TimeInputParam t(param);
is in the code right after the BLYNK_WRITE(V12).
And the error message I get is ‘t’ was not declared in this scope.
I don’t know how to include the code the right way so I just cut and pasted it below.
Thanks
Rick
//*************************************************************
App project setup:
Time Input widget on V12.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Wire.h> // required for I2C support
#include <ESP8266WiFi.h> // required for ESP-WiFi support
#include <BlynkSimpleEsp8266.h> // required for Blynk support
const char* authtoken = "myAuthToken";
const char* ssid = "mySSID"; // set wireless network name (SSID)
const char* password = "myPassword"; // set Wi-Fi network password
BLYNK_WRITE(V12) {
TimeInputParam t(param);
// Process start time
if (t.hasStartTime())
{
Serial.println(String("Start: ") +
t.getStartHour() + ":" +
t.getStartMinute() + ":" +
t.getStartSecond());
}
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();
}
void setup()
{
// Debug console
Serial.begin(115200);
Serial.println("hello");
WiFiClient client;
Serial.print("Initalize Wifi and Blynk Interface");
Blynk.begin(authtoken, ssid, password);
Serial.println ("--complete");
Serial.print (" ");
Serial.println ("WiFi connected");
Blynk.syncVirtual(V12);
Serial.println(String("Start: ") + t.getStartHour();
}
void loop()
{
Blynk.run();
}
Because the TimeInputParam t(param) gets provided only within the BLYNK_WRITE(V12) function, when sent by the widget.
As I suggested check out that whole topic about using this widget. One way (probably not the only way) I utilised the time parameters throughout my code was to declare separate global variables and assign them from the param call.
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;
BLYNK_WRITE(V1) { // Called whenver setting Time Input Widget
TimeInputParam t(param);
SThour = t.getStartHour();
STmin = t.getStartMinute();
STsec = t.getStartSecond();
SPhour = t.getStopHour();
SPmin = t.getStopMinute();
SPsec = t.getStopSecond();
}
Thanks a bunch, for your replay and the reading assignment. This has helped me better understand the interface with the TimeInput widget. However, I am still missing something.
My objective in my actual project in to get real-time from the internet so I don’t understand how that relates to RTC in the code and the requirement for the inclusion of the RTC widget although I have included those for testing here.
All in want from the Blynk TimeInput widget is a place to allow a user a place to define a start and stop time. As I am beginning to understand this there is a lot more capability than I realized.
At this point when I run my code all I get in “Start time: 0:0:0”, So I think I am making headway, but I have more to learn.
I am sure thankful for this community and your time to provide this assistance as I learn this TimeInput widget interface. Below is me current code:
/*************************************************************
App project setup:
Time Input widget on V12.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Wire.h> // required for I2C support
#include <ESP8266WiFi.h> // required for ESP-WiFi support
#include <BlynkSimpleEsp8266.h> // required for Blynk support
#include <TimeLib.h> // added per Blynk communitee
#include <WidgetRTC.h> // added per Blynk communitee
// ***** Wi-Fi Settings and Blynk id info *****
const char* ssid = "xxxxxxx"; // set wireless network name (SSID)
const char* password = "xxxxx"; // set Wi-Fi network password
const char* authtoken = "xxxxxxxx";
SimpleTimer timer; // added
WidgetRTC rtc; //added
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;
BLYNK_WRITE(V12) { // Called whenver setting Time Input Widget
TimeInputParam t(param);
SThour = t.getStartHour();
STmin = t.getStartMinute();
STsec = t.getStartSecond();
SPhour = t.getStopHour();
SPmin = t.getStopMinute();
SPsec = t.getStopSecond();
}
void setup()
{
// Debug console
Serial.begin(115200);
Serial.println("hello");
WiFiClient client;
rtc.begin(); //added per Blynk community
Serial.print("Initalize Wifi and Blynk Interface");
Blynk.begin(authtoken, ssid, password);
Serial.println ("--complete");
Serial.print (" ");
Serial.println ("WiFi connected");
Blynk.syncVirtual(V12);
Serial.println(String("Start time: ") + SThour + ":" +
STmin + ":" +
STsec);
}
void loop()
{
Blynk.run();
timer.run();
}
Tthe result is "Start time: 0:0:0:
Thanks
.
Well that is what the RTC Widget, TimeLib.h and other related code does. The Widget is also for keeping the phone in sync timezone wise with the server & device (which generally stays home), in case you are a world traveler.
Well, that it does… however it needs to know the actual time first in order to compare with your start and stop times… thus the RTC
It probably makes sense for me to rethink my design based on the totality of when Blynk does with RTC and date and time in general. Blynk is so much more than a pretty face.
I now am able to read and print the widget data in the loop portion of my code. so I am over that hump based on the all the help you have provided.
Thanks so much, once I get this test code cleaned up I will update this and include a copy of the working code.