Remote version check

This commit is contained in:
2023-11-28 20:06:05 +05:30
parent 8396820a9f
commit 339a230aa2
4 changed files with 49 additions and 7 deletions
Binary file not shown.
+3 -3
View File
@@ -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
+45 -3
View File
@@ -1,6 +1,7 @@
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPClient.h>
#include <WiFiUdp.h>
#include <networkCredentials.h>
#include <version.h>
@@ -9,6 +10,9 @@
#include <WiFiClientSecure.h>
#include "myDisplay.h"
WiFiClient wifiClient;
HTTPClient httpClient;
void setupOTALocal() {
Serial.println("Booting");
{
@@ -70,9 +74,44 @@ void handleOTALocal() {
ArduinoOTA.handle();
}
void handleOTARemote() {
WiFiClient client;
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() {
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");
}
}
+1 -1
View File
@@ -1 +1 @@
50
58