Send status message every interval (10min). Reboot once per day (hack).
This commit is contained in:
parent
ef26d2e297
commit
49a9b45ab9
15
src/main.cpp
15
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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user