Add status check for connectivity before making HTTP calls

This commit is contained in:
Junior 2026-11-24 20:45:42 -05:00
parent 945a46cde4
commit 9f031e57c5

View File

@ -71,7 +71,7 @@ bool debouncing = false;
void loop() { void loop() {
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
if ( (currentMillis - lastStatusTime) >= STATUSINTERVAL ) { if ( (currentMillis - lastStatusTime) >= STATUSINTERVAL ) {
lastStatusTime = sendDeviceStatus(); if ( WiFi.status() == WL_CONNECTED ) lastStatusTime = sendDeviceStatus();
currentMillis = lastStatusTime; currentMillis = lastStatusTime;
} }
unsigned short buttonCheck = digitalRead(BUTTONPIN); unsigned short buttonCheck = digitalRead(BUTTONPIN);
@ -85,7 +85,7 @@ void loop() {
buttonState = buttonCheck; buttonState = buttonCheck;
if ( buttonState == LOW ) { if ( buttonState == LOW ) {
actionState = !actionState; actionState = !actionState;
sendActionMessage(actionState); if ( WiFi.status() == WL_CONNECTED ) sendActionMessage(actionState);
} }
} }
} }