From 17ce2debce214f20757357074f1c726fa99fa048 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 16 Mar 2023 07:59:39 -0500 Subject: [PATCH] [OTA] Add hourly update routine for update check (#1538) Update check will be done at start and hourly --- docs/use/gateway.md | 3 +++ main/User_config.h | 1 + main/main.ino | 15 +++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/use/gateway.md b/docs/use/gateway.md index e93e07b..7bd5f5a 100644 --- a/docs/use/gateway.md +++ b/docs/use/gateway.md @@ -122,6 +122,9 @@ mosquitto_pub -t "home/OpenMQTTGateway_ESP32_BLE/commands/MQTTtoSYS/firmware_upd "version": "v1.2.0" }' ``` + +OpenMQTTGateway checks at start and every hour if an update is available. + Alternatively if you want to choose the update URL you can use the command below (ESP32 and ESP8266): Without certificate, in this case we will use the root certificate defined in User_config.h diff --git a/main/User_config.h b/main/User_config.h index 5bce020..fb8987b 100644 --- a/main/User_config.h +++ b/main/User_config.h @@ -605,6 +605,7 @@ CRGB leds2[FASTLED_IND_NUM_LEDS]; #endif #define TimeBetweenReadingSYS 120 // time between (s) system readings (like memory) +#define TimeBetweenCheckingSYS 3600 // time between (s) system checkings (like updates) #define TimeLedON 1 // time LED are ON #define InitialMQTTConnectionTimeout 10 // time estimated (s) before the board is connected to MQTT #define subjectSYStoMQTT "/SYStoMQTT" diff --git a/main/main.ino b/main/main.ino index 011942e..bf8c55b 100644 --- a/main/main.ino +++ b/main/main.ino @@ -45,6 +45,10 @@ ReceivedSignal receivedSignal[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}}; #if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) //Time used to wait for an interval before checking system measures unsigned long timer_sys_measures = 0; + +// Time used to wait before system checkings +unsigned long timer_sys_checks = 0; + # define ARDUINOJSON_USE_LONG_LONG 1 # define ARDUINOJSON_ENABLE_STD_STRING 1 #endif @@ -1544,10 +1548,6 @@ void loop() { connected = true; #if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) if (now > (timer_sys_measures + (TimeBetweenReadingSYS * 1000)) || !timer_sys_measures) { -# if defined(ESP32) && defined(MQTT_HTTPS_FW_UPDATE) - if (!timer_sys_measures) // Only check for updates at start for ESP32 - checkForUpdates(); -# endif timer_sys_measures = millis(); stateMeasures(); # ifdef ZgatewayBT @@ -1560,6 +1560,12 @@ void loop() { stateSSD1306Display(); # endif } + if (now > (timer_sys_checks + (TimeBetweenCheckingSYS * 1000)) || !timer_sys_checks) { +# if defined(ESP32) && defined(MQTT_HTTPS_FW_UPDATE) + checkForUpdates(); +# endif + timer_sys_checks = millis(); + } #endif #ifdef ZsensorBME280 MeasureTempHumAndPressure(); //Addon to measure Temperature, Humidity, Pressure and Altitude with a Bosch BME280/BMP280 @@ -1998,6 +2004,7 @@ String latestVersion; * Only available for ESP32 */ bool checkForUpdates() { + Log.notice(F("Update check")); HTTPClient http; http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); http.begin(OTA_JSON_URL, OTAserver_cert);