This commit is contained in:
@@ -22,14 +22,14 @@ Firmware OTA::getLatestVersionOnServer() {
|
||||
HTTPClient http;
|
||||
http.begin(_serverUrl);
|
||||
int httpCode = http.GET();
|
||||
logger.log(0, DEBUG, "HTTP Code: %d", httpCode);
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTP Code: %d", httpCode);
|
||||
|
||||
if (httpCode != 200) {
|
||||
return createErrorResponse("HTTP GET request failed with code " + String(httpCode));
|
||||
}
|
||||
|
||||
String payload = http.getString();
|
||||
logger.log(0, DEBUG, "Payload: %s", payload.c_str());
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "Payload: %s", payload.c_str());
|
||||
DynamicJsonDocument doc(4096);
|
||||
DeserializationError error = deserializeJson(doc, payload);
|
||||
|
||||
@@ -54,7 +54,7 @@ Firmware OTA::getLatestVersionOnServer() {
|
||||
deviceConfig
|
||||
});
|
||||
} else {
|
||||
logger.log(0, DEBUG, "Configuration %s does not match current device configuration %s", deviceConfig.c_str(), _current_device_configuration.c_str());
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "Configuration %s does not match current device configuration %s", deviceConfig.c_str(), _current_device_configuration.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ Firmware OTA::getLatestVersionOnServer() {
|
||||
Configuration latest = getLatestConfiguration(configs.data(), configs.size());
|
||||
|
||||
if (!isVersionNewer(_currentVersion, latest.version)) {
|
||||
logger.log(0, DEBUG, "No newer version found. Server version: %d.%d.%d", latest.version.major, latest.version.minor, latest.version.patch);
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "No newer version found. Server version: %d.%d.%d", latest.version.major, latest.version.minor, latest.version.patch);
|
||||
}
|
||||
|
||||
return Firmware{
|
||||
@@ -88,79 +88,79 @@ Firmware OTA::createErrorResponse(const String& errorMsg) {
|
||||
}
|
||||
|
||||
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) {
|
||||
logger.log(0, DEBUG, "Starting OTA upgrade");
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "Starting OTA upgrade");
|
||||
HTTPUpdate httpUpdate;
|
||||
httpUpdate.onStart(callback_started);
|
||||
httpUpdate.onEnd(callback_finished);
|
||||
httpUpdate.onProgress(callback_progress);
|
||||
httpUpdate.onError(callback_error);
|
||||
logger.log(0, DEBUG, "Defined callbacks, Starting update now");
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "Defined callbacks, Starting update now");
|
||||
|
||||
t_httpUpdate_return ret;
|
||||
|
||||
if (url.startsWith("https")) {
|
||||
logger.log(0, DEBUG, "HTTPS URL");
|
||||
WiFiClientSecure client;
|
||||
client.setInsecure();
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL");
|
||||
WiFiClient client;
|
||||
// client.setInsecure();
|
||||
ret = httpUpdate.update(client, url);
|
||||
} else if (url.startsWith("http")) {
|
||||
logger.log(0, DEBUG, "HTTP URL");
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTP URL");
|
||||
WiFiClient client;
|
||||
ret = httpUpdate.update(client, url);
|
||||
} else {
|
||||
logger.log(0, ERROR, "URL is not valid: \n%s", url.c_str());
|
||||
Logger.log(0, ELOG_LEVEL_ERROR, "URL is not valid: \n%s", url.c_str());
|
||||
}
|
||||
|
||||
switch (ret) {
|
||||
case HTTP_UPDATE_FAILED:
|
||||
logger.log(0, ERROR, "HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
|
||||
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
|
||||
break;
|
||||
|
||||
case HTTP_UPDATE_NO_UPDATES:
|
||||
logger.log(0, ERROR, "HTTP_UPDATE_NO_UPDATES");
|
||||
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_NO_UPDATES");
|
||||
break;
|
||||
|
||||
case HTTP_UPDATE_OK:
|
||||
logger.log(0, DEBUG, "Update done");
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "Update done");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void run_ota_spiffs_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) {
|
||||
logger.log(0, DEBUG, "Starting OTA SPIFFS upgrade");
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "Starting OTA SPIFFS upgrade");
|
||||
HTTPUpdate httpUpdate;
|
||||
httpUpdate.onStart(callback_started);
|
||||
httpUpdate.onEnd(callback_finished);
|
||||
httpUpdate.onProgress(callback_progress);
|
||||
httpUpdate.onError(callback_error);
|
||||
logger.log(0, DEBUG, "Defined callbacks, Starting update now");
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "Defined callbacks, Starting update now");
|
||||
|
||||
t_httpUpdate_return ret;
|
||||
|
||||
if (url.startsWith("https")) {
|
||||
logger.log(0, DEBUG, "HTTPS URL");
|
||||
WiFiClientSecure client;
|
||||
client.setInsecure();
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTPS URL");
|
||||
WiFiClient client;
|
||||
// client.setInsecure();
|
||||
ret = httpUpdate.updateSpiffs(client, url);
|
||||
} else if (url.startsWith("http")) {
|
||||
logger.log(0, DEBUG, "HTTP URL");
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "HTTP URL");
|
||||
WiFiClient client;
|
||||
ret = httpUpdate.updateSpiffs(client, url);
|
||||
} else {
|
||||
logger.log(0, ERROR, "URL is not valid: \n%s", url.c_str());
|
||||
Logger.log(0, ELOG_LEVEL_ERROR, "URL is not valid: \n%s", url.c_str());
|
||||
}
|
||||
|
||||
switch (ret) {
|
||||
case HTTP_UPDATE_FAILED:
|
||||
logger.log(0, ERROR, "HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
|
||||
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
|
||||
break;
|
||||
|
||||
case HTTP_UPDATE_NO_UPDATES:
|
||||
logger.log(0, ERROR, "HTTP_UPDATE_NO_UPDATES");
|
||||
Logger.log(0, ELOG_LEVEL_ERROR, "HTTP_UPDATE_NO_UPDATES");
|
||||
break;
|
||||
|
||||
case HTTP_UPDATE_OK:
|
||||
logger.log(0, DEBUG, "SPIFFS Update done");
|
||||
Logger.log(0, ELOG_LEVEL_DEBUG, "SPIFFS Update done");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user