Skip to content

Commit

Permalink
Firmware: OTA works
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis960 committed Apr 4, 2024
1 parent 02b8f3c commit 7c0ef02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions ESPlant-Firmware/frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export async function isConnected(): Promise<WifiStatus> {
return Number(res);
}

export async function getConnectedNetwork(): Promise<{ ssid: string, status: WifiStatus }> {
export async function getConnectedNetwork(): Promise<{
ssid: string;
status: WifiStatus;
}> {
return await getDataFromEsp("/connectedNetwork");
}

Expand Down Expand Up @@ -177,7 +180,7 @@ export async function hardResetEsp() {
}

export async function updateFirmware(url: string) {
return await postDataToEsp("/update/firmware", url);
return await postDataToEsp("/update/firmware", { url });
}

export async function getUpdateFirmwareUrl(): Promise<{ url: string }> {
Expand Down
12 changes: 8 additions & 4 deletions ESPlant-Firmware/main/configuration_mode_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,18 @@ esp_err_t post_api_update_firmware_handler(httpd_req_t *req)

plantstore_setFirmwareUpdateUrl(url);

const char resp[] = "OK";
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);

esp_http_client_config_t config = {
.url = url,
.cert_pem = NULL,
.timeout_ms = 10000,
};
esp_https_ota_config_t ota_config;
ota_config.http_config = &config;
esp_https_ota_config_t ota_config = {
.http_config = &config,
.http_client_init_cb = NULL,
};
esp_https_ota_handle_t handle = NULL;
esp_err_t err = esp_https_ota_begin(&ota_config, &handle);
if (err != ESP_OK)
Expand All @@ -453,8 +458,6 @@ esp_err_t post_api_update_firmware_handler(httpd_req_t *req)
ESP_LOGE("OTA", "Failed to get image size (%d)", otaImageSize);
return ESP_FAIL;
}
const char resp[] = "OK";
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
while (1)
{
err = esp_https_ota_perform(handle);
Expand Down Expand Up @@ -484,6 +487,7 @@ esp_err_t post_api_update_firmware_handler(httpd_req_t *req)

ESP_LOGI("OTA", "OTA finished, restarting");
esp_restart();
return ESP_OK;
}

esp_err_t get_api_update_firmware_handler(httpd_req_t *req)
Expand Down
4 changes: 2 additions & 2 deletions ESPlant-Firmware/sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ CONFIG_HTTPD_PURGE_BUF_LEN=32
# ESP HTTPS OTA
#
# CONFIG_ESP_HTTPS_OTA_DECRYPT_CB is not set
# CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP is not set
CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP=y
# end of ESP HTTPS OTA

#
Expand Down Expand Up @@ -1872,7 +1872,7 @@ CONFIG_ESP_WIFI_SW_COEXIST_ENABLE=y
# CONFIG_EVENT_LOOP_PROFILING is not set
CONFIG_POST_EVENTS_FROM_ISR=y
CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
# CONFIG_OTA_ALLOW_HTTP is not set
CONFIG_OTA_ALLOW_HTTP=y
# CONFIG_ESP_SYSTEM_PD_FLASH is not set
CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y
# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set
Expand Down

0 comments on commit 7c0ef02

Please sign in to comment.