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();
}