This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
#include <ArduinoLog.h>
|
||||
#include <HTTPUpdate.h>
|
||||
|
||||
OTA::OTA(String server_url, String currentVersion, String currentDeviceConfiguration) {
|
||||
OTA::OTA(String server_url, Version currentVersion, String currentDeviceConfiguration) {
|
||||
_serverUrl = server_url;
|
||||
_currentVersion = parseVersion(currentVersion.c_str());
|
||||
_currentVersion = currentVersion;
|
||||
_current_device_configuration = currentDeviceConfiguration;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,13 @@ Firmware OTA::getLatestVersionOnServer() {
|
||||
return createErrorResponse("No valid configuration found in the JSON response");
|
||||
}
|
||||
|
||||
|
||||
Configuration latest = getLatestConfiguration(configs.data(), configs.size());
|
||||
|
||||
if (!isVersionNewer(_currentVersion, latest.version)) {
|
||||
Log.verbose("No newer version found. Server version: %d.%d.%d", latest.version.major, latest.version.minor, latest.version.patch);
|
||||
}
|
||||
|
||||
return Firmware{
|
||||
latest.version,
|
||||
latest.url,
|
||||
|
||||
@@ -11,22 +11,18 @@
|
||||
|
||||
class OTA {
|
||||
public:
|
||||
OTA(String server_url, String currentVersion, String currentDeviceConfiguration);
|
||||
OTA(String server_url, Version currentVersion, String currentDeviceConfiguration);
|
||||
Firmware getLatestVersionOnServer();
|
||||
|
||||
|
||||
bool checkForUpdate();
|
||||
void run_ota_update(String url, std::function<void()> callback_started, std::function<void()> callback_finished, std::function<void(int, int)> callback_progress, std::function<void(int)> callback_error);
|
||||
|
||||
|
||||
private:
|
||||
bool _isHTTPS = false;
|
||||
String _serverUrl;
|
||||
Version _currentVersion;
|
||||
String _current_device_configuration;
|
||||
Firmware createErrorResponse(const String& errorMsg);
|
||||
void update_started();
|
||||
void update_finished();
|
||||
void update_progress(int cur, int total);
|
||||
void update_error(int err);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -30,4 +30,13 @@ Configuration getLatestConfiguration(Configuration *configs, int count) {
|
||||
}
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
|
||||
bool isVersionNewer(Version oldVersion, Version newVersion) {
|
||||
if (newVersion.major > oldVersion.major ||
|
||||
(newVersion.major == oldVersion.major && newVersion.minor > oldVersion.minor) ||
|
||||
(newVersion.major == oldVersion.major && newVersion.minor == oldVersion.minor && newVersion.patch > oldVersion.patch)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -28,4 +28,5 @@ struct Configuration {
|
||||
};
|
||||
|
||||
Version parseVersion(const char *versionStr);
|
||||
Configuration getLatestConfiguration(Configuration *configs, int count);
|
||||
Configuration getLatestConfiguration(Configuration *configs, int count);
|
||||
bool isVersionNewer(Version oldVersion, Version newVersion);
|
||||
Reference in New Issue
Block a user