Skip to content

Commit b6b270e

Browse files
committed
http_app: code clean up
1 parent 11d35e2 commit b6b270e

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

main/src/user/http_app_ota.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ static esp_ota_handle_t update_handle = 0;
3232

3333
esp_err_t http_app_ota_event_handler(esp_http_client_event_t *evt)
3434
{
35+
esp_err_t err = ESP_OK;
36+
3537
switch (evt->event_id) {
3638
case HTTP_EVENT_ERROR:
3739
break;
@@ -44,6 +46,8 @@ esp_err_t http_app_ota_event_handler(esp_http_client_event_t *evt)
4446
case HTTP_EVENT_ON_DATA: {
4547
if (evt->data_len) {
4648
if (!update_handle) {
49+
data_length = 0;
50+
4751
led_set_mode(7);
4852
gui_show_image(8);
4953

@@ -56,16 +60,14 @@ esp_err_t http_app_ota_event_handler(esp_http_client_event_t *evt)
5660
goto exit;
5761
}
5862

59-
esp_err_t err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
63+
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
6064
if (err != ESP_OK) {
6165
ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err));
6266
goto exit;
6367
}
64-
65-
data_length = 0;
6668
}
6769

68-
esp_err_t err = esp_ota_write(update_handle, (const void *)evt->data, evt->data_len);
70+
err = esp_ota_write(update_handle, (const void *)evt->data, evt->data_len);
6971
if (err != ESP_OK) {
7072
ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err));
7173
goto exit;
@@ -77,12 +79,13 @@ esp_err_t http_app_ota_event_handler(esp_http_client_event_t *evt)
7779
}
7880
case HTTP_EVENT_ON_FINISH: {
7981
if (data_length != 0) {
80-
if (esp_ota_end(update_handle) != ESP_OK) {
82+
err = esp_ota_end(update_handle);
83+
if (err != ESP_OK) {
8184
ESP_LOGE(TAG, "esp_ota_end failed");
8285
goto exit;
8386
}
8487

85-
esp_err_t err = esp_ota_set_boot_partition(update_partition);
88+
err = esp_ota_set_boot_partition(update_partition);
8689
if (err != ESP_OK) {
8790
ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)", esp_err_to_name(err));
8891
goto exit;
@@ -124,6 +127,7 @@ void http_app_check_for_updates(void)
124127
{
125128
#ifdef CONFIG_ENABLE_OTA
126129
ESP_LOGI(TAG, "checking for firmware update...");
130+
127131
EventBits_t uxBits = xEventGroupSync(
128132
user_event_group,
129133
HTTP_APP_OTA_RUN_BIT,
@@ -133,6 +137,12 @@ void http_app_check_for_updates(void)
133137
if ((uxBits & HTTP_APP_OTA_READY_BIT) == 0) {
134138
xEventGroupClearBits(user_event_group, HTTP_APP_OTA_RUN_BIT);
135139
}
136-
update_handle = 0;
140+
141+
if (update_handle) {
142+
esp_ota_end(update_handle);
143+
update_handle = 0;
144+
145+
data_length = 0;
146+
}
137147
#endif
138148
}

main/src/user/http_app_token.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ void http_app_verify_token(char *token)
9191
if (token == NULL) {
9292
return;
9393
}
94+
9495
token_string = token;
96+
9597
EventBits_t uxBits = xEventGroupSync(
9698
user_event_group,
9799
HTTP_APP_TOKEN_RUN_BIT,

0 commit comments

Comments
 (0)