Setting specific event time alarms over 24hour clock - Photon

Hi everyone, i’ve been googling like crazy to find a way to execute an event at a specific time on my Photon and timealarms.h cropped but seemed a bit overkill for my requirements. So have used bits and pieces of several pieces of code I eventually got it to work. Basically I wanted some to execute at 18:00 everyday GMT but not interfere with existing process in the loop. Thought it best to share. Of course with code people have their own preferred layouts etc so i’m sure people will comment that its not quite laid out correctly. plus this isn’t my day job more for fun. Anyway here you go.

    int lastHour = 24; //more varibubbles
    int timstate = 0; //another varibubble
    void setup()
      pinMode(led, OUTPUT); // Initialize D0 pin as output, for my use not time related; //utc time - 1 hour behind GMT - I use GMT
    void  loop(){
    int currentHour = Time.hour(); // hour() returns zero through twenty-three
    if (timstate != 1 && currentHour == 18) //change the time in two places
    fullemail(); //execute new void at specific time, in this example at 18:00
      timstate = 1;
 if (currentHour != 18) //heres the other place to change the time
        timstate = 0; //resets the state when outside the time, so the code executes once.
        //reset the state so that it doesnt execute twice
    //also change the time if required 
     //carry on from here doing the rest of the loop
1 Like


Please take a look at the little library I wrote to perform repeating daily tasks, non-blocking.

If you don’t like the overhead of the library (it has a small footprint) you could alternatively lift some of the code from the methods I wrote:

I’ve been using it for several weeks on a particle Photon… seems to work nicely. Untested on Electron, FYI.