Skip to content

Commit

Permalink
only check for OTA when there's WiFi
Browse files Browse the repository at this point in the history
  • Loading branch information
tcsullivan committed Mar 24, 2024
1 parent 41dec5c commit 2c3646a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
51 changes: 26 additions & 25 deletions noisemeter-device/noisemeter-device.ino
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,6 @@ void loop() {
#ifndef UPLOAD_DISABLED
const auto now = Timestamp();

if (lastOTACheck.secondsBetween(now) >= OTA_INTERVAL_SEC) {
lastOTACheck = now;

SERIAL.println("Checking for updates...");

OTAUpdate ota (cert_ISRG_Root_X1);
if (ota.available()) {
SERIAL.print(ota.version);
SERIAL.println(" available!");
digitalWrite(PIN_LED1, LOW);

if (ota.download()) {
SERIAL.println("Download success! Restarting...");
digitalWrite(PIN_LED1, HIGH);
delay(1000);
ESP.restart();
} else {
SERIAL.println("Update download failed.");
digitalWrite(PIN_LED1, HIGH);
}
} else {
SERIAL.println("No update available.");
}
}

if (lastUpload.secondsBetween(now) >= UPLOAD_INTERVAL_SEC) {
packets.front().timestamp = now;

Expand All @@ -232,6 +207,32 @@ void loop() {
return true; // Discard empty packets
}
});

// We have WiFi: also check for software updates
if (lastOTACheck.secondsBetween(now) >= OTA_INTERVAL_SEC) {
lastOTACheck = now;
SERIAL.println("Checking for updates...");

OTAUpdate ota (cert_ISRG_Root_X1);
if (ota.available()) {
SERIAL.print(ota.version);
SERIAL.println(" available!");
digitalWrite(PIN_LED1, LOW);

if (ota.download()) {
SERIAL.println("Download success! Restarting...");
digitalWrite(PIN_LED1, HIGH);
delay(1000);
ESP.restart();
} else {
SERIAL.println("Update download failed.");
digitalWrite(PIN_LED1, HIGH);
}
} else {
SERIAL.println("No update available.");
}
}

}

if (!packets.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ build_flags =
-std=gnu++17
-DBUILD_PLATFORMIO
-DNO_GLOBAL_EEPROM
-DNOISEMETER_VERSION=\"0.0.1\"
-DNOISEMETER_VERSION=\"0.0.2\"
-Wall -Wextra

[env:esp32-pcb]
Expand Down

0 comments on commit 2c3646a

Please sign in to comment.