Hi all,
I am a new blynk user here trying to use the time input function to set like a certain time duration/range to turn on a LED. I have succeeded in doing this with the LED turning on in a certain day and time and close when it is supposed to, but now I noticed that when no days are selected in blynk app it will turn all of the days into selected days. Is this the normal behavior of the time input widget ? and if so how do I change it so that if no days are selected then it wont turn on the LED?
Here is the attached code where I test for no days selected:
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "*"
#define BLYNK_TEMPLATE_NAME "*"
#define BLYNK_AUTH_TOKEN "*"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <TimeLib.h> // For time functions
BlynkTimer timer;
char ssid[] = "*"; // Wifi SSID
char pass[] = "*"; // Wifi password
bool isTimeSynced = false; // Flag to check time synchronization
// Request time sync from Blynk server
BLYNK_CONNECTED() {
Serial.println("Device connected to Blynk server, requesting time sync...");
Blynk.sendInternal("rtc", "sync");
isTimeSynced = false; // Reset the flag to check for new sync
}
BLYNK_WRITE(InternalPinRTC) { //check the value of InternalPinRTC
long t = param.asLong(); //store time in t variable
Serial.print("Unix time: ");
Serial.print(t); //prints time in UNIX format to Serial Monitor
Serial.println();
}
// Callback for Time Input widget
BLYNK_WRITE(V14) {
TimeInputParam t(param);
// Check for start and stop times
if (t.hasStartTime()) {
Serial.println(String("Start: ") + t.getStartHour() + ":" +
t.getStartMinute() + ":" + t.getStartSecond());
}
if (t.hasStopTime()) {
Serial.println(String("Stop: ") + t.getStopHour() + ":" +
t.getStopMinute() + ":" + t.getStopSecond());
}
// Timezone information
Serial.println(String("Time zone: ") + t.getTZ());
Serial.println(String("Time zone offset: ") + t.getTZ_Offset());
// Weekday selection
for (int i = 1; i <= 7; i++) {
if (t.isWeekdaySelected(i)) {
Serial.println(String("Day ") + i + " is selected");
}
}
Serial.println();
}
// Check if the RTC time has been synchronized
void setup() {
// Debug console
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
Blynk.run();
timer.run();
}
and this is the serial monitor display when no days are selected:
Start: 2:8:0
Stop: 21:1:0
Time zone: Asia/Kuala_Lumpur
Time zone offset: 28800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Day 6 is selected
Day 7 is selected
Cheers and Thanks!