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

View File

@ -69,11 +69,17 @@ bool AgApiClient::fetchServerConfiguration(void) {
if (retCode != 200) { if (retCode != 200) {
client.end(); client.end();
getConfigFailed = true; getConfigFailed = true;
/** Return code 400 mean device not setup on cloud. */
if (retCode == 400) {
notAvailableOnDashboard = true;
}
return false; return false;
} }
/** clear failed */ /** clear failed */
getConfigFailed = false; getConfigFailed = false;
notAvailableOnDashboard = false;
/** Get response string */ /** Get response string */
String respContent = client.getString(); String respContent = client.getString();
@ -144,6 +150,17 @@ bool AgApiClient::isFetchConfigureFailed(void) { return getConfigFailed; }
*/ */
bool AgApiClient::isPostToServerFailed(void) { return postToServerFailed; } 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; } void AgApiClient::setAirGradient(AirGradient *ag) { this->ag = ag; }
/** /**

View File

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

View File

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

View File

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