Skip to content

Commit bcba420

Browse files
committed
IDF5.0 support: fix ota
Signed-off-by: Simone Orru <simone.orru@secomind.com>
1 parent 8b54704 commit bcba420

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/edgehog_ota.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ static esp_err_t http_ota_event_handler(esp_http_client_event_t *evt)
101101
case HTTP_EVENT_DISCONNECTED:
102102
ESP_LOGD(TAG, "DISCONNECTED");
103103
break;
104+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
105+
case HTTP_EVENT_REDIRECT:
106+
break;
107+
#endif
104108
}
105109
return ESP_OK;
106110
}
@@ -219,20 +223,31 @@ static edgehog_err_t do_ota(
219223
nvs_commit(handle);
220224

221225
ESP_LOGI(TAG, "DOWNLOAD_AND_DEPLOY");
222-
esp_http_client_config_t config = {
226+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
227+
esp_http_client_config_t http_config = {
228+
.url = ota_url,
229+
.event_handler = http_ota_event_handler,
230+
.timeout_ms = OTA_REQ_TIMEOUT_MS,
231+
};
232+
esp_https_ota_config_t ota_config = {
233+
.http_config = &http_config,
234+
};
235+
#else
236+
esp_http_client_config_t ota_config = {
223237
.url = ota_url,
224238
.event_handler = http_ota_event_handler,
225239
.timeout_ms = OTA_REQ_TIMEOUT_MS,
226240
};
241+
#endif
227242

228243
uint8_t attempts = 0;
229244
// FIXME: this function is blocking
230-
esp_ret = esp_https_ota(&config);
245+
esp_ret = esp_https_ota(&ota_config);
231246
while (attempts < MAX_OTA_RETRY && esp_ret != ESP_OK) {
232247
vTaskDelay(pdMS_TO_TICKS(attempts * 2000));
233248
attempts++;
234249
ESP_LOGW(TAG, "! OTA FAILED, ATTEMPT #%d !", attempts);
235-
esp_ret = esp_https_ota(&config);
250+
esp_ret = esp_https_ota(&ota_config);
236251
}
237252

238253
ESP_LOGI(TAG, "RESULT %s", esp_err_to_name(esp_ret));

0 commit comments

Comments
 (0)