forked from airgradienthq/arduino
Merge pull request #137 from airgradienthq/hotfix/correct-ota-update-message-on-display
Correct OTA process message show on display
This commit is contained in:
@ -219,6 +219,7 @@ void setup() {
|
|||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
// ota not supported
|
// ota not supported
|
||||||
#else
|
#else
|
||||||
|
otaHandler.setHandlerCallback(otaHandlerCallback);
|
||||||
otaHandler.updateFirmwareIfOutdated(ag->deviceId());
|
otaHandler.updateFirmwareIfOutdated(ag->deviceId());
|
||||||
|
|
||||||
/** Update first OTA */
|
/** Update first OTA */
|
||||||
@ -489,6 +490,7 @@ static bool sgp41Init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void otaHandlerCallback(OtaState state, String mesasge) {
|
static void otaHandlerCallback(OtaState state, String mesasge) {
|
||||||
|
Serial.println("OTA message: " + mesasge);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case OtaState::OTA_STATE_BEGIN:
|
case OtaState::OTA_STATE_BEGIN:
|
||||||
displayExecuteOta(state, fwNewVersion, 0);
|
displayExecuteOta(state, fwNewVersion, 0);
|
||||||
@ -511,7 +513,7 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case OtaState::OTA_STATE_BEGIN: {
|
case OtaState::OTA_STATE_BEGIN: {
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
oledDisplay.showNewFirmwareVersion(msg);
|
oledDisplay.showFirmwareUpdateVersion(msg);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("New firmware: " + msg);
|
Serial.println("New firmware: " + msg);
|
||||||
}
|
}
|
||||||
@ -520,7 +522,7 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
|
|||||||
}
|
}
|
||||||
case OtaState::OTA_STATE_FAIL: {
|
case OtaState::OTA_STATE_FAIL: {
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
oledDisplay.showNewFirmwareFailed();
|
oledDisplay.showFirmwareUpdateFailed();
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Error: Firmware update: failed");
|
Serial.println("Error: Firmware update: failed");
|
||||||
}
|
}
|
||||||
@ -528,9 +530,29 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
|
|||||||
delay(2500);
|
delay(2500);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case OtaState::OTA_STATE_SKIP: {
|
||||||
|
if (ag->isOne()) {
|
||||||
|
oledDisplay.showFirmwareUpdateSkipped();
|
||||||
|
} else {
|
||||||
|
Serial.println("Firmware update: Skipped");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(2500);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OtaState::OTA_STATE_UP_TO_DATE: {
|
||||||
|
if (ag->isOne()) {
|
||||||
|
oledDisplay.showFirmwareUpdateUpToDate();
|
||||||
|
} else {
|
||||||
|
Serial.println("Firmware update: up to date");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(2500);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case OtaState::OTA_STATE_PROCESSING: {
|
case OtaState::OTA_STATE_PROCESSING: {
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
oledDisplay.showNewFirmwareUpdating(String(processing));
|
oledDisplay.showFirmwareUpdateProgress(processing);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Firmware update: " + String(processing) + String("%"));
|
Serial.println("Firmware update: " + String(processing) + String("%"));
|
||||||
}
|
}
|
||||||
@ -546,13 +568,14 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
|
|||||||
while (i != 0) {
|
while (i != 0) {
|
||||||
i = i - 1;
|
i = i - 1;
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
oledDisplay.showNewFirmwareSuccess(String(i));
|
oledDisplay.showFirmwareUpdateSuccess(i);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Rebooting... " + String(i));
|
Serial.println("Rebooting... " + String(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
oledDisplay.setBrightness(0);
|
||||||
esp_restart();
|
esp_restart();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -884,7 +907,7 @@ static void configUpdateHandle() {
|
|||||||
fwNewVersion = configuration.newFirmwareVersion();
|
fwNewVersion = configuration.newFirmwareVersion();
|
||||||
if (fwNewVersion.length()) {
|
if (fwNewVersion.length()) {
|
||||||
bool doOta = false;
|
bool doOta = false;
|
||||||
if (measurements.otaBootCount == 0) {
|
if (measurements.otaBootCount < 0) {
|
||||||
doOta = true;
|
doOta = true;
|
||||||
Serial.println("First OTA");
|
Serial.println("First OTA");
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,6 +18,8 @@ enum OtaUpdateOutcome {
|
|||||||
enum OtaState {
|
enum OtaState {
|
||||||
OTA_STATE_BEGIN,
|
OTA_STATE_BEGIN,
|
||||||
OTA_STATE_FAIL,
|
OTA_STATE_FAIL,
|
||||||
|
OTA_STATE_SKIP,
|
||||||
|
OTA_STATE_UP_TO_DATE,
|
||||||
OTA_STATE_PROCESSING,
|
OTA_STATE_PROCESSING,
|
||||||
OTA_STATE_SUCCESS
|
OTA_STATE_SUCCESS
|
||||||
};
|
};
|
||||||
@ -40,13 +42,22 @@ public:
|
|||||||
config.url = urlAsChar;
|
config.url = urlAsChar;
|
||||||
OtaUpdateOutcome ret = attemptToPerformOta(&config);
|
OtaUpdateOutcome ret = attemptToPerformOta(&config);
|
||||||
Serial.println(ret);
|
Serial.println(ret);
|
||||||
if (ret == OtaUpdateOutcome::UPDATE_PERFORMED) {
|
|
||||||
if (this->callback) {
|
if (this->callback) {
|
||||||
|
switch (ret) {
|
||||||
|
case OtaUpdateOutcome::UPDATE_PERFORMED:
|
||||||
this->callback(OtaState::OTA_STATE_SUCCESS, "");
|
this->callback(OtaState::OTA_STATE_SUCCESS, "");
|
||||||
}
|
break;
|
||||||
} else {
|
case OtaUpdateOutcome::UDPATE_SKIPPED:
|
||||||
if(this->callback) {
|
this->callback(OtaState::OTA_STATE_SKIP, "");
|
||||||
|
break;
|
||||||
|
case OtaUpdateOutcome::ALREADY_UP_TO_DATE:
|
||||||
|
this->callback(OtaState::OTA_STATE_UP_TO_DATE, "");
|
||||||
|
break;
|
||||||
|
case OtaUpdateOutcome::UPDATE_FAILED:
|
||||||
this->callback(OtaState::OTA_STATE_FAIL, "");
|
this->callback(OtaState::OTA_STATE_FAIL, "");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,6 +138,9 @@ private:
|
|||||||
int data_read =
|
int data_read =
|
||||||
esp_http_client_read(client, upgrade_data_buf, OTA_BUF_SIZE);
|
esp_http_client_read(client, upgrade_data_buf, OTA_BUF_SIZE);
|
||||||
if (data_read == 0) {
|
if (data_read == 0) {
|
||||||
|
if (this->callback) {
|
||||||
|
this->callback(OtaState::OTA_STATE_PROCESSING, String(100));
|
||||||
|
}
|
||||||
Serial.println("Connection closed, all data received");
|
Serial.println("Connection closed, all data received");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ void OledDisplay::setBrightness(int percent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::showNewFirmwareVersion(String version) {
|
void OledDisplay::showFirmwareUpdateVersion(String version) {
|
||||||
if (isDisplayOff) {
|
if (isDisplayOff) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -344,7 +344,7 @@ void OledDisplay::showNewFirmwareVersion(String version) {
|
|||||||
} while (DISP()->nextPage());
|
} while (DISP()->nextPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::showNewFirmwareUpdating(String percent) {
|
void OledDisplay::showFirmwareUpdateProgress(int percent) {
|
||||||
if (isDisplayOff) {
|
if (isDisplayOff) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -353,11 +353,11 @@ void OledDisplay::showNewFirmwareUpdating(String percent) {
|
|||||||
do {
|
do {
|
||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
setCentralText(20, "Firmware Update");
|
setCentralText(20, "Firmware Update");
|
||||||
setCentralText(50, String("Updating... ") + percent + String("%"));
|
setCentralText(50, String("Updating... ") + String(percent) + String("%"));
|
||||||
} while (DISP()->nextPage());
|
} while (DISP()->nextPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::showNewFirmwareSuccess(String count) {
|
void OledDisplay::showFirmwareUpdateSuccess(int count) {
|
||||||
if (isDisplayOff) {
|
if (isDisplayOff) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -367,11 +367,11 @@ void OledDisplay::showNewFirmwareSuccess(String count) {
|
|||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
setCentralText(20, "Firmware Update");
|
setCentralText(20, "Firmware Update");
|
||||||
setCentralText(40, "Success");
|
setCentralText(40, "Success");
|
||||||
setCentralText(60, String("Rebooting... ") + count);
|
setCentralText(60, String("Rebooting... ") + String(count));
|
||||||
} while (DISP()->nextPage());
|
} while (DISP()->nextPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::showNewFirmwareFailed(void) {
|
void OledDisplay::showFirmwareUpdateFailed(void) {
|
||||||
if (isDisplayOff) {
|
if (isDisplayOff) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -380,8 +380,34 @@ void OledDisplay::showNewFirmwareFailed(void) {
|
|||||||
do {
|
do {
|
||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
setCentralText(20, "Firmware Update");
|
setCentralText(20, "Firmware Update");
|
||||||
setCentralText(40, "Failed");
|
setCentralText(40, "fail, will retry");
|
||||||
setCentralText(60, String("Retry after 24h"));
|
// setCentralText(60, "will retry");
|
||||||
|
} while (DISP()->nextPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OledDisplay::showFirmwareUpdateSkipped(void) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DISP()->firstPage();
|
||||||
|
do {
|
||||||
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
|
setCentralText(20, "Firmware Update");
|
||||||
|
setCentralText(40, "skipped");
|
||||||
|
} while (DISP()->nextPage());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OledDisplay::showFirmwareUpdateUpToDate(void) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DISP()->firstPage();
|
||||||
|
do {
|
||||||
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
|
setCentralText(20, "Firmware Update");
|
||||||
|
setCentralText(40, "up to date");
|
||||||
} while (DISP()->nextPage());
|
} while (DISP()->nextPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +36,12 @@ public:
|
|||||||
void showDashboard(void);
|
void showDashboard(void);
|
||||||
void showDashboard(const char *status);
|
void showDashboard(const char *status);
|
||||||
void setBrightness(int percent);
|
void setBrightness(int percent);
|
||||||
void showNewFirmwareVersion(String version);
|
void showFirmwareUpdateVersion(String version);
|
||||||
void showNewFirmwareUpdating(String percent);
|
void showFirmwareUpdateProgress(int percent);
|
||||||
void showNewFirmwareSuccess(String count);
|
void showFirmwareUpdateSuccess(int count);
|
||||||
void showNewFirmwareFailed(void);
|
void showFirmwareUpdateFailed(void);
|
||||||
|
void showFirmwareUpdateSkipped(void);
|
||||||
|
void showFirmwareUpdateUpToDate(void);
|
||||||
void showRebooting(void);
|
void showRebooting(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
int countPosition;
|
int countPosition;
|
||||||
const int targetCount = 20;
|
const int targetCount = 20;
|
||||||
int bootCount;
|
int bootCount;
|
||||||
int otaBootCount;
|
int otaBootCount = -1;
|
||||||
|
|
||||||
String toString(bool isLocal, AgFirmwareMode fwMode, int rssi, void* _ag, void* _config);
|
String toString(bool isLocal, AgFirmwareMode fwMode, int rssi, void* _ag, void* _config);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user