kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/update_ota_download_valid_bin' into 'master'
bugfix(ota): update ota to download valid bin file See merge request idf/esp-idf!2038pull/1880/merge
commit
6dcf273f0d
|
@ -245,16 +245,22 @@ static void ota_example_task(void *pvParameter)
|
|||
}
|
||||
ESP_LOGI(TAG, "esp_ota_begin succeeded");
|
||||
|
||||
bool resp_body_start = false, flag = true;
|
||||
bool resp_body_start = false, socket_flag = true, http_200_flag = false;
|
||||
/*deal with all receive packet*/
|
||||
while (flag) {
|
||||
while (socket_flag) {
|
||||
memset(text, 0, TEXT_BUFFSIZE);
|
||||
memset(ota_write_data, 0, BUFFSIZE);
|
||||
int buff_len = recv(socket_id, text, TEXT_BUFFSIZE, 0);
|
||||
if (buff_len < 0) { /*receive error*/
|
||||
ESP_LOGE(TAG, "Error: receive data error! errno=%d", errno);
|
||||
task_fatal_error();
|
||||
} else if (buff_len > 0 && !resp_body_start) { /*deal with response header*/
|
||||
} else if (buff_len > 0 && !resp_body_start) { /*deal with response header*/
|
||||
// only start ota when server response 200 state code
|
||||
if (strstr(text, "200") == NULL && !http_200_flag) {
|
||||
ESP_LOGE(TAG, "ota url is invalid or bin is not exist");
|
||||
task_fatal_error();
|
||||
}
|
||||
http_200_flag = true;
|
||||
memcpy(ota_write_data, text, buff_len);
|
||||
resp_body_start = read_past_http_header(text, buff_len, update_handle);
|
||||
} else if (buff_len > 0 && resp_body_start) { /*deal with response body*/
|
||||
|
@ -267,7 +273,7 @@ static void ota_example_task(void *pvParameter)
|
|||
binary_file_length += buff_len;
|
||||
ESP_LOGI(TAG, "Have written image length %d", binary_file_length);
|
||||
} else if (buff_len == 0) { /*packet over*/
|
||||
flag = false;
|
||||
socket_flag = false;
|
||||
ESP_LOGI(TAG, "Connection closed, all packets received");
|
||||
close(socket_id);
|
||||
} else {
|
||||
|
|
Ładowanie…
Reference in New Issue