RF 433 Mhz on virtual pin doesn't want to send (with scheduling)

@distans I recently revamped my scheduling code to make it easier to add more schedules i.e. variables are all local now so you can simply copy the function over and over again, plus a minor mod to one other function.

Test the following sketch with 2 schedulers and once you now it works incorporate into your project.

/****************************************************************************** 
  EziScheduler.ino   by Costas, 7 Sept 2017
  Scheduler with Time Input and obligatory OTA update facility for ESP's
  RTC widget (no pin allocation)
  LED V0
  Time Input V1
  Time Input V2
  To add more schedules simply copy BLYNK_WRITE(V1) function and change V1 to V3
  and in activetoday() function add: Blynk.syncVirtual(V3); // sync scheduler #3 
*******************************************************************************/
#define BLYNK_PRINT Serial 
#include <ArduinoOTA.h>             
#include <ESP8266WiFi.h>        
#include <BlynkSimpleEsp8266.h> 
BlynkTimer timer;

#include <TimeLib.h>
#include <WidgetRTC.h>
WidgetRTC rtc;
char currentTime[9];

char auth[]   = "**************"; 
char ssid[]   = "GargoyleTest";                     
char pass[]   = "**************";                     
char server[] = "blynk-cloud.com"; 
bool clockSync = false;    

void setup() {
  Serial.begin(115200);
  Serial.println();
  Blynk.begin(auth, ssid, pass, server);
  ArduinoOTA.setHostname("EziScheduler");       
  ArduinoOTA.begin();    
  timer.setInterval(60000L, activetoday);  // check every 60s if ON / OFF trigger time has been reached
  timer.setInterval(1000L, clockDisplay);  // check every second if time has been obtained from the server
}

BLYNK_CONNECTED() {
  rtc.begin();
}

void activetoday(){         // check if schedule #1 or #2 should run today
  if(year() != 1970){
    Blynk.syncVirtual(V1);  // sync scheduler #1
    Blynk.syncVirtual(V2);  // sync scheduler #2   
  }
}

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) {   // Scheduler #1 Time Input widget  
  TimeInputParam t(param);
  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; // needed for Sunday Time library is day 1 and Blynk is day 7
  }
  if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday  
    //Schedule is ACTIVE today 
    if(nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ){    // 62s on 60s timer ensures 1 trigger command is sent
      Blynk.virtualWrite(V0, 255);  // turn on virtual LED
      Serial.println("Schedule 1 started");
    }                  
    if(nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ){   // 62s on 60s timer ensures 1 trigger command is sent
      Blynk.virtualWrite(V0, 0);   // turn OFF virtual LED
      Serial.println("Schedule 1 finished");
    }               
  }
}

BLYNK_WRITE(V2) {   // Scheduler #2 Time Input widget  
  TimeInputParam t(param);
  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; // needed for Sunday Time library is day 1 and Blynk is day 7
  }
  if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday  
    //Schedule is ACTIVE today 
    if(nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ){    // 62s on 60s timer ensures 1 trigger command is sent
      Blynk.virtualWrite(V0, 255);  // turn on virtual LED
      Serial.println("Schedule 2 started");
    }                  
    if(nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ){   // 62s on 60s timer ensures 1 trigger command is sent
      Blynk.virtualWrite(V0, 0);    // turn OFF virtual LED
      Serial.println("Schedule 2 finished");
    }              
  }
}

void loop() {
  if(Blynk.connected()){ 
    Blynk.run();        
  }                     
  ArduinoOTA.handle(); 
  timer.run();
}
1 Like