Hi I am trying to make and advanced time input widget work for a future much larger project. I have base the code on code which was from Costas and Gunner. The problem is the it does not works as it should. It appears from the Serial monitor that it gets stuck at " if (activeToday == true) of function TimeCheck(). Could someone possibly look over my code a point me to my mistake. Much appreciated.
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WidgetRTC.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "68c0c1f4f4e74f5cb561a29cad50b8cd";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
//Time Input Variables
char currentTime[9];
char currentDate[11];
char startTime[9];
char stopTime[9];
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;
int dayNumber;
bool activeToday = false;
bool scheduler = true;
bool schedulerStatusChange = false;
WidgetRTC rtc;
BlynkTimer timer;
BLYNK_WRITE(V10)
{
TimeInputParam t(param);
SThour = t.getStartHour();
STmin = t.getStartMinute();
STsec = t.getStartSecond();
SPhour = t.getStopHour();
SPmin = t.getStopMinute();
SPsec = t.getStopSecond();
activeToday = false;
unsigned int OnDays = 0;
for (int i = 1; i <= 7; i++) // Process weekdays (1-Mon, 2-Tues, 3-Wed, 4-Thurs, 5-Fri, 6-Sat, 7-Sun)
{
if (t.isWeekdaySelected(i))
{
OnDays++;
if(i==dayNumber)
{
activeToday = true;
}
Serial.println(String("Day ") + i + " is selected");
}
}
if (OnDays == 0)
{
scheduler = false;
}
else
{
scheduler = true;
}
if (scheduler != schedulerStatusChange)
{
schedulerStatusChange = scheduler;
}
}
void TimeCheck()
{
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second()); //Get RTC time
Serial.print("Current Time: ");
Serial.println(currentTime);
sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec); //Get start time from widget
Serial.print("Start Time: ");
Serial.println(startTime);
sprintf(stopTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec); //Get stop time from widget
Serial.print("Stop Time: ");
Serial.println(stopTime);
if (activeToday == true)
{
if (hour() == SThour)
{
if (minute() == STmin)
{
Serial.println("Doing something now");
digitalWrite(2, LOW); // Turn ON built-in LED
}
else if (minute() < STmin)
{
Serial.println("Will do something");
}
else if (minute() > STmin)
{
Serial.println("Did something");
}
else
{
Serial.println("Clueless");
}
}
if (hour() == SPhour)
{
if (minute() == SPmin)
{
Serial.println("Stopping something now");
digitalWrite(2, HIGH); // Turn OFF built-in LED
}
else if (minute() < SPmin)
{
Serial.println("Will stop something");
}
else if (minute() > SPmin)
{
Serial.println("Stopped something");
}
else
{
Serial.println("Clueless");
}
}
Serial.println("----------");
}
}
void ClockDisplay()
{
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
sprintf(currentDate, "%02d/%02d/%04d", day(), month(), year());
Blynk.virtualWrite(V0, currentTime); //Send time to TIME widget
Blynk.virtualWrite(V1, currentDate); //Send date to DATE widget
}
BLYNK_CONNECTED() //Connect to Blynk server
{
Blynk.syncAll();
TimeCheck();
}
void setup()
{
// Debug console
Serial.begin(9600);
digitalWrite(2, HIGH);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
rtc.begin();
setSyncInterval(360);
timer.setInterval(1000L, ClockDisplay);
timer.setInterval(30000L, TimeCheck);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}