Merge branch 'develop' into hotfix/correct-ota-update-message-on-display

This commit is contained in:
Phat Nguyen
2024-05-24 13:30:09 +07:00
committed by GitHub
5 changed files with 31 additions and 7 deletions

View File

@ -219,15 +219,20 @@ void setup() {
#ifdef ESP8266
// ota not supported
#else
// otaHandler.updateFirmwareIfOutdated(ag->deviceId());
otaHandler.updateFirmwareIfOutdated(ag->deviceId());
/** Update first OTA */
measurements.otaBootCount = 0;
#endif
apiClient.fetchServerConfiguration();
configSchedule.update();
if (apiClient.isFetchConfigureFailed()) {
if (ag->isOne()) {
stateMachine.displayHandle(
AgStateMachineWiFiOkServerOkSensorConfigFailed);
if (apiClient.isNotAvailableOnDashboard()) {
stateMachine.displayHandle(
AgStateMachineWiFiOkServerOkSensorConfigFailed);
}
}
stateMachine.handleLeds(
AgStateMachineWiFiOkServerOkSensorConfigFailed);
@ -882,8 +887,9 @@ static void configUpdateHandle() {
doOta = true;
Serial.println("First OTA");
} else {
int bootDiff = measurements.bootCount - measurements.otaBootCount;
if (bootDiff >= 30) {
/** Only check for update each 1h*/
const float otaBootCount = 60.0f / (SERVER_SYNC_INTERVAL / 60000.0f);
if ((measurements.bootCount - measurements.otaBootCount) >= (int)otaBootCount) {
doOta = true;
} else {
Serial.println(

View File

@ -69,11 +69,17 @@ bool AgApiClient::fetchServerConfiguration(void) {
if (retCode != 200) {
client.end();
getConfigFailed = true;
/** Return code 400 mean device not setup on cloud. */
if (retCode == 400) {
notAvailableOnDashboard = true;
}
return false;
}
/** clear failed */
getConfigFailed = false;
notAvailableOnDashboard = false;
/** Get response string */
String respContent = client.getString();
@ -144,6 +150,17 @@ bool AgApiClient::isFetchConfigureFailed(void) { return getConfigFailed; }
*/
bool AgApiClient::isPostToServerFailed(void) { return postToServerFailed; }
/**
* @brief Get status device has available on dashboard or not. should get after
* fetch configuration return failed
*
* @return true
* @return false
*/
bool AgApiClient::isNotAvailableOnDashboard(void) {
return notAvailableOnDashboard;
}
void AgApiClient::setAirGradient(AirGradient *ag) { this->ag = ag; }
/**

View File

@ -23,6 +23,7 @@ private:
bool getConfigFailed;
bool postToServerFailed;
bool notAvailableOnDashboard = false; // Device not setup on Airgradient cloud dashboard.
public:
AgApiClient(Stream &stream, Configuration &config);
@ -33,6 +34,7 @@ public:
bool postToServer(String data);
bool isFetchConfigureFailed(void);
bool isPostToServerFailed(void);
bool isNotAvailableOnDashboard(void);
void setAirGradient(AirGradient *ag);
bool sendPing(int rssi, int bootCount);
};

View File

@ -628,7 +628,6 @@ bool Configuration::parse(String data, bool isLocal) {
saveConfig();
printConfig();
} else {
logInfo("Update ignored due to local unofficial changes");
if (ledBarTestRequested || co2CalibrationRequested) {
udpated = true;
}

View File

@ -173,7 +173,7 @@ String Measurements::toString(bool localServer, AgFirmwareMode fwMode, int rssi,
root["noxRaw"] = this->NOxRaw;
}
}
root["bootCount"] = bootCount;
root["boot"] = bootCount;
if (localServer) {
root["ledMode"] = config->getLedBarModeName();