From 49a9b45ab9b4b0761a8c2c6ae7bff9af75b10fc7 Mon Sep 17 00:00:00 2001 From: Junior Date: Tue, 8 Apr 2025 17:42:25 -0400 Subject: [PATCH] Send status message every interval (10min). Reboot once per day (hack). --- src/main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dbceb59..bc34cb7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,12 +10,15 @@ #define DEBOUNCEMS 15 #define BOARD "ESP32" #define SERVICE "LEDsActionButton" +#define STATUSINTERVAL 600000 String toggleURL = "http://moon.basement.lan/l/actionbutton.php?state="; String statusURL = "http://moon.basement.lan/l/boardstatus.php"; unsigned short buttonState = HIGH, lastButtonState = HIGH; +unsigned long lastStatusTime = 0; void sendToggleMessage(bool state) { + Serial.println("Action button triggered"); char webMsg[255] = ""; strcat(webMsg, toggleURL.c_str()); strcat(webMsg, (state) ? "true" : "false"); @@ -25,7 +28,8 @@ void sendToggleMessage(bool state) { http.end(); } -void sendDeviceStatus() { +unsigned long sendDeviceStatus() { + Serial.println("Sending device status"); WiFiClient client; HTTPClient http; http.begin(client, statusURL.c_str()); @@ -33,6 +37,7 @@ void sendDeviceStatus() { String httpData = "mac=" + WiFi.macAddress() + "&board=" + BOARD + "&firmware=" + FIRMWARE + "&service=" + SERVICE; int httpResponseCode = http.POST(httpData); http.end(); + return millis(); } void setup() { @@ -41,7 +46,7 @@ void setup() { Serial.println("MAC Address: " + WiFi.macAddress()); WiFiManager wifiManager; wifiManager.autoConnect("LEDsActionButton"); - sendDeviceStatus(); + lastStatusTime = sendDeviceStatus(); ArduinoOTA.onStart([]() { String type; if ( ArduinoOTA.getCommand() == U_FLASH ) @@ -68,6 +73,12 @@ unsigned long lastDebounceTime = 0; bool toggleState = false; bool debouncing = false; void loop() { + if ( millis() > (lastStatusTime + STATUSINTERVAL) ) { + lastStatusTime = sendDeviceStatus(); + } + if ( millis() > 86400000 ) { + ESP.restart(); + } unsigned short buttonCheck = digitalRead(BUTTONPIN); if ( buttonCheck != lastButtonState ) { debouncing = true;