diff --git a/build/esp12e/firmware.bin b/build/esp12e/firmware.bin index 07c69b7..189fc2a 100644 Binary files a/build/esp12e/firmware.bin and b/build/esp12e/firmware.bin differ diff --git a/include/version.h b/include/version.h index 6ef67cb..414de6d 100644 --- a/include/version.h +++ b/include/version.h @@ -1,9 +1,9 @@ #ifndef BUILD_NUMBER - #define BUILD_NUMBER 50 + #define BUILD_NUMBER 58 #endif #ifndef VERSION - #define VERSION "v0.1.50 - 2023-11-28 19:16:31.683586" + #define VERSION "v0.1.58 - 2023-11-28 20:05:50.363623" #endif #ifndef VERSION_SHORT - #define VERSION_SHORT "v0.1.50" + #define VERSION_SHORT "v0.1.58" #endif diff --git a/src/myOTA.cpp b/src/myOTA.cpp index e3233c1..8601ea3 100644 --- a/src/myOTA.cpp +++ b/src/myOTA.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -9,6 +10,9 @@ #include #include "myDisplay.h" +WiFiClient wifiClient; +HTTPClient httpClient; + void setupOTALocal() { Serial.println("Booting"); { @@ -70,9 +74,44 @@ void handleOTALocal() { ArduinoOTA.handle(); } +bool isOTARemoteNeeded() { + const char* url = "http://patient.bendtherules.in/versioning.html"; + + Serial.println("RU version check: Started"); + if (httpClient.begin(wifiClient, url)) { + // start connection and send HTTP header + int httpCode = httpClient.GET(); + + // httpCode will be negative on error + if (httpCode == HTTP_CODE_OK) { + String payload = httpClient.getString(); + Serial.println("RU version check: Response below -"); + Serial.println(payload); + + int newVersion = payload.toInt(); + Serial.printf("RU version check: Remote=%d Current=%d\n", newVersion, BUILD_NUMBER); + if (newVersion > BUILD_NUMBER) { + Serial.println("RU version check: Update needed"); + return true; + } else { + Serial.println("RU version check: Skip update"); + showInsideInfo("RU:Skip"); + return false; + } + } else { + Serial.printf("RU version check: GET failed, error: %s\n", httpClient.errorToString(httpCode).c_str()); + showInsideInfo("RU: Version failed"); + return false; + } + httpClient.end(); + } else { + Serial.println("RU version check: Connection failed"); + showInsideInfo("RU: Version failed"); + return false; + } +} + void handleOTARemote() { - WiFiClient client; - ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW); ESPhttpUpdate.onStart([]() { Serial.println("RU: Started"); @@ -96,5 +135,8 @@ void handleOTARemote() { showInsideInfo("RU:Failed"); }); - t_httpUpdate_return ret = ESPhttpUpdate.update(client, "http://patient.bendtherules.in/build/esp12e/firmware.bin"); + bool isUpdateNeeded = isOTARemoteNeeded(); + if (isUpdateNeeded) { + ESPhttpUpdate.update(wifiClient, "http://patient.bendtherules.in/build/esp12e/firmware.bin"); + } } diff --git a/versioning.html b/versioning.html index c5b431b..4800c7d 100644 --- a/versioning.html +++ b/versioning.html @@ -1 +1 @@ -50 \ No newline at end of file +58 \ No newline at end of file