Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct OTA process message show on display #137

Merged
merged 8 commits into from
Jun 4, 2024
31 changes: 29 additions & 2 deletions examples/OneOpenAir/OneOpenAir.ino
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,26 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
delay(2500);
break;
}
case OtaState::OTA_STATE_SKIP: {
if (ag->isOne()) {
oledDisplay.showNewFirmwareSkipped();
} else {
Serial.println("Firmware update: Skipped");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propose to rephrase to
Firmware update skipped

}

delay(2500);
break;
}
case OtaState::OTA_STATE_UP_TO_DATE: {
if (ag->isOne()) {
oledDisplay.showNewFirmwareUpToDate();
} else {
Serial.println("Firmware update: up to date");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propose to rephrase to
Firmware is up to date

}

delay(2500);
break;
}
case OtaState::OTA_STATE_PROCESSING: {
if (ag->isOne()) {
oledDisplay.showNewFirmwareUpdating(String(processing));
Expand All @@ -529,6 +549,11 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {
break;
}
case OtaState::OTA_STATE_SUCCESS: {
if (ag->isOne()) {
oledDisplay.showNewFirmwareUpdating(String(100));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to the PR but I would expect that we can write this here in this context

oledDisplay.showFirmwareUpdateProgress(100);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's relate to PR. Because firmware process has finish 100% but display sometime do not show 100%.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehm, I mean that we should pass the value along as an int (and not a String)

delay(250);
}

int i = 6;
while(i != 0) {
i = i - 1;
Expand All @@ -544,6 +569,7 @@ static void displayExecuteOta(OtaState state, String msg, int processing) {

delay(1000);
}
oledDisplay.setBrightness(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious to know, what happens without this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This like will be clear all display content while reboot device. If not the display still Show "Firmware update success" while rebooting

esp_restart();
}
break;
Expand Down Expand Up @@ -857,11 +883,12 @@ static void configUpdateHandle() {
fwNewVersion = configuration.newFirmwareVersion();
if (fwNewVersion.length()) {
bool doOta = false;
if (measurements.otaBootCount == 0) {
if (measurements.otaBootCount < 0) {
doOta = true;
Serial.println("First OTA");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the message is misleading, the device might have gone through several OTA updates when we arrive here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indicate first OTA check. If it's zero and process failed, retry will call for 3-4 times (Because we check cloud configure each 15sec). < 0 should help, that mean the otaBootCount is invalid, after first check it's set to bootCount

} else {
if ((measurements.bootCount - measurements.otaBootCount) >= 30) {
int bootDiff = measurements.bootCount - measurements.otaBootCount;
if (bootDiff >= 30) {
doOta = true;
} else {
Serial.println(
Expand Down
21 changes: 16 additions & 5 deletions examples/OneOpenAir/OtaHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ enum OtaUpdateOutcome {
enum OtaState {
OTA_STATE_BEGIN,
OTA_STATE_FAIL,
OTA_STATE_SKIP,
OTA_STATE_UP_TO_DATE,
OTA_STATE_PROCESSING,
OTA_STATE_SUCCESS
};
Expand All @@ -40,13 +42,22 @@ class OtaHandler {
config.url = urlAsChar;
OtaUpdateOutcome ret = attemptToPerformOta(&config);
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, "");
}
} else {
if(this->callback) {
break;
case OtaUpdateOutcome::UDPATE_SKIPPED:
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, "");
break;
default:
break;
}
}
}
Expand Down
30 changes: 28 additions & 2 deletions src/AgOledDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,33 @@ void OledDisplay::showNewFirmwareFailed(void) {
do {
DISP()->setFont(u8g2_font_t0_16_tf);
setCentralText(20, "Firmware Update");
setCentralText(40, "Failed");
setCentralText(60, String("Retry after 24h"));
setCentralText(40, "fail, will retry");
// setCentralText(60, "will retry");
} while (DISP()->nextPage());
}

void OledDisplay::showNewFirmwareSkipped(void) {
if (isDisplayOff) {
return;
}

DISP()->firstPage();
do {
DISP()->setFont(u8g2_font_t0_16_tf);
setCentralText(20, "Firmware Update");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propose to rephrase to
Firmware update skipped

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's fit for a line we should reduce the font size.

setCentralText(40, "skipped");
} while (DISP()->nextPage());
}

void OledDisplay::showNewFirmwareUpToDate(void) {
if (isDisplayOff) {
return;
}

DISP()->firstPage();
do {
DISP()->setFont(u8g2_font_t0_16_tf);
setCentralText(20, "Firmware Update");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term Update is redundant this way, propose to make it a sentence and say

Firmware
is up to date

setCentralText(40, "up to date");
} while (DISP()->nextPage());
}
2 changes: 2 additions & 0 deletions src/AgOledDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class OledDisplay : public PrintLog {
void showNewFirmwareUpdating(String percent);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propose to rename to
showFormwareUpdateProgress(int percent)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

void showNewFirmwareSuccess(String count);
void showNewFirmwareFailed(void);
void showNewFirmwareSkipped(void);
void showNewFirmwareUpToDate(void);
};

#endif /** _AG_OLED_DISPLAY_H_ */
2 changes: 1 addition & 1 deletion src/AgValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Measurements {
int countPosition;
const int targetCount = 20;
int bootCount;
int otaBootCount;
int otaBootCount = -1;

String toString(bool isLocal, AgFirmwareMode fwMode, int rssi, void* _ag, void* _config);
};
Expand Down