mirror of
https://github.com/bendtherules/Patient-counter-esp8266.git
synced 2026-08-18 13:52:39 +00:00
Remote version check
This commit is contained in:
Binary file not shown.
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
#ifndef BUILD_NUMBER
|
#ifndef BUILD_NUMBER
|
||||||
#define BUILD_NUMBER 50
|
#define BUILD_NUMBER 58
|
||||||
#endif
|
#endif
|
||||||
#ifndef VERSION
|
#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
|
#endif
|
||||||
#ifndef VERSION_SHORT
|
#ifndef VERSION_SHORT
|
||||||
#define VERSION_SHORT "v0.1.50"
|
#define VERSION_SHORT "v0.1.58"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+45
-3
@@ -1,6 +1,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
|
#include <ESP8266HTTPClient.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <networkCredentials.h>
|
#include <networkCredentials.h>
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
@@ -9,6 +10,9 @@
|
|||||||
#include <WiFiClientSecure.h>
|
#include <WiFiClientSecure.h>
|
||||||
#include "myDisplay.h"
|
#include "myDisplay.h"
|
||||||
|
|
||||||
|
WiFiClient wifiClient;
|
||||||
|
HTTPClient httpClient;
|
||||||
|
|
||||||
void setupOTALocal() {
|
void setupOTALocal() {
|
||||||
Serial.println("Booting");
|
Serial.println("Booting");
|
||||||
{
|
{
|
||||||
@@ -70,9 +74,44 @@ void handleOTALocal() {
|
|||||||
ArduinoOTA.handle();
|
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() {
|
void handleOTARemote() {
|
||||||
WiFiClient client;
|
|
||||||
|
|
||||||
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
|
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
|
||||||
ESPhttpUpdate.onStart([]() {
|
ESPhttpUpdate.onStart([]() {
|
||||||
Serial.println("RU: Started");
|
Serial.println("RU: Started");
|
||||||
@@ -96,5 +135,8 @@ void handleOTARemote() {
|
|||||||
showInsideInfo("RU:Failed");
|
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
@@ -1 +1 @@
|
|||||||
50
|
58
|
||||||
Reference in New Issue
Block a user