mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-12 15:36:30 +02:00
Change the OTA update period use timestamp to bootCount
This commit is contained in:
@ -856,13 +856,23 @@ static void configUpdateHandle() {
|
||||
|
||||
fwNewVersion = configuration.newFirmwareVersion();
|
||||
if (fwNewVersion.length()) {
|
||||
int lastOta = configuration.getLastOta();
|
||||
if (lastOta != 0 && lastOta < (60 * 60 * 24)) {
|
||||
Serial.println("Ignore OTA cause last update is " + String(lastOta) +
|
||||
String("sec"));
|
||||
Serial.println("Retry again after 24h");
|
||||
bool doOta = false;
|
||||
if (measurements.otaBootCount == 0) {
|
||||
doOta = true;
|
||||
Serial.println("First OTA");
|
||||
} else {
|
||||
configuration.updateLastOta();
|
||||
if ((measurements.bootCount - measurements.otaBootCount) >= 30) {
|
||||
doOta = true;
|
||||
} else {
|
||||
Serial.println(
|
||||
"OTA ignore, try again next " +
|
||||
String(30 - (measurements.bootCount - measurements.otaBootCount)) +
|
||||
String(" boots"));
|
||||
}
|
||||
}
|
||||
|
||||
if (doOta) {
|
||||
measurements.otaBootCount = measurements.bootCount;
|
||||
otaHandler.setHandlerCallback(otaHandlerCallback);
|
||||
otaHandler.updateFirmwareIfOutdated(ag->deviceId());
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ JSON_PROP_DEF(ledBarBrightness);
|
||||
JSON_PROP_DEF(displayBrightness);
|
||||
JSON_PROP_DEF(co2CalibrationRequested);
|
||||
JSON_PROP_DEF(ledBarTestRequested);
|
||||
JSON_PROP_DEF(lastOta);
|
||||
JSON_PROP_DEF(offlineMode);
|
||||
|
||||
#define jprop_model_default ""
|
||||
@ -56,7 +55,6 @@ JSON_PROP_DEF(offlineMode);
|
||||
#define jprop_postDataToAirGradient_default true
|
||||
#define jprop_ledBarBrightness_default 100
|
||||
#define jprop_displayBrightness_default 100
|
||||
#define jprop_lastOta_default 0
|
||||
#define jprop_offlineMode_default false
|
||||
|
||||
JSONVar jconfig;
|
||||
@ -162,7 +160,6 @@ void Configuration::defaultConfig(void) {
|
||||
jconfig[jprop_noxLearningOffset] = jprop_noxLearningOffset_default;
|
||||
jconfig[jprop_abcDays] = jprop_abcDays_default;
|
||||
jconfig[jprop_model] = jprop_model_default;
|
||||
jconfig[jprop_lastOta] = jprop_lastOta_default;
|
||||
jconfig[jprop_offlineMode] = jprop_offlineMode_default;
|
||||
|
||||
saveConfig();
|
||||
@ -1073,17 +1070,6 @@ void Configuration::toConfig(const char *buf) {
|
||||
jconfig[jprop_offlineMode] = false;
|
||||
}
|
||||
|
||||
/** Last OTA */
|
||||
if(JSON.typeof_(jconfig[jprop_lastOta]) != "number") {
|
||||
isInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
}
|
||||
if(isInvalid) {
|
||||
jconfig[jprop_lastOta] = jprop_lastOta_default;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
saveConfig();
|
||||
}
|
||||
@ -1167,53 +1153,6 @@ bool Configuration::isDisplayBrightnessChanged(void) {
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get number of sec from last OTA
|
||||
*
|
||||
* @return int < 0 is invalid, 0 mean there is no OTA trigger.
|
||||
*/
|
||||
int Configuration::getLastOta(void) {
|
||||
struct tm timeInfo;
|
||||
if (getLocalTime(&timeInfo) == false) {
|
||||
logError("Get localtime failed");
|
||||
return -1;
|
||||
}
|
||||
int curYear = timeInfo.tm_year + 1900;
|
||||
if (curYear < 2024) {
|
||||
logError("Current year " + String(curYear) + String(" invalid"));
|
||||
return -1;
|
||||
}
|
||||
double _t = jconfig[jprop_lastOta];
|
||||
time_t lastOta = (time_t)_t;
|
||||
time_t curTime = mktime(&timeInfo);
|
||||
logInfo("Last ota time: " + String(lastOta));
|
||||
if (lastOta == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sec = curTime - lastOta;
|
||||
logInfo("Last ota secconds: " + String(sec));
|
||||
return sec;
|
||||
}
|
||||
|
||||
void Configuration::updateLastOta(void) {
|
||||
struct tm timeInfo;
|
||||
if (getLocalTime(&timeInfo) == false) {
|
||||
logError("updateLastOta: Get localtime failed");
|
||||
return;
|
||||
}
|
||||
int curYear = timeInfo.tm_year + 1900;
|
||||
if (curYear < 2024) {
|
||||
logError("updateLastOta: lolcal time invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
time_t lastOta = mktime(&timeInfo);
|
||||
jconfig[jprop_lastOta] = (unsigned long)lastOta;
|
||||
logInfo("Last OTA: " + String(lastOta));
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
String Configuration::newFirmwareVersion(void) {
|
||||
String newFw = otaNewFirmwareVersion;
|
||||
otaNewFirmwareVersion = String("");
|
||||
|
@ -76,8 +76,6 @@ public:
|
||||
int getLedBarBrightness(void);
|
||||
bool isDisplayBrightnessChanged(void);
|
||||
int getDisplayBrightness(void);
|
||||
int getLastOta(void);
|
||||
void updateLastOta(void);
|
||||
String newFirmwareVersion(void);
|
||||
bool isOfflineMode(void);
|
||||
void setOfflineMode(bool offline);
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
int countPosition;
|
||||
const int targetCount = 20;
|
||||
int bootCount;
|
||||
int otaBootCount;
|
||||
|
||||
String toString(bool isLocal, AgFirmwareMode fwMode, int rssi, void* _ag, void* _config);
|
||||
};
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "AgWiFiConnector.h"
|
||||
#include "Libraries/WiFiManager/WiFiManager.h"
|
||||
#include <time.h>
|
||||
|
||||
#define WIFI_CONNECT_COUNTDOWN_MAX 180
|
||||
#define WIFI_HOTSPOT_PASSWORD_DEFAULT "cleanair"
|
||||
@ -159,11 +158,6 @@ bool WifiConnector::connect(void) {
|
||||
config.setPostToAirGradient(result != "T");
|
||||
}
|
||||
hasPortalConfig = false;
|
||||
|
||||
/** Configure internet time */
|
||||
const char *ntp_server = "pool.ntp.org";
|
||||
configTime(0, 0, ntp_server);
|
||||
logInfo("Set internet time server: " + String(ntp_server));
|
||||
}
|
||||
#else
|
||||
_wifiProcess();
|
||||
|
Reference in New Issue
Block a user