Hello
I am trying to have a function called once a day (for example midnight) that sends me a text telling me the arduino is online.
I tried to use TimeAlarms and Alarm.alarmrepeat statement is in the Setup section.
The main loop of the script tests the status of a few sensors and then sends a text message if any of the sensors are out of correct values. The main loop then has a 5 minute delay.
Two problems - if the time happens to be 11:55pm - 11.59pm, and then goes into the 5 minute delay, the alarm is not tripped.
I have thought of doing a series of 20 second or 30 second delays so the Alarm module can see the midnight time and call the function.
I have read in some places I need to use the Alarm.delay call instead of the standard delay (60000) ?
What you can do instead is to save the current time in a variable with the function millis().
That way you can do different things with different time intervals and keep the timing.
You just have to be aware, that it overflows after 50 days of not resetting the arduino. If you plan to run it for longer, you should put something in place to handle that.
Structure your code as a number of tasks and in one of them add a millisDelay timer. (millisDelay is a class that does non-blocking delays and repeating timers)
You will not have any problems @Kerbolosh mentioned when you use a repeating millisDelay timer.
However, the microprocessor clock is not very accurate or stable and your alarm will drift over time.
An RTC (real time clock) chip, like a DS3231 from Adafruit is a better solution with a drift of a few secs/month