I am losing my mind and now unable to figure out what to google to self sooth - feels like i have tried everything.
I am trying to trigger sending an Email based on an event (temperature) using previousMillis.
The timer works perfect - with only one problem... the "const long interval = 360000;" delays the action UNTILL that time has past. So in the situation of 1 hour delay before a repeat it takes an hour to send the first email, before waiting an hour to repeat IF the statement is still true.
So simply put - how do i make previousMillis fire the action THEN start the countdown to prevent it spamming my email for 1 hour delay?
unsigned long previousMillis = 0;
const long interval = 360000;
// IF STATMENT MILLIS TIMER //
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
//}
//
//p.runShellCommand("cat /mnt/sda1/mail.txt | ssmtp an.email.address@gmail.com 2>&1");
Serial.print('\n');
Serial.print("-------------------------------------------------IT HAS SENT After Timer-----------------------------------------");
I am currently using 2 different no delay timers depending upon needs.
So hears how to determine which to use.
If you have any long delays that could hold up the code for more than t (time in milliseconds) then you may not want to use the first because it will repeat until _ETimer catches up to millis()
I use the second for a spam timer because even in the code locks on a while loop looking for input it won,t spam the serial port when it starts looping again. Both are good and both have their purpose.
unsigned long t = 1000 // 1 second
// Exact intervals
static unsigned long _ETimer;
if ( millis() - _ETimer >= (t)) {
_ETimer += (t);
// place your timed code here
}
// After Interval ( t (time) or more will pass before this runs again)
static unsigned long _ATimer;
if ( (unsigned long)(millis() - _ATimer) >= (t)) {
_ATimer = millis();
// place your timed code here
}