I have alarm set by hour and minute and dayofweek.
I set the alarms via access point HTML.
When Alarm is triggered it pusles my Remote Fob set number of times.
I put a delay (60000) to stop from looping back and doing the if statement again
Everything works like this.
From what I do know from reading around is delay is frowned upon.
I don't know any other way. I've tried break where delay is, while counter above if statement .
the code is long,
For the DS3231, you need a library that is made to cooperate with the TimeLib library.
When you test the time to the second, then it is active during that second. If other code takes longer than a second, then you could have missed that second.
With fixed times it is easier.
Suppose you want to turn something on at 05:00 and turn off at 11:00, then you need a variable that tells if it is turned on or not. There is even no need to test the minutes and seconds.
An other way is to convert everything to seconds-since-1970 and remember if the alarm was activated.
Suppose the alarms should sound at 1700000000, then a ">=" can be used.
There has to be a moment that the 'alarmWasActivated' is reset to 'false'. Perhaps at the moment that a new alarm was set.
When you want to test for hours, minutes and seconds, then it is almost impossible to make it fail-safe. Suppose the seconds is 59, and due to some delay in the code a second has passed, then it is hard to check if the right moment has passed.
If all of this is too much trouble, then the easiest solution is to use the TimeAlarms library.
Thank you aarg.
The bool seemed promising.
Wouldn't work unless the bool was above void setup. Is that correct ?
(if) looks like this.
if ((now.hour () == yourA1H) && (now.minute () == yourA1M ) && (yourA1S == 1) && (AlarmSent == false)&&((now.dayOfTheWeek() == your1SU)||(now.dayOfTheWeek() == your1M)||(now.dayOfTheWeek() == your1T)||(now.dayOfTheWeek() == your1W)||(now.dayOfTheWeek() == your1TH)|| (now.dayOfTheWeek() == your1F)||(now.dayOfTheWeek() == your1SA))) { //if alarm time is true by hr, min,, and day of week (set as weekdays) sun0 mon1 tue2 wed3 th4 fri5 sat6
for (A = 1; A <= yourP1; A++){
digitalWrite(trigger, HIGH);
delay(yourON);
digitalWrite(trigger, LOW);
delay(yourOFF);
Serial.print("ALARM");
}
AlarmSent = true;
}
Alarm gets triggered.
(for) statement pulses 5 times determined by the yourP1 SPIFF file.
and no more.
Even if the time is true again. Because AlarmSet is still True.
The alarm is repeating alarm as in same time every day of the week its set to. So how do I set the AlarmSet back to false. if the alarm is already set.
I tried AlarmSet=false in the void setup. nothing different
In the void loop before the (if). it activates alarm, pulses the (for) then finishes the statement, reads all the spiffs files (takes about a second. comes to the (if) again and sees that alarm is true and repeats until the now.minute changes.
I'm using an ESP8266 WHich has no internal hardware-RTC. So I coded a software RTC that gets synched once per day to the time of a NTP-server- This is precise enough for me.
You are using an ESP32. Will the ESP32 be powered from a battery or a wall-plug?
ESP32 do have an internal hardware-RTC. So IMHO there is no need for an external RTC.
And if you keep connected to your WLAN-router you could even use a NTP-server to keep time accurate.
As a general hint you should post your entire sketch. In 98% of all cases the entire sketch is needed for various reasons
like your potential helpers need to know all about your sketch, the error is somewhere else then the OP guessed where the error might be
Sorry, Half my last post got cut.
I learned a lot with this project. At this point just trying to learn more and make the sketch better.
Soon I'll be trying power management. As long as if it doesn't interfere with WiFi access point.
Full project is linked in first post through project hub.
I'll try to post the full sketch here next time on PC.
Which DS3231 module do you have ? Some of the cheap modules have counterfeit/discarded DS3231 chips, some have a charging circuit that will damage the rechargeable battery.
The forum saves "drafts" when you write something.
Try this:
click in the upper-right corner on your name/avatar.
select "profile"
there is a "forum settings edit", click "edit".
on the left, click "Show Drafts".
You found the drafts !
[Update] There is also an option right-below the text field, "More / Modify". With "Modify" you can fix something that was not okay. For example when a picture or a link turned out to be wrong. Sometimes I put [Update] in front of something new.