Below I have wrote a short code to check if there is any activity today.
For testing, I insert weekday 4 (Thursday). I can see the correct weekday is selected in Timeinput Widget.
The output value continuesly say 5 when do line Serial.println(weekday());
Why can’t I compare actally weekday with Blynk selected weekday?
BLYNK_WRITE(V2) // Read timer value and check
{
TimeInputParam t(param);
for (int i = 1; i <= 7; i++)
{
if (t.isWeekdaySelected(i))
{
Serial.println(String("Day ") + i + " is selected");
Serial.println(weekday());
}
}
if (weekday() == 4)
{
Serial.println("Activity today!");
}
}
@SCH Blynk days of the week are different to the rest of the world.
Fix:
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
// etc
Thanks, I know the issue about Sunday adjustment. But this is not the problem.
The problem is, I do not get current weekday. If today is Monday (weekday 1).
Line in code: Serial.println (weekday()); shows output 5. Same for Saturday and Sunday, is output = 5.
I think it hs nothing todo with Android, because I got the values correct from Arduino.
This code below, output correct weekday as String, but not at Int.
I want to compare actal weekday with Blynk selected weekday.
BLYNK_WRITE(V2) // Read timer value and check
{
TimeInputParam t(param);
String td;
for (int i = 1; i <= 7; i++)
{
if (t.isWeekdaySelected(i))
{
Serial.println(String("Day ") + i + " is selected");
td = (dayStr(weekday()));
Serial.println(td);
Serial.println(dayStr(weekday()));
}
}
if (td == "Thursday")
{
Serial.println("Activity today!");
}
}
I have been doing some scheduling from a friend recently and when I include your code Serial Monitor now looks like this with 6 Time Input widgets:
13:27:21
Day 1 is selected
5
Day 2 is selected
5
Day 3 is selected
5
Day 4 is selected
5
Day 5 is selected
5
Day 6 is selected
5
Day 7 is selected
5
Sch2 is active today 48441 82500 82560
Sch3 is active today 48441 82620 82680
Sch4 is active today 48441 82740 82800
Sch5 is active today 48441 82860 82920
Sch6 is active today 48441 82980 83040
13:27:31
Day 1 is selected
5
Day 2 is selected
5
Day 3 is selected
5
Day 4 is selected
5
Day 5 is selected
5
Day 6 is selected
5
Day 7 is selected
5
Actually day 5 looks to be fine i.e. the day number allocated to Thursday for most time libraires, but not Blynk’s. Not sure I see a problem when you do the day adjustment hack.
I have done a new test as my code below:
If I select all weekdays (colored) in Widget. it print out from Monday to Sunday, it’s OK.
If I deselect all, it still print out all weekdays.
If I select one or two weekdays, it print out correct.
Actually I tested a simple code yesterday (Wednesday) and it still output value 5 when using code line:
Serial.println(weekday());
No matter which weekday, the output is 5.
Blynk “designed” it that way, although some might call it a bug.
There is a 2 character library hack to fix that. Have a good search of the site and come back to us if you don’t find the hack.
Thanks, I solved the problem. I realized I have to add the RTC widget to get the correct time.
If no time fixed, you always get weekday 5. Thanks for your help. It works now.
Case closed.
Sorry, what do you mean by “no time fixed”? In my case, I got current time but not current day. Same as you always display value 5 no matter what today is