hey, i managed to find the code but it is not working,
this is the code i have used … please check it out
********** code starts *********
char auth[] = “";
char ssid[]="”;
char pass[]="*****";
char Date[16];
char Time[16];
long startsecondswd; // weekday start time in seconds
long stopsecondswd; // weekday stop time in seconds
long nowseconds; // time now in seconds
int btnpin;
SimpleTimer timer;
WidgetRTC rtc;
BLYNK_ATTACH_WIDGET(rtc, V0);
void setup()
{
Serial.begin(9600);
pinMode(16,OUTPUT);
Blynk.begin(auth,ssid,pass);
Blynk.notify(“connected successfully”);
Serial.print(“done”);
rtc.begin();
timer.setInterval(60000L, activetoday); // check every minute if schedule should run today
timer.setInterval(30000L, reconnectBlynk); // check every 30s if still connected to server
}
void activetoday(){ // check if schedule should run today
if(year() != 1970){
Blynk.syncVirtual(V1); // sync timeinput widget
}
}
BLYNK_WRITE(V1) {
TimeInputParam t(param);
Serial.print("Checked schedule at: ");
Serial.println(Time);
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
Serial.println(“Schedule ACTIVE today”);
if (t.hasStartTime()) // Process start time
{
Serial.println(String("Start: ") + t.getStartHour() + “:” + t.getStartMinute());
}
if (t.hasStopTime()) // Process stop time
{
Serial.println(String("Stop : ") + t.getStopHour() + “:” + t.getStopMinute());
}
// Display timezone details, for information purposes only
Serial.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time
Serial.println(String("Time zone offset: ") + t.getTZ_Offset()); // Get timezone offset (in seconds)
for (int i = 1; i <= 7; i++) { // Process weekdays (1. Mon, 2. Tue, 3. Wed, …)
if (t.isWeekdaySelected(i)) {
Serial.println(String("Day “) + i + " is selected”);
}
}
nowseconds = ((hour() * 3600) + (minute() * 60) + second());
startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
//Serial.println(startsecondswd); // used for debugging
if(nowseconds >= startsecondswd){
Serial.println(String(" ") + t.getStartHour() + “:” + t.getStartMinute());
if(nowseconds <= startsecondswd + 90){ // 90s on 60s timer ensures 1 trigger command is sent
digitalWrite(16, HIGH);
Blynk.virtualWrite(V2,1);
// code here to switch the relay ON
}
}
else{
Serial.println(“relay not on”);
// nothing more to do here, waiting for relay to be turned on later today
}
stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
//Serial.println(stopsecondswd); // used for debugging
if(nowseconds >= stopsecondswd){
Serial.println(String(" ") + t.getStopHour() + “:” + t.getStopMinute());
if(nowseconds <= stopsecondswd + 90){ // 90s on 60s timer ensures 1 trigger command is sent
digitalWrite(16, LOW); //
Blynk.virtualWrite(V2,0);
// code here to switch the relay OFF
}
}
else{
if(nowseconds >= startsecondswd){ // only show relay has already started today
Serial.println(“relay is still ON”);
// nothing more to do here, waiting for motor to be turned off later today
}
}
}
else{
Serial.println(“Schedule INACTIVE today”);
// nothing to do today, check again in 1 minutes time
}
Serial.println();
}
void reconnectBlynk() {
if (!Blynk.connected()) {
if(Blynk.connect()) {
BLYNK_LOG(“Reconnected”);
} else {
BLYNK_LOG(“Not reconnected”);
}
}
}
BLYNK_WRITE(V2) {
btnpin=param.asInt();
digitalWrite(16,btnpin);
}
void loop()
{
if (Blynk.connected()) {
Blynk.run();
}
timer.run();
}
`