Electron App tread fails using Time.hour after an hour [SOLVED]

  if (Time.hour() <= 8)  {
   delay(10);
   Serial4.println("GRGROF");
   AlarmByPass(); 

}

If this runs for more than an hour the App tread fails. Keeps flashing magenta, but won’t reprogram without a reset first. Reset does start the program running again. What am I doing wrong?
Richard,

@Microlink, can you please post the code around this? It is difficult to help when we don’t have the full picture. If this code is in loop() then it will keep firing and executing the code between midnight (hour == 0) and 8am (hour==8). I’m not sure this is your intention.

void AlarmByPass() {

  digitalWrite (led2, HIGH);
  delay(500);
  digitalWrite (led2, LOW);
  delay(500);
  digitalWrite (led2, HIGH);
  delay(5000);
  digitalWrite (led2, LOW);
  Serial.println (Time.hour());
  Serial.println ("in alarm bypass mode");
  
loop();

}

Sorry, yes the intent is to stay in AlarmByPass() untill 9AM.

If the function is called from loop() and you call loop() from the function the recursion will overflow the stack and crash your firmware.

3 Likes

Thanks BulldogLowell, that makes perfect sense, and I’ve spent way to much time proving it. No true learning without a little pain!

@Microlink did you get it fixed?

Will take a few hours to be sure, but I expect it will work by not looping loop(). I did find StateTimer code on here which I’m working with now. I’m a newbie and make lots of dumb mistakes. Nice to be able to get answers really fast, I should have asked sooner.

2 Likes

There is a lot of great people here on the forums so feel free to ask!

2 Likes