hello. I wanted explanations this code always worked. But now it happens that when the days of the week are not all flagged are interpreted as all enabled. Is it a bug? It turns out esp 01.0.52
sorry google translator
#define BLYNK_PRINT Serial
#define relePIN 2
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
BlynkTimer timer;
WidgetRTC rtc;
WidgetLED led1(V6);
WidgetLED led2(V7);
WidgetLED led3(V9);
WidgetLED led4(V10);
WidgetLED led5(V11);
WidgetLED led6(V18);
char currentTime[9];
char auth[] = "0";
char ssid[] = "moreno12344";
char pass[] = "lucky123";
char server[] = "blynk-cloud.com";
bool clockSync = false;
const int rele = 2;
int Avvio;
bool isFirstConnect = true;
void setup() {
Serial.begin(9600);
Serial.println();
pinMode(2, OUTPUT);
Blynk.begin(auth, ssid, pass, server);
timer.setInterval(1000L, activetoday);
timer.setInterval(2000L, clockDisplay);
timer.setInterval(20000L, reconnectBlynk);
timer.setInterval(2000L, ledStatus);
}
BLYNK_CONNECTED() {
rtc.begin();
if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;
}
}
void activetoday() {
if (year() != 1970) {
Blynk.syncVirtual(V1); // sync scheduler #1
Blynk.syncVirtual(V2); // sync scheduler #2
Blynk.syncVirtual(V3); // sync scheduler #3
Blynk.syncVirtual(V4); // sync scheduler #4
Blynk.syncVirtual(V5); // sync scheduler #5
}
}
void clockDisplay() { // only needs to be done once after time sync
if ((year() != 1970) && (clockSync == false)) {
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
Serial.println(currentTime);
clockSync = true;
}
}
BLYNK_WRITE(V1) {
TimeInputParam t(param);
int Avvio1;
unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
int dayadjustment = -1;
if (weekday() == 1) {
dayadjustment = 6;
}
if (t.isWeekdaySelected((weekday() + dayadjustment))) {
//Schedule is ACTIVE today
if (nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ) {
led1.on(); // turn on virtual LED
Avvio1 = Avvio = 1;
// Serial.println("Schedule 1 started");
}
if (nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ) {
led1.off(); // turn OFF virtual LED
Avvio = 0;
//Serial.println("Schedule 1 finished");
//Serial.println(Avvio);
}
}
}
BLYNK_WRITE(V2) { // Scheduler #2 Time Input widget
TimeInputParam t(param);
int Avvio1;
unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
int dayadjustment = -1;
if (weekday() == 1) {
dayadjustment = 6;
}
if (t.isWeekdaySelected((weekday() + dayadjustment))) {
//Schedule is ACTIVE today
if (nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ) {
led2.on(); // turn on virtual LED
Avvio1 = Avvio = 1;
// Serial.println("Schedule 2 started");
}
if (nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ) {
led2.off(); // turn OFF virtual LED
Avvio = 0;
// Serial.println("Schedule 2 finished");
//Serial.println(Avvio);
}
}
}
BLYNK_WRITE(V3) { // Scheduler #3 Time Input widget
TimeInputParam t(param);
int Avvio1;
unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
int dayadjustment = -1;
if (weekday() == 1) {
dayadjustment = 6;
}
if (t.isWeekdaySelected((weekday() + dayadjustment))) {
//Schedule is ACTIVE today
if (nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ) {
led3.on(); // turn on virtual LED
Avvio1 = Avvio = 1;
//Serial.println("Schedule 3 started");
}
if (nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ) {
led3.off(); // turn OFF virtual LED
Avvio = 0;
// Serial.println("Schedule 3 finished");
//Serial.println(Avvio);
}
}
}
BLYNK_WRITE(V4) { // Scheduler #4 Time Input widget
TimeInputParam t(param);
int Avvio1;
unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
int dayadjustment = -1;
if (weekday() == 1) {
dayadjustment = 6;
}
if (t.isWeekdaySelected((weekday() + dayadjustment))) {
//Schedule is ACTIVE today
if (nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ) {
led4.on(); // turn on virtual LED
Avvio1 = Avvio = 1;
//Serial.println("Schedule 4 started");
}
if (nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ) {
led4.off(); // turn OFF virtual LED
Avvio = 0;
//Serial.println("Schedule 4 finished");
//Serial.println(Avvio);
}
}
}
BLYNK_WRITE(V5) { // Scheduler #5 Time Input widget
TimeInputParam t(param);
int Avvio1;
unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
int dayadjustment = -1;
if (weekday() == 1) {
dayadjustment = 6;
}
if (t.isWeekdaySelected((weekday() + dayadjustment))) {
//Schedule is ACTIVE today
if (nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ) {
led5.on(); // turn on virtual LED
Avvio1 = Avvio = 1;
// Serial.println("Schedule 5 started");
}
if (nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ) {
led5.off(); // turn OFF virtual LED
Avvio = 0;
// Serial.println("Schedule 5 finished");
//Serial.println(Avvio);
}
}
if (Avvio == 1) {
digitalWrite(rele, 1);
Serial.println(rele);
}
else {
digitalWrite(rele, 0);
Serial.println(rele);
}
}
void ledStatus() {
int ledState;
ledState = digitalRead(rele);
if (ledState == HIGH)
led6.on();
else
led6.off();
}
void reconnectBlynk() {
if (!Blynk.connected()) {
if (Blynk.connect()) {
BLYNK_LOG("Reconnected");
}
else {
BLYNK_LOG("Not reconnected");
}
}
}
BLYNK_WRITE(V8){
if (param.asInt() == 1){
Avvio = 1;
//led6.on();
Blynk.virtualWrite(V8, 1);
}
else{
Avvio = 0;
Blynk.virtualWrite(V8, 0);
}
}
void loop()
{
if
(Blynk.connected()) {
Blynk.run();
}
timer.run();
}