mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-04 03:36:32 +02:00
Implement regular OTA update attempt / indicate OTA processing on display
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#else
|
||||
#include "EEPROM.h"
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#define EEPROM_CONFIG_SIZE 512
|
||||
#define CONFIG_FILE_NAME "/cfg.bin"
|
||||
@ -163,6 +164,7 @@ void Configuration::defaultConfig(void) {
|
||||
config.temperatureUnit = 'c';
|
||||
config.ledBarBrightness = 100;
|
||||
config.displayBrightness = 100;
|
||||
config.lastOta = 0;
|
||||
|
||||
saveConfig();
|
||||
}
|
||||
@ -171,7 +173,10 @@ void Configuration::defaultConfig(void) {
|
||||
* @brief Show configuration as JSON string message over log
|
||||
*
|
||||
*/
|
||||
void Configuration::printConfig(void) { logInfo(toString().c_str()); }
|
||||
void Configuration::printConfig(void) {
|
||||
logInfo(toString().c_str());
|
||||
logInfo("Last OTA time: " + String(config.lastOta));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new Ag Configure:: Ag Configure object
|
||||
@ -638,6 +643,18 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.typeof_(root["targetFirmware"]) == "string") {
|
||||
String newVer = root["targetFirmware"];
|
||||
String curVer = String(GIT_VERSION);
|
||||
if (curVer != newVer) {
|
||||
logInfo("Detected new firwmare version: " + newVer);
|
||||
otaNewFirmwareVersion = newVer;
|
||||
udpated = true;
|
||||
} else {
|
||||
otaNewFirmwareVersion = String("");
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
udpated = true;
|
||||
saveConfig();
|
||||
@ -938,3 +955,52 @@ bool Configuration::isDisplayBrightnessChanged(void) {
|
||||
displayBrightnessChanged = false;
|
||||
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;
|
||||
}
|
||||
time_t curTime = mktime(&timeInfo);
|
||||
logInfo("Last ota time: " + String(config.lastOta));
|
||||
if (config.lastOta == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sec = curTime - config.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;
|
||||
}
|
||||
config.lastOta = mktime(&timeInfo);
|
||||
logInfo("Last OTA: " + String(config.lastOta));
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
String Configuration::newFirmwareVersion(void) {
|
||||
String newFw = otaNewFirmwareVersion;
|
||||
otaNewFirmwareVersion = String("");
|
||||
return newFw;
|
||||
}
|
||||
|
Reference in New Issue
Block a user