Skip to content

Commit

Permalink
Add maintenance loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Nov 28, 2020
1 parent 1c70675 commit 815fc2c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void loop()
saveConfig();
}
serialLoop();
maintenanceLoop();
yield();
}
}
1 change: 0 additions & 1 deletion src/pushhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void updateLoop();
void setDoURLTarget();
void setDoBFTarget();
void setDoBrewfTarget();
void setDoReset();
extern volatile bool doBubble;
extern struct Bubbles bubbles;

Expand Down
39 changes: 34 additions & 5 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,40 @@ void saveBpm()
}
}

void maintenanceLoop()
{
if (ESP.getFreeHeap() < MINFREEHEAP)
{
Log.warning(F("Maintenance: Heap memory has degraded below safe minimum, restarting." CR));
resetController();
}
if (WiFi.status() != WL_CONNECTED)
{
Log.warning(F("Maintenance: WiFi not connected, reconnecting." CR));
// TODO:
// doNonBlock = true;
doWiFi(); // With doNonBlock, this should be non-blocking
}
if (millis() > ESPREBOOT)
{
// The ms clock will rollover after ~49 days. To be on the safe side,
// restart the ESP after about 42 days to reset the ms clock.
Log.warning(F("Maintenance: Six week routine restart."));
ESP.restart();
}
if (lastNTPUpdate > NTPRESET)
{
// Reset NTP (blocking) every measured 24 hours
Log.notice(F("Maintenance: Setting time"));
setClock();
}
}

void setDoReset()
{
doReset = true; // Semaphore required for reset in callback
}

void setDoURLTarget()
{
doURLTarget = true; // Semaphore required for Ticker + radio event
Expand All @@ -128,11 +162,6 @@ void setDoBrewfTarget()
doBrewfTarget = true; // Semaphore required for Ticker + radio event
}

void setDoReset()
{
doReset = true; // Semaphore required for reset in callback
}

void setDoOTA()
{
doOTA = true; // Semaphore required for OTA in callback
Expand Down
1 change: 1 addition & 0 deletions src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void resetController();
void loadBpm();
void saveBpm();
void tickerLoop();
void maintenanceLoop();
void setDoURLTarget();
void setDoBFTarget();
void setDoBrewfTarget();
Expand Down

0 comments on commit 815fc2c

Please sign in to comment.