I need some direction on a project I am working on. I already have code running on my Electron which monitors a couple of switches and temp sensor on my RV. What I want to do is set up a schedule that can be edited online. A schedule like from 8am to 6pm on Mon/Wed/Friday allow doors/windows to open/close no action, from 6:01pm to 7:59am notify if doors/windows open/close and temp is outside a certain range.
What is the best way to implement something like this?
I made a library that allows you to create multiple schedules which would enable you to do this quite easily. You can modify the startTime and endTime, the active days, etc. using a Particle.function().
the library is here. The “documentation” is in the example.
What I was trying to do was set a start/stop time, then when the time expired set a new start/stop. The new start time worked OK but the stop time never happened. Here’s a small part of the code; So what I want to do is keep resetting the start/stop time when the previous time expires. Is this the best way to do this or is there a better way.
thanks
DailyTimer timer2(18, 30, 9, 30, EVERY_DAY, RANDOM_END, customSeedGenerator);
timer2.setRandomOffset(30, RANDOM_END);
bool timerState2 = timer2.isActive(); //State Change method this block
if(timerState2 != timer2_LastState)
{
if(timerState2)
{
//
digitalWrite(D5, HIGH);
digitalWrite(D4, LOW);
}
else
{
digitalWrite(D5, LOW);
//turn back on with new start/stop
timer2.setStartTime(10,00);
timer2.setEndTime(10,30);
}
timer2_LastState = timerState2;
}
Maybe that is my issue…I’m using the current one called “DailyTimerSpark” I saw the name were different but I though the actual code was the same? I’m using it on an Electron!
on at 9 off at 10, on at 11 off at 12, etc…what is the best way to implement something like that,
right now I check in a off function and just reset the one timer to new on/off. That requires keeping a table/array of time but maybe that is the best way to do that or should I set multiple timers per day?
I thought about the opportunity to do that when I made the library.
I suppose I would, like you mentioned create an array of times and use the endTimeCallback() to cycle through that array and reset the times to the next bracket (not including random start/stop times from the conversation at this moment) .
That would require a persistent variable from which you could increment along the way, but that seems doable.
Maybe I could work on a way to do this using some library object. I'll give it some thought.
I came across this before and started to add three methods:
myDailyTimer.manualOn() // run the start callback and maintain that "manual" state
myDailyTimer.manualOff() . // run the end callback and maintain that "manual" state
myDailyTimer.resume() . // resume the timer in its natural state
testing i did and results…
Examples are for everyday.
It seems when I set:
ledTimer1.setStartTime(08:00, 00:00);
ledTimer1.setEndTime(11:00, 00:00);
and the actual time is say 7am (07:00)
this it not work, it ran my SystemOff subroutine when I set the above times
and never ran anything when the actual time reached 8am.
Now if the actual time is 09:00
this works.
So it looks like ledTimer1 start/end time has to be between the current time
to come on.
example: 9am is between 8am and 11am in the example above and works.
I also tried the ledTimer1.resume(); in the SystemOff subroutine but didn’t work either.