Skip to content

Commit

Permalink
show OTA message
Browse files Browse the repository at this point in the history
  • Loading branch information
oseiler2 committed Mar 16, 2023
1 parent 517cc60 commit 575de96
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/ota.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef _OTA_H
#define _OTA_H

#include "globals.h"

#include <globals.h>
#include <messageSupport.h>

typedef void (*preUpdateCallback_t)(void);

namespace OTA {
void setupOta(preUpdateCallback_t preUpdateCallback);
void setupOta(preUpdateCallback_t preUpdateCallback, setPriorityMessageCallback_t _setPriorityMessageCallback, clearPriorityMessageCallback_t _clearPriorityMessageCallback);
void checkForUpdate();
extern TaskHandle_t otaTask;
void otaLoop(void* pvParameters);
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void setup() {

housekeeping::cyclicTimer.attach(30, housekeeping::doHousekeeping);

OTA::setupOta(prepareOta);
OTA::setupOta(prepareOta, setPriorityMessage, clearPriorityMessage);

attachInterrupt(BTN_1, buttonHandler, CHANGE);

Expand Down
13 changes: 11 additions & 2 deletions src/ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ namespace OTA {

Ticker cyclicTimer;
preUpdateCallback_t preUpdateCallback;
setPriorityMessageCallback_t setPriorityMessageCallback;
clearPriorityMessageCallback_t clearPriorityMessageCallback;
String forceUpdateURL;

void setupOta(preUpdateCallback_t _preUpdateCallback) {
void setupOta(preUpdateCallback_t _preUpdateCallback, setPriorityMessageCallback_t _setPriorityMessageCallback, clearPriorityMessageCallback_t _clearPriorityMessageCallback) {
preUpdateCallback = _preUpdateCallback;
setPriorityMessageCallback = _setPriorityMessageCallback;
clearPriorityMessageCallback = _clearPriorityMessageCallback;
#ifdef OTA_POLL
cyclicTimer.attach(1060 * 60 * 24, checkForUpdate);
#endif
Expand All @@ -38,9 +42,12 @@ namespace OTA {
if (shouldExecuteFirmwareUpdate) {
ESP_LOGD(TAG, "Firmware update available");
if (preUpdateCallback) preUpdateCallback();
setPriorityMessageCallback("Starting OTA update");
mqtt::publishStatusMsg("Starting OTA update");
esp32FOTA.execOTA();
setPriorityMessageCallback("Rebooting");
delay(1000);
clearPriorityMessageCallback();
esp_restart();
} else {
ESP_LOGD(TAG, "No firmware update available");
Expand All @@ -59,11 +66,13 @@ namespace OTA {
esp32FOTA esp32FOTA(OTA_APP, APP_VERSION, false, false);
esp32FOTA.setCertFileSystem(&LittleFS);
mqtt::publishStatusMsg("Starting forced OTA update");
setPriorityMessageCallback("Starting OTA update");
esp32FOTA.forceUpdate(forceUpdateURL, false);
forceUpdateURL = "";
ESP_LOGD(TAG, "Forced OTA done");
forceUpdateURL = "";
setPriorityMessageCallback("Rebooting");
delay(1000);
clearPriorityMessageCallback();
esp_restart();
}

Expand Down

0 comments on commit 575de96

Please sign in to comment.