Skip to content

Commit

Permalink
[OTA] Add hourly update routine for update check (#1538)
Browse files Browse the repository at this point in the history
Update check will be done at start and hourly
  • Loading branch information
1technophile authored Mar 16, 2023
1 parent 3b134fc commit 17ce2de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/use/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 11 additions & 4 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 17ce2de

Please sign in to comment.