forked from DroneBridge/ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to DroneBridge#45 Add OTA firmware update functionality to the ESP32 telemetry solution. * **CMakeLists.txt**: Include `ota.c` in the build and add `ota.h` to the include directories. * **http_server.c**: Add `ota_update_post_handler` to handle OTA update requests and register it in `start_rest_server`. * **main.c**: Include `ota.h` and initialize OTA update functionality in `app_main`. * **ota.c**: Implement OTA update functionality using ESP-IDF OTA APIs and define `ota_update_task` to handle the OTA update process. * **ota.h**: Declare `ota_update_task` function and include necessary headers. * **README.md**: Add a section explaining how to perform OTA updates and provide instructions for uploading firmware via the web interface.
- Loading branch information
1 parent
0e2810a
commit 81f0fec
Showing
6 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
idf_component_register(SRCS main.c db_esp32_control.c msp_ltm_serial.c http_server.c | ||
db_esp32_comm.c db_comm.c db_crc.c tcp_server.c db_esp_now.c db_serial.c db_mavlink_msgs.c | ||
INCLUDE_DIRS ".") | ||
db_esp32_comm.c db_comm.c db_crc.c tcp_server.c db_esp_now.c db_serial.c db_mavlink_msgs.c ota.c | ||
INCLUDE_DIRS "." "ota.h") | ||
|
||
if(CONFIG_WEB_DEPLOY_SF) | ||
set(WEB_SRC_DIR "${CMAKE_BINARY_DIR}/frontend") | ||
spiffs_create_partition_image(www ${WEB_SRC_DIR} FLASH_IN_PROJECT DEPENDS frontend) | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "ota.h" | ||
#include "esp_log.h" | ||
#include "esp_ota_ops.h" | ||
#include "esp_http_client.h" | ||
|
||
static const char *TAG = "OTA"; | ||
|
||
void ota_update_task(void *pvParameter) { | ||
char *ota_write_data = (char *)pvParameter; | ||
esp_err_t err; | ||
esp_ota_handle_t update_handle = 0; | ||
const esp_partition_t *update_partition = esp_ota_get_next_update_partition(NULL); | ||
ESP_LOGI(TAG, "Starting OTA update"); | ||
|
||
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle); | ||
if (err != ESP_OK) { | ||
ESP_LOGE(TAG, "esp_ota_begin failed (%s)", esp_err_to_name(err)); | ||
vTaskDelete(NULL); | ||
return; | ||
} | ||
|
||
err = esp_ota_write(update_handle, (const void *)ota_write_data, strlen(ota_write_data)); | ||
if (err != ESP_OK) { | ||
ESP_LOGE(TAG, "esp_ota_write failed (%s)", esp_err_to_name(err)); | ||
esp_ota_end(update_handle); | ||
vTaskDelete(NULL); | ||
return; | ||
} | ||
|
||
err = esp_ota_end(update_handle); | ||
if (err != ESP_OK) { | ||
ESP_LOGE(TAG, "esp_ota_end failed (%s)", esp_err_to_name(err)); | ||
vTaskDelete(NULL); | ||
return; | ||
} | ||
|
||
err = esp_ota_set_boot_partition(update_partition); | ||
if (err != ESP_OK) { | ||
ESP_LOGE(TAG, "esp_ota_set_boot_partition failed (%s)", esp_err_to_name(err)); | ||
vTaskDelete(NULL); | ||
return; | ||
} | ||
|
||
ESP_LOGI(TAG, "OTA update successful, restarting..."); | ||
esp_restart(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef OTA_H | ||
#define OTA_H | ||
|
||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
#include "esp_system.h" | ||
#include "esp_ota_ops.h" | ||
#include "esp_log.h" | ||
|
||
void ota_update_task(void *pvParameter); | ||
|
||
#endif // OTA_H |