martin-laclaustra / cronalarms Goto Github PK
View Code? Open in Web Editor NEWArduino IDE library for scheduling alarms to occur at specific times with crontab syntax
License: GNU Lesser General Public License v3.0
Arduino IDE library for scheduling alarms to occur at specific times with crontab syntax
License: GNU Lesser General Public License v3.0
Thanks for this very useful library. I think the killer feature would be to read a crontab file (e.g., from the filesystem in a esp8266/esp32), from a https URL, or from a multiline string) in order to be able to change alarms dynamically.
My use case is that I would like to maintain the crontab file in the web, and have the ESP based device fetch that file when it boots.
Coud you consider this feature request?
My use case is that I would like to put certain messages onto a display, as defined in a crontab file hosted on the web:
# Minute Hour DayOfMonth Month DayOfWeek Message
0 7 * * 1-5 Good morning!
0 12 * * * Lunch time!
0 17 * * 1-5 Work day is over!
0 8 1 * * Happy New Month!
0 8 1 1,4,7,10 * Happy New Quarter!
0 0 1 1 * Happy New Year!
When i run CronAlarms_example.ino, is it possible to introduce a non blocking delay function into the function starting on line 93 ?
I am trying to control 4 relays, doing tasks at certain times a day, in intervals. I get time via NTP and create tasks as per the CronAlarms_example.ino file :)
Something like this?
void Repeats() {
Serial.println("15 second timer");
digitalWrite(relayPin04, HIGH);
Cron.delay(relayDelay04);
digitalWrite(relayPin04, LOW);
}
I would like it to run, but not block for other functions to be executed. Iv tried this, but it does not seem to work as how i hoped it would.
Am i doing something wrong or do you have a suggestion about how this could be done?
Thanks for a great project and thanks for your time.
*iv ended up using ESP32TimerInterrupt.h, but if you have a functionmality which actually makes it unnessasary, i would love to hear about it.
Hi, thanks for the library, one really important feature is missing though. I have one global handler for all my cron tasks so I need to know which task is running. Would be great to have it as a parameter.
Thanks in advance!
Please let me know if you need a PR for that
hi i have an Wemos d1 mini v.3.00
I've made a cron to run every 5 minutes.
So i expected output times like
9:45:00
9:50:00
9:55:00
but i get
10:46:44
10:51:44
10:56:45
#include <time.h> // time() ctime()
#ifdef ESP8266
#include <sys/time.h> // struct timeval
#endif
#include "CronAlarms.h"
void setup() {
Serial.begin(115200);
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("Starting setup...");
Cron.create("0 */5 * * * *", Repeats, false);
Serial.println("Ending setup...");
}
void loop() {
delay(1000);// do other things... like waiting one second between clock display
}
void Repeats() {
postData();
}
postData() is sending something to my server.
Thanks already René
I'm getting the Systemtime via NTP on the ESP32.
All cronjobs works just for the first day, it looks like after midnight (date change), the cronjobs stop working.
Do you have a idea where the problem might be?
Should i post some snipped of code here?
Interesting news:
I noticed that the problem described above seems to affect only the first cronjob of the day.
For testing purposes I let a function call 3 times a day at the following times: 07:00am, 07:05am and 07:10am.
The first call is not executed, the other two are.
Enclosed is the code snippet with the call of the functions:
_
Cron.create("0 0 7 * * *", Daily_Report, false); // // 7:00am every day send Daily Report
Cron.create("0 5 7 * * *", Daily_Report, false); // // 7:05am every day send Daily Report ->>>>>>>> just for testing
Cron.create("0 10 7 * * *", Daily_Report, false); // // 7:10am every day send Daily Report ->>>>>>>> just for testing
_
This is my code, it's not in an ino file it's in its own class.
The init is called correctly and "Cron set" is shown in console but after that nothing works. Loop is also running (checked with println)
void TIMER::init()
{
struct tm tm_newtime; // set time to Saturday 8:29:00am Jan 1 2011
tm_newtime.tm_year = 2011 - 1900;
tm_newtime.tm_mon = 1 - 1;
tm_newtime.tm_mday = 1;
tm_newtime.tm_hour = 8;
tm_newtime.tm_min = 29;
tm_newtime.tm_sec = 0;
tm_newtime.tm_isdst = 0;
timeval tv = { mktime(&tm_newtime), 0 };
settimeofday(&tv, nullptr);
Cron.create("*/15 * * * * *", this->timedFunction, false);
Serial.println("Cron set!");
}
void TIMER::loop()
{
Cron.delay();
yield();
}
void TIMER::timedFunction()
{
Serial.println("Cron called!");
}
`virtual void onScheduleUpdate(JsonDocument& actions) override{
JsonArray actions_array = actions.as();
for (JsonVariant action : actions_array) {
const char* action_name = action["name"];
if (strcmp(action_name, "irigate") == 0) {
const char* cron = action["cron"];
OnTick_t tic = [this]() { // no suitable conversion function from to exists from lamda [] void () to OnTick_t
MyDevice::irigate(this, 3, 4);
};
Cron.create(cron, tic, false);
}
}
}`
When running the example code the scheduled events won't trigger.
Based on my limited understanding something is off with the time library.
The time(nullptr) function always returns the same time.
Console output:
Wed Dec 31 23:59:59 1969
Wed Dec 31 23:59:59 1969
Wed Dec 31 23:59:59 1969
deleted
Is there any way to free whole alarms by a function? Currently, we should store the ID of that alarm in an extra variable.
For example, I must turn on a led at 08am and turn it off at 04pm.
// ...
Cron.create("0 0 16 * * *", { printLocalTime(); }, false);
Cron.create("0 0 8 * * *", { printLocalTime(); }, false);
// ...loop
Cron.delay();
// ...
But I saw that when restarting esp, alarms are triggered. How to work this to fire the next day? Since these times have passed.
on esp 12th and esp1s:
when powering on or when reset, all Crons are activated, they are then active according to their programming
cordialement RB
(nb goo traduction)
Line 150 in 3ad9ac8
Could you use a non blocking delay instead of the while?
Sorry to post here again but I can't see anywhere else I could post ...
Curious to hear how your display driver is going - it sounded very interesting - my hand is up to do testing.
I was thinking of the possibility of creating a github project with the goal of unifying all the latest ideas in esp32 display/sound technology, supporting VGA/PAL/NTSC, - MIT licensed, supporting both esp32 and esp32-s2. All new code, not drawn from other projects. Especially important that the door would be fully open to contributors to join the project as equal project leaders and do direct commits - the idea being to build a team/community of active contributors. There's several really great esp32 video and sound projects on github right now, but the license and ongoing activity level of the original author varies from project to project. What do you think - is that something you'd find interesting?
In #9, someone asked how to specify arguments to the called function.
Another question: is there a way to overgive arguments to the called function?
Martin-Laclaustra commented on Dec 31, 2020
You could create member variables in your class that can be accessed from the called function.
Changing the called function signature would require changes to the library code.
Can you please give an example how to do that?
When I import CronAlarms.h
and use Cron.create(...)
in a platformio project where the board used is a STM Nucleo WB55 I get the following error:
<userpath>/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: <userpath>/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(lib_a-gettimeofdayr.o): in function `_gettimeofday_r':
gettimeofdayr.c:(.text._gettimeofday_r+0xe): undefined reference to `_gettimeofday'
This is the exact platformio.ini I'm using.
[env:nucleo_wb55rg_p]
platform = ststm32
board = nucleo_wb55rg_p
framework = arduino
lib_deps =
martin-laclaustra/CronAlarms@^0.1.0
if you use it with this code the error should be reproducible:
#include <CronAlarms.h>
void setup(){
Cron.create("0 0 * * * *", [](){ }, false);
}
void loop(){
Cron.delay(1000);
}
What can I do about this?
warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
Cron.create("0 30 8 * * *", setBrightnessMaxDayPerCron, false);
Not work with arduino mkr. Are there some configuration problem?
I use the NtpClient library, which is dependent on the TimeLib library, to synchronize the time with an NTP server on an ESP8266.
I know that the ESP8266 SDK now also has an NTP mechanism. The NtpClient library has a few nice features that are missing in the SDk, so I use them.
In conjunction with the CronAlarms I have a time difference of one hour. If I get the time via the TimeLib, the time is correct.
TimeLib: 20:47:52 18.02.2021
time:.h Thu Feb 18 19:47:51 2021
Do you have an idea or tip where I have to set the time difference - possibly TimeZone - correctly?
Links
Hello do you have contact details anywhere like email or twitter?
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.