mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 12:37:01 +03:00
OTA werks... sort of!
This commit is contained in:
@@ -18,14 +18,15 @@
|
||||
#include <stdbool.h>
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "cmd_system.h"
|
||||
#include "esp_err.h"
|
||||
#include "tcpip_adapter.h"
|
||||
|
||||
#include "squeezelite-ota.h"
|
||||
|
||||
static const char *TAG = "squeezelite-ota";
|
||||
extern const uint8_t server_cert_pem_start[] asm("_binary_github_pem_start");
|
||||
extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end");
|
||||
extern bool wait_for_wifi();
|
||||
|
||||
#define OTA_URL_SIZE 256
|
||||
static char ota_status[31]={0};
|
||||
@@ -45,7 +46,7 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||
break;
|
||||
case HTTP_EVENT_ON_CONNECTED:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
|
||||
// strncpy(ota_status,"HTTP_EVENT_ON_CONNECTED",sizeof(ota_status)-1);
|
||||
// strncpy(ota_status,"HTTP_EVENT_ON_CONNECTED",sizsffeof(ota_status)-1);
|
||||
break;
|
||||
case HTTP_EVENT_HEADER_SENT:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
|
||||
@@ -53,10 +54,15 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||
break;
|
||||
case HTTP_EVENT_ON_HEADER:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, status_code=%d, key=%s, value=%s",esp_http_client_get_status_code(evt->client),evt->header_key, evt->header_value);
|
||||
// check for header Content-Length:2222240
|
||||
// convert to numeric and store in total bin size
|
||||
|
||||
//snprintf(ota_status,sizeof(ota_status)-1,"HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
|
||||
break;
|
||||
case HTTP_EVENT_ON_DATA:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, status_code=%d, len=%d",esp_http_client_get_status_code(evt->client), evt->data_len);
|
||||
//increment the total data received, then divide by the bin size and store as ota_pct
|
||||
|
||||
//snprintf(ota_status,sizeof(ota_status)-1, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
|
||||
break;
|
||||
case HTTP_EVENT_ON_FINISH:
|
||||
@@ -73,9 +79,8 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||
void ota_task(void *pvParameter)
|
||||
{
|
||||
char * bin_url=(char *)pvParameter;
|
||||
ESP_LOGI(TAG, "Starting OTA example");
|
||||
|
||||
esp_http_client_config_t config = {
|
||||
esp_http_client_config_t config = {
|
||||
.url = bin_url,
|
||||
.cert_pem = (char *)server_cert_pem_start,
|
||||
.event_handler = _http_event_handler,
|
||||
@@ -97,8 +102,10 @@ void ota_task(void *pvParameter)
|
||||
|
||||
void start_ota(const char * bin_url)
|
||||
{
|
||||
// Initialize NVS.
|
||||
esp_err_t err = nvs_flash_init();
|
||||
ESP_LOGW(TAG, "Called to update the firmware from url: %s",bin_url);
|
||||
#if RECOVERY_APPLICATION
|
||||
// Initialize NVS.
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
// todo: If we ever change the size of the nvs partition, we need to figure out a mechanism to enlarge the nvs.
|
||||
// 1.OTA app partition table has a smaller NVS partition size than the non-OTA
|
||||
@@ -114,4 +121,9 @@ void start_ota(const char * bin_url)
|
||||
|
||||
ESP_LOGI(TAG, "Starting ota: %s", urlPtr);
|
||||
xTaskCreate(&ota_task, "ota_task", 8192*3,(void *) urlPtr, 5, NULL);
|
||||
#else
|
||||
ESP_LOGW(TAG, "Rebooting to recovery to complete the installation");
|
||||
guided_factory();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
17
components/squeezelite-ota/squeezelite-ota.h
Normal file
17
components/squeezelite-ota/squeezelite-ota.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* squeezelite-ota.h
|
||||
*
|
||||
* Created on: 25 sept. 2019
|
||||
* Author: sle11
|
||||
*/
|
||||
|
||||
#ifndef COMPONENTS_SQUEEZELITE_OTA_SQUEEZELITE_OTA_H_
|
||||
#define COMPONENTS_SQUEEZELITE_OTA_SQUEEZELITE_OTA_H_
|
||||
|
||||
void start_ota(const char * bin_url);
|
||||
const char * ota_get_status();
|
||||
uint8_t ota_get_pct_complete();
|
||||
|
||||
|
||||
|
||||
#endif /* COMPONENTS_SQUEEZELITE_OTA_SQUEEZELITE_OTA_H_ */
|
||||
Reference in New Issue
Block a user