Hello !
I am using time input widget to set start and stop time. Everything works fine.
The problem is -
Lets assume i have set the time for turning on a relay and during this time the internet was ok.
Later if the internet goes down then obviously the relay doesnt turn on due to lack of internet.
Now, once the internet is back the module doesnt turn on once it is connected. It remains OFF.
This happens the other way around too !!
if the relay has been turned on with in the set time and then, if the internet goes down and comes back online after the stop time has been passed ! Then the relay will stay ON the whole time…
Is there a way to read the Time Input widgets (virtual pin) value stored on the cloud server and accordingly turn on\off the relay ?? (I think the widget throws 1 and 0 at start and stop )
I have no problem reconnecting to the blynk cloud after the internet is back again.
I think i have failed to explain , I will give one more try…
Ex : Start time 11:00 AM - Stop time 2:00PM (Time the relay should turn on and off)
Now lets say the relay turned on at 11:00AM and waits to turn back off at 2:00PM, unfortunately the internet goes down at 1:50PM . So now the relay will remain ON due to lack of internet !
At 2:15PM the internet is back online !! And the device reconnects to blynk cloud no issues. But the relay will remain in the ON state… I will not turn OFF… It will turn off only at 2:00PM the next day if the internet is okay !!
Is there a way to know whether the time has passed and turn the relay OFF ?? by getting the value from the server ??
Thanks,
I understood your first explanation. I am not a very good coder, actually my coding sucks… but the idea should work.
If you use @PeteKnight 's suggestion and use the timer to resync at certain intervals…
Not sure if this is correct?
BLYNK_CONNECTED()
{
//Blynk.syncAll(); //synchronize the state of widgets with hardware states
//Blynk.syncVirtual(V0); //synchronize the state of virtual pins
//Blynk.syncVirtual(V0,600000L); // every 10 min
Blynk.syncVirtual(V0,1800000L); //every 30 min
}
Use the server as the timer (timer widget) for your relay… to switch a widget led on and off - led controls the relay.
So if the internet is on again, blynk should sync your relay with the state of the led.
Another way is take the times you set and make a comparison to actual time so when internet reconnects a comparison with actual time is carried out to determine if the relay should be on or off
Hello !!
For this we need to have any RTC right like DS3231 ? Only then we can compare like you said !! Correct me if i am wrong !! Because everything is working on the server side and when no connection is available then there is data to compare right ???
void SetLed(int pin,
unsigned long time, //Current time in millis
unsigned long start, //Start time of LED channel
unsigned long fadeup, //Fadeup period in millis
unsigned long period, //Total photo period
unsigned long fadedown, //Fadedown period in millis
unsigned long stop, //Stop time of LED channel
float pwm, //Max value of brightness
int Vpin) //ProgressBar
{
//ON PERIOD//
if (time > start + fadeup && time <= start + period - fadedown)
{
analogWrite(pin, pwm);
int progress = round((pwm*100)/1023);
Blynk.virtualWrite (Vpin, progress);
}
//FADEUP PERIOD//
else if (time > start && time <= start + fadeup)
{
float brightness;
brightness = map(time - start, 0, fadeup, 0, pwm);
analogWrite(pin, brightness);
int progress = round((brightness*100)/1023);
Blynk.virtualWrite (Vpin, progress);
}
//FADEDOWN PERIOD//
else if (time > start + period - fadedown && time <= start + period)
{
float brightness;
brightness = map(time - start - period + fadedown, 0, fadedown, pwm, 0);
analogWrite(pin, brightness);
int progress = round((brightness*100)/1023);
Blynk.virtualWrite (Vpin, progress);
}
//OFF PERIOD//
else if (time > stop || time < start)
{
analogWrite(pin, 0);
Blynk.virtualWrite(Vpin, 0);
}
}
I didn’t suggest that a timer should be used to trigger the Blynk.syncVirtual call(s).
The way to do it is to use the BLYNK_CONNECTED callback function to trigger the synchronisation whenever the device reconnects to Blynk.
Hello !!
I firstly dont know whether to ask this doubt\problem here or create a new topic, but as this related to Time input widget i feel i can post this here… if not please tell me i will create a new topic …
The problem is i am trying to read the t.isWeekdaySelected out side the BLYNK_WRITE function. TimeInputParam t(param); as this can only be called inside BLYNK_WRITE… As i am not a coder i think i have failed to explain properly, But i want to see the days selected in a void function…
BLYNK_WRITE(V1) { // Called whenever setting Time Input Widget
TimeInputParam t(param);
Mon = t.isWeekdaySelected(weekday(1)); // Check if Monday is selected or not (1 = Yes, 0 = No)
Tues = t.isWeekdaySelected(weekday(2));
Wed = t.isWeekdaySelected(weekday(3));
Thu = t.isWeekdaySelected(weekday(4));
Fri = t.isWeekdaySelected(weekday(5));
Sat = t.isWeekdaySelected(weekday(6));
Sun = t.isWeekdaySelected(weekday(7));
}
Later checking if the days are selected
void checkdays1() {
if (Mon == 1) {
TimeCheck1();
} else if (Tues == 1) {
TimeCheck1();
} if (Wed == 1) {
TimeCheck1();
} else if (Thu == 1) {
TimeCheck1();
} if (Fri == 1) {
TimeCheck1();
} else if (Sat == 1) {
TimeCheck1();
} if (Sun == 1) {
TimeCheck1();
}
}
Every things seems to work properly !! But when i select only a single day ex: Sat… I does not trigger the event… But if a select Fri , Sat, Sun then it will trigger…
I’d start by putting some serial print statements in your code, so that you can see the value of your variables and monitor the program flow through the if/else statements.