Skip to content

Commit

Permalink
Merge branch 'example/optimize_httpget_to_fs_example' into 'master'
Browse files Browse the repository at this point in the history
optimize(example): Optimized the http_get_to_fatfs example

See merge request application/esp-at!1713
  • Loading branch information
xcguang committed Jan 7, 2025
2 parents a107039 + 334417a commit 26023f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/at_http_get_to_fatfs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ file(GLOB_RECURSE srcs *.c)
set(includes "include")

# Add more required components you need here, separated by spaces
set(require_components at freertos nvs_flash)
set(require_components at freertos esp_http_client)

idf_component_register(
SRCS ${srcs}
Expand Down
22 changes: 3 additions & 19 deletions examples/at_http_get_to_fatfs/custom/at_custom_cmd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -88,6 +88,7 @@ at_write_fs_handle_t *at_http_to_fs_begin(char *path)
remove(fs_handle->path);
fs_handle->fp = fopen(fs_handle->path, "wb");
if (!fs_handle->fp) {
free(fs_handle->path);
free(fs_handle);
at_fatfs_unmount();
ESP_LOGE(TAG, "fopen failed");
Expand Down Expand Up @@ -167,18 +168,9 @@ static void at_custom_wait_data_cb(void)

static esp_err_t at_http_event_handler(esp_http_client_event_t *evt)
{
ESP_LOGI(TAG, "http event id=%d", evt->event_id);
switch (evt->event_id) {
case HTTP_EVENT_ERROR:
printf("http(https) error\r\n");
break;
case HTTP_EVENT_ON_CONNECTED:
printf("http(https) connected\r\n");
break;
case HTTP_EVENT_HEADER_SENT:
printf("http(https) header sent\r\n");
break;
case HTTP_EVENT_ON_HEADER:
printf("http(https) headed key=%s, value=%s\r\n", evt->header_key, evt->header_value);
if (strcmp(evt->header_key, "Content-Length") == 0) {
sp_http_to_fs->total_size = atoi(evt->header_value);
printf("total_size=%d\r\n", sp_http_to_fs->total_size);
Expand All @@ -187,7 +179,6 @@ static esp_err_t at_http_event_handler(esp_http_client_event_t *evt)
break;
case HTTP_EVENT_ON_DATA:
sp_http_to_fs->recv_size += evt->data_len;

// chunked check
if (sp_http_to_fs->is_chunked) {
printf("received total len=%d\r\n", sp_http_to_fs->recv_size);
Expand All @@ -196,12 +187,6 @@ static esp_err_t at_http_event_handler(esp_http_client_event_t *evt)
sp_http_to_fs->recv_size, (sp_http_to_fs->recv_size * 1.0) * 100 / sp_http_to_fs->total_size);
}
break;
case HTTP_EVENT_ON_FINISH:
printf("http(https) finished\r\n");
break;
case HTTP_EVENT_DISCONNECTED:
printf("http(https) disconnected\r\n");
break;
default:
break;
}
Expand Down Expand Up @@ -322,7 +307,6 @@ static uint8_t at_setup_cmd_httpget_to_fs(uint8_t para_num)
ESP_LOGE(TAG, "Connection aborted!");
break;
} else {
printf("Connection closed\r\n");
ret = ESP_OK;
break;
}
Expand Down

0 comments on commit 26023f2

Please sign in to comment.