mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-10 05:27:01 +03:00
cmake ota leverage esp_http_client
This commit is contained in:
@@ -9,10 +9,3 @@ set_source_files_properties(display.c
|
|||||||
PROPERTIES COMPILE_FLAGS
|
PROPERTIES COMPILE_FLAGS
|
||||||
-Wno-format-overflow
|
-Wno-format-overflow
|
||||||
)
|
)
|
||||||
|
|
||||||
#target_link_libraries(${COMPONENT_LIB} PUBLIC
|
|
||||||
# -Wl,--whole-archive
|
|
||||||
# $<TARGET_PROPERTY,INTERFACE_LINK_LIBRARIES>
|
|
||||||
# -Wl,--no-whole-archive
|
|
||||||
#)
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ __attribute__( ( always_inline ) ) static inline void SwapInt( int* a, int* b )
|
|||||||
*a = Temp;
|
*a = Temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// un-comment if need to be instanciated for external callers
|
|
||||||
extern inline void IRAM_ATTR GDS_DrawPixelFast( struct GDS_Device* Device, int X, int Y, int Color );
|
|
||||||
extern inline void IRAM_ATTR GDS_DrawPixel( struct GDS_Device* Device, int X, int Y, int Color );
|
extern inline void IRAM_ATTR GDS_DrawPixel( struct GDS_Device* Device, int X, int Y, int Color );
|
||||||
|
|
||||||
void GDS_DrawHLine( struct GDS_Device* Device, int x, int y, int Width, int Color ) {
|
void GDS_DrawHLine( struct GDS_Device* Device, int x, int y, int Width, int Color ) {
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ void GDS_DrawHLine( struct GDS_Device* Device, int x, int y, int Width, int Colo
|
|||||||
void GDS_DrawVLine( struct GDS_Device* Device, int x, int y, int Height, int Color );
|
void GDS_DrawVLine( struct GDS_Device* Device, int x, int y, int Height, int Color );
|
||||||
void GDS_DrawLine( struct GDS_Device* Device, int x0, int y0, int x1, int y1, int Color );
|
void GDS_DrawLine( struct GDS_Device* Device, int x0, int y0, int x1, int y1, int Color );
|
||||||
void GDS_DrawBox( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color, bool Fill );
|
void GDS_DrawBox( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color, bool Fill );
|
||||||
|
void IRAM_ATTR GDS_DrawPixelExt( struct GDS_Device* Device, int X, int Y, int Color );
|
||||||
|
void IRAM_ATTR GDS_DrawPixelFastExt( struct GDS_Device* Device, int X, int Y, int Color );
|
||||||
// draw a bitmap with source 1-bit depth organized in column and col0 = bit7 of byte 0
|
// draw a bitmap with source 1-bit depth organized in column and col0 = bit7 of byte 0
|
||||||
void GDS_DrawBitmapCBR( struct GDS_Device* Device, uint8_t *Data, int Width, int Height, int Color);
|
void GDS_DrawBitmapCBR( struct GDS_Device* Device, uint8_t *Data, int Width, int Height, int Color);
|
||||||
|
|
||||||
|
|||||||
18
components/display/core/gds_draw_ext.c
Normal file
18
components/display/core/gds_draw_ext.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2017-2018 Tara Keeling
|
||||||
|
* 2020 Philippe G.
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gds_private.h"
|
||||||
|
#include "gds.h"
|
||||||
|
#include "gds_draw.h"
|
||||||
|
|
||||||
|
void IRAM_ATTR GDS_DrawPixelExt( struct GDS_Device* Device, int X, int Y, int Color ){
|
||||||
|
GDS_DrawPixel( Device, X, Y, Color );
|
||||||
|
}
|
||||||
|
void IRAM_ATTR GDS_DrawPixelFastExt( struct GDS_Device* Device, int X, int Y, int Color ){
|
||||||
|
GDS_DrawPixelFast( Device, X, Y, Color );
|
||||||
|
}
|
||||||
@@ -8,8 +8,5 @@ idf_component_register( SRCS
|
|||||||
INCLUDE_DIRS .
|
INCLUDE_DIRS .
|
||||||
REQUIRES nvs_flash
|
REQUIRES nvs_flash
|
||||||
PRIV_REQUIRES console app_update tools services spi_flash platform_config vfs pthread wifi-manager platform_config newlib telnet )
|
PRIV_REQUIRES console app_update tools services spi_flash platform_config vfs pthread wifi-manager platform_config newlib telnet )
|
||||||
|
target_link_libraries(${COMPONENT_LIB} "-Wl,--undefined=GDS_DrawPixelFast")
|
||||||
target_link_libraries(${COMPONENT_LIB} ${build_dir}/esp-idf/$<TARGET_PROPERTY:RECOVERY_PREFIX>/lib$<TARGET_PROPERTY:RECOVERY_PREFIX>.a )
|
target_link_libraries(${COMPONENT_LIB} ${build_dir}/esp-idf/$<TARGET_PROPERTY:RECOVERY_PREFIX>/lib$<TARGET_PROPERTY:RECOVERY_PREFIX>.a )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
idf_build_get_property(idf_path IDF_PATH)
|
idf_build_get_property(idf_path IDF_PATH)
|
||||||
idf_component_register( SRCS cmd_squeezelite.c
|
idf_component_register( SRCS cmd_squeezelite.c
|
||||||
INCLUDE_DIRS .
|
INCLUDE_DIRS .
|
||||||
PRIV_REQUIRES spi_flash bootloader_support partition_table bootloader_support console codecs squeezelite newlib pthread tools platform_config )
|
PRIV_REQUIRES spi_flash bootloader_support partition_table bootloader_support console codecs squeezelite newlib pthread tools platform_config display )
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=feof")
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=feof")
|
||||||
|
|||||||
@@ -203,7 +203,24 @@ esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_m
|
|||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
void messaging_post_message(messaging_types type,messaging_classes msg_class, char *fmt, ...){
|
esp_err_t messaging_type_to_err_type(messaging_types type){
|
||||||
|
switch (type) {
|
||||||
|
case MESSAGING_INFO:
|
||||||
|
return ESP_LOG_INFO;
|
||||||
|
break;
|
||||||
|
case MESSAGING_ERROR:
|
||||||
|
return ESP_LOG_ERROR;
|
||||||
|
break;
|
||||||
|
case MESSAGING_WARNING:
|
||||||
|
return ESP_LOG_WARN;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ESP_LOG_DEBUG;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ESP_LOG_DEBUG;
|
||||||
|
}
|
||||||
|
void messaging_post_message(messaging_types type,messaging_classes msg_class, const char *fmt, ...){
|
||||||
single_message_t * message=NULL;
|
single_message_t * message=NULL;
|
||||||
size_t msg_size=0;
|
size_t msg_size=0;
|
||||||
size_t ln =0;
|
size_t ln =0;
|
||||||
|
|||||||
@@ -26,7 +26,20 @@ typedef struct {
|
|||||||
cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
|
cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
|
||||||
messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name);
|
messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name);
|
||||||
esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_message_t * message, size_t message_size);
|
esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_message_t * message, size_t message_size);
|
||||||
void messaging_post_message(messaging_types type,messaging_classes msg_class, char * fmt, ...);
|
void messaging_post_message(messaging_types type,messaging_classes msg_class, const char * fmt, ...);
|
||||||
cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
|
cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
|
||||||
single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle);
|
single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle);
|
||||||
|
esp_err_t messaging_type_to_err_type(messaging_types type);
|
||||||
void messaging_service_init();
|
void messaging_service_init();
|
||||||
|
|
||||||
|
|
||||||
|
#define LOG_SEND(y, ...) \
|
||||||
|
{ \
|
||||||
|
ESP_LOG_LEVEL_LOCAL(messaging_type_to_err_type(y),TAG, ##__VA_ARGS__); \
|
||||||
|
messaging_post_message(y, MESSAGING_CLASS_SYSTEM, ##__VA_ARGS__); }
|
||||||
|
|
||||||
|
#define LOG_SEND_ERROR( ...) LOG_SEND(MESSAGING_ERROR,##__VA_ARGS__)
|
||||||
|
#define LOG_SEND_INFO( ...) LOG_SEND(MESSAGING_INFO,##__VA_ARGS__)
|
||||||
|
#define LOG_SEND_WARN( ...) LOG_SEND(MESSAGING_WARNING,##__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,5 +3,3 @@ idf_component_register(SRC_DIRS .
|
|||||||
REQUIRES app_update esp_https_ota
|
REQUIRES app_update esp_https_ota
|
||||||
PRIV_REQUIRES console tools display services platform_config spi_flash vfs console freertos platform_console
|
PRIV_REQUIRES console tools display services platform_config spi_flash vfs console freertos platform_console
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
CONDITIONS OF ANY KIND, either express or implied.
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
@@ -38,6 +39,7 @@
|
|||||||
#include "platform_esp32.h"
|
#include "platform_esp32.h"
|
||||||
|
|
||||||
extern const char * get_certificate();
|
extern const char * get_certificate();
|
||||||
|
#define IF_DISPLAY(x) if(display) { x; }
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1
|
#ifdef CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1
|
||||||
#define OTA_CORE 0
|
#define OTA_CORE 0
|
||||||
@@ -110,9 +112,7 @@ typedef struct _progress {
|
|||||||
} progress_t;
|
} progress_t;
|
||||||
|
|
||||||
static progress_t * loc_displayer_get_progress_dft(){
|
static progress_t * loc_displayer_get_progress_dft(){
|
||||||
if(!display){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int start_coord_offset=0;
|
int start_coord_offset=0;
|
||||||
static progress_t def={
|
static progress_t def={
|
||||||
.border_thickness = 2,
|
.border_thickness = 2,
|
||||||
@@ -121,9 +121,9 @@ static progress_t * loc_displayer_get_progress_dft(){
|
|||||||
};
|
};
|
||||||
def.bar_fill_height= def.bar_tot_height-(def.border_thickness*2);
|
def.bar_fill_height= def.bar_tot_height-(def.border_thickness*2);
|
||||||
def.border.x1=start_coord_offset+def.sides_margin;
|
def.border.x1=start_coord_offset+def.sides_margin;
|
||||||
def.border.x2=GDS_GetWidth(display)-def.sides_margin;
|
IF_DISPLAY(def.border.x2=GDS_GetWidth(display)-def.sides_margin);
|
||||||
// progress bar will be drawn at the bottom of the display
|
// progress bar will be drawn at the bottom of the display
|
||||||
def.border.y2= GDS_GetHeight(display)-def.border_thickness;
|
IF_DISPLAY( def.border.y2= GDS_GetHeight(display)-def.border_thickness);
|
||||||
def.border.y1= def.border.y2-def.bar_tot_height;
|
def.border.y1= def.border.y2-def.bar_tot_height;
|
||||||
def.border.width=def.border.x2-def.border.x1;
|
def.border.width=def.border.x2-def.border.x1;
|
||||||
def.border.height=def.border.y2-def.border.y1;
|
def.border.height=def.border.y2-def.border.y1;
|
||||||
@@ -188,10 +188,7 @@ void sendMessaging(messaging_types type,const char * fmt, ...){
|
|||||||
}
|
}
|
||||||
va_end(args);
|
va_end(args);
|
||||||
if(type!=MESSAGING_INFO){
|
if(type!=MESSAGING_INFO){
|
||||||
|
IF_DISPLAY(GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, msg_str));
|
||||||
if(display) {
|
|
||||||
GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, msg_str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_AddStringToObject(msg,"ota_dsc",str_or_unknown(msg_str));
|
cJSON_AddStringToObject(msg,"ota_dsc",str_or_unknown(msg_str));
|
||||||
@@ -203,19 +200,6 @@ void sendMessaging(messaging_types type,const char * fmt, ...){
|
|||||||
cJSON_free(msg);
|
cJSON_free(msg);
|
||||||
_printMemStats();
|
_printMemStats();
|
||||||
}
|
}
|
||||||
//esp_err_t decode_alloc_ota_message(single_message_t * message, char * ota_dsc, uint8_t * ota_pct ){
|
|
||||||
// if(!message || !message->message) return ESP_ERR_INVALID_ARG;
|
|
||||||
// cJSON * json = cJSON_Parse(message->message);
|
|
||||||
// if(!json) return ESP_FAIL;
|
|
||||||
// if(ota_dsc) {
|
|
||||||
// ota_dsc = strdup(cJSON_GetObjectItem(json, "ota_dsc")?cJSON_GetStringValue(cJSON_GetObjectItem(json, "ota_dsc")):"");
|
|
||||||
// }
|
|
||||||
// if(ota_pct){
|
|
||||||
// *ota_pct = cJSON_GetObjectItem(json, "ota_pct")?cJSON_GetObjectItem(json, "ota_pct")->valueint:0;
|
|
||||||
// }
|
|
||||||
// cJSON_free(json);
|
|
||||||
// return ESP_OK;
|
|
||||||
//}
|
|
||||||
|
|
||||||
static void __attribute__((noreturn)) task_fatal_error(void)
|
static void __attribute__((noreturn)) task_fatal_error(void)
|
||||||
{
|
{
|
||||||
@@ -227,6 +211,37 @@ static void __attribute__((noreturn)) task_fatal_error(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t handle_http_on_data(esp_http_client_event_t *evt){
|
||||||
|
|
||||||
|
int http_status= esp_http_client_get_status_code(evt->client);
|
||||||
|
static char * recv_ptr=NULL;
|
||||||
|
|
||||||
|
if(http_status == 200){
|
||||||
|
|
||||||
|
|
||||||
|
if(!ota_status.bOTAStarted)
|
||||||
|
{
|
||||||
|
if(ota_status.bOTAStarted) sendMessaging(MESSAGING_INFO,"Downloading firmware");
|
||||||
|
ota_status.bOTAStarted = true;
|
||||||
|
ota_status.total_image_len=esp_http_client_get_content_length(evt->client);
|
||||||
|
ota_status.bin_data= malloc(ota_status.total_image_len);
|
||||||
|
if(ota_status.bin_data==NULL){
|
||||||
|
sendMessaging(MESSAGING_ERROR,"Error: buffer alloc error");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
recv_ptr=ota_status.bin_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we're downloading the binary data file
|
||||||
|
if (!esp_http_client_is_chunked_response(evt->client)) {
|
||||||
|
memcpy(recv_ptr,evt->data,evt->data_len);
|
||||||
|
recv_ptr+=evt->data_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||||
{
|
{
|
||||||
// --------------
|
// --------------
|
||||||
@@ -245,41 +260,35 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
|||||||
// char *header_value For HTTP_EVENT_ON_HEADER event_id, it<69>s store current http header value
|
// char *header_value For HTTP_EVENT_ON_HEADER event_id, it<69>s store current http header value
|
||||||
// --------------
|
// --------------
|
||||||
switch (evt->event_id) {
|
switch (evt->event_id) {
|
||||||
|
|
||||||
case HTTP_EVENT_ERROR:
|
case HTTP_EVENT_ERROR:
|
||||||
ESP_LOGD(TAG, "HTTP_EVENT_ERROR");
|
ESP_LOGD(TAG, "HTTP_EVENT_ERROR");
|
||||||
_printMemStats();
|
_printMemStats();
|
||||||
//strncpy(ota_status,"HTTP_EVENT_ERROR",sizeof(ota_status)-1);
|
|
||||||
break;
|
break;
|
||||||
case HTTP_EVENT_ON_CONNECTED:
|
case HTTP_EVENT_ON_CONNECTED:
|
||||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
|
ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
|
||||||
|
if(ota_status.bOTAStarted) sendMessaging(MESSAGING_INFO,"HTTP Connected");
|
||||||
if(ota_status.bOTAStarted) sendMessaging(MESSAGING_INFO,"Connecting to URL...");
|
|
||||||
ota_status.total_image_len=0;
|
ota_status.total_image_len=0;
|
||||||
ota_status.actual_image_len=0;
|
ota_status.actual_image_len=0;
|
||||||
ota_status.lastpct=0;
|
ota_status.lastpct=0;
|
||||||
ota_status.remain_image_len=0;
|
ota_status.remain_image_len=0;
|
||||||
ota_status.newpct=0;
|
ota_status.newpct=0;
|
||||||
gettimeofday(&ota_status.OTA_start, NULL);
|
gettimeofday(&ota_status.OTA_start, NULL);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case HTTP_EVENT_HEADER_SENT:
|
case HTTP_EVENT_HEADER_SENT:
|
||||||
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
|
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
|
||||||
break;
|
break;
|
||||||
case HTTP_EVENT_ON_HEADER:
|
case HTTP_EVENT_ON_HEADER:
|
||||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s",evt->header_key, evt->header_value);
|
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s",evt->header_key, evt->header_value);
|
||||||
if (strcasecmp(evt->header_key, "location") == 0) {
|
// if (strcasecmp(evt->header_key, "location") == 0) {
|
||||||
ESP_LOGW(TAG,"OTA will redirect to url: %s",evt->header_value);
|
// ESP_LOGW(TAG,"OTA will redirect to url: %s",evt->header_value);
|
||||||
}
|
// }
|
||||||
if (strcasecmp(evt->header_key, "content-length") == 0) {
|
// if (strcasecmp(evt->header_key, "content-length") == 0) {
|
||||||
ota_status.total_image_len = atol(evt->header_value);
|
// ota_status.total_image_len = atol(evt->header_value);
|
||||||
ESP_LOGW(TAG, "Content length found: %s, parsed to %d", evt->header_value, ota_status.total_image_len);
|
// ESP_LOGW(TAG, "Content length found: %s, parsed to %d", evt->header_value, ota_status.total_image_len);
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
case HTTP_EVENT_ON_DATA:
|
case HTTP_EVENT_ON_DATA:
|
||||||
if(!ota_status.bOTAStarted) {
|
return handle_http_on_data(evt);
|
||||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, status_code=%d, len=%d",esp_http_client_get_status_code(evt->client), evt->data_len);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case HTTP_EVENT_ON_FINISH:
|
case HTTP_EVENT_ON_FINISH:
|
||||||
ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH");
|
ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH");
|
||||||
@@ -318,12 +327,14 @@ esp_err_t init_config(ota_thread_parms_t * p_ota_thread_parms){
|
|||||||
case OTA_TYPE_HTTP:
|
case OTA_TYPE_HTTP:
|
||||||
http_client_config.cert_pem =get_certificate();
|
http_client_config.cert_pem =get_certificate();
|
||||||
http_client_config.event_handler = _http_event_handler;
|
http_client_config.event_handler = _http_event_handler;
|
||||||
http_client_config.disable_auto_redirect=true;
|
http_client_config.disable_auto_redirect=false;
|
||||||
http_client_config.skip_cert_common_name_check = false;
|
http_client_config.skip_cert_common_name_check = false;
|
||||||
http_client_config.url = strdup(p_ota_thread_parms->url);
|
http_client_config.url = strdup(p_ota_thread_parms->url);
|
||||||
http_client_config.max_redirection_count = 3;
|
http_client_config.max_redirection_count = 4;
|
||||||
// buffer size below is for http read chunks
|
// buffer size below is for http read chunks
|
||||||
http_client_config.buffer_size = 1024 ;
|
http_client_config.buffer_size = 8192; //1024 ;
|
||||||
|
http_client_config.buffer_size_tx = 8192;
|
||||||
|
//http_client_config.timeout_ms = 5000;
|
||||||
break;
|
break;
|
||||||
case OTA_TYPE_BUFFER:
|
case OTA_TYPE_BUFFER:
|
||||||
ota_status.bin_data = p_ota_thread_parms->bin;
|
ota_status.bin_data = p_ota_thread_parms->bin;
|
||||||
@@ -409,100 +420,6 @@ esp_err_t _erase_last_boot_app_partition(const esp_partition_t *ota_partition)
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool process_again(int status_code)
|
|
||||||
{
|
|
||||||
switch (status_code) {
|
|
||||||
case HttpStatus_MovedPermanently:
|
|
||||||
case HttpStatus_Found:
|
|
||||||
case HttpStatus_Unauthorized:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client, int status_code)
|
|
||||||
{
|
|
||||||
esp_err_t err=ESP_OK;
|
|
||||||
if (status_code == HttpStatus_MovedPermanently || status_code == HttpStatus_Found ) {
|
|
||||||
ESP_LOGW(TAG, "Handling HTTP redirection. ");
|
|
||||||
err = esp_http_client_set_redirection(http_client);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "URL redirection Failed. %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
ESP_LOGW(TAG, "Done Handling HTTP redirection. ");
|
|
||||||
|
|
||||||
} else if (status_code == HttpStatus_Unauthorized) {
|
|
||||||
ESP_LOGW(TAG, "Handling Unauthorized. ");
|
|
||||||
esp_http_client_add_auth(http_client);
|
|
||||||
}
|
|
||||||
ESP_LOGD(TAG, "Redirection done, checking if we need to read the data. ");
|
|
||||||
if (process_again(status_code)) {
|
|
||||||
//ESP_LOGD(TAG, "We have to read some more data. Allocating buffer size %u",ota_config.buffer_size+1);
|
|
||||||
//char * local_buff = heap_caps_malloc(ota_status.buffer_size+1, (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT));
|
|
||||||
|
|
||||||
// if(local_buff==NULL){
|
|
||||||
// ESP_LOGE(TAG,"Failed to allocate internal memory buffer for http processing");
|
|
||||||
// return ESP_ERR_NO_MEM;
|
|
||||||
// }
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
ESP_LOGD(TAG, "Reading data chunk. ");
|
|
||||||
int data_read = esp_http_client_read(http_client, ota_status.ota_write_data, ota_status.buffer_size);
|
|
||||||
if (data_read < 0) {
|
|
||||||
ESP_LOGE(TAG, "Error: SSL data read error");
|
|
||||||
err= ESP_FAIL;
|
|
||||||
break;
|
|
||||||
} else if (data_read == 0) {
|
|
||||||
ESP_LOGD(TAG, "No more data. ");
|
|
||||||
err= ESP_OK;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//FREE_RESET(local_buff);
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
static esp_err_t _http_connect(esp_http_client_handle_t http_client)
|
|
||||||
{
|
|
||||||
esp_err_t err = ESP_FAIL;
|
|
||||||
int status_code, header_ret;
|
|
||||||
do {
|
|
||||||
ESP_LOGI(TAG, "connecting the http client. ");
|
|
||||||
err = esp_http_client_open(http_client, 0);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
|
|
||||||
sendMessaging(MESSAGING_ERROR,"Failed to open HTTP connection: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "Fetching headers");
|
|
||||||
header_ret = esp_http_client_fetch_headers(http_client);
|
|
||||||
if (header_ret < 0) {
|
|
||||||
// Error found
|
|
||||||
sendMessaging(MESSAGING_ERROR,"Header fetch failed");
|
|
||||||
return header_ret;
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "HTTP Header fetch completed, found content length of %d",header_ret);
|
|
||||||
status_code = esp_http_client_get_status_code(http_client);
|
|
||||||
ESP_LOGD(TAG, "HTTP status code was %d",status_code);
|
|
||||||
|
|
||||||
err = _http_handle_response_code(http_client, status_code);
|
|
||||||
if (err != ESP_OK) {
|
|
||||||
sendMessaging(MESSAGING_ERROR,"HTTP connect error: %s", esp_err_to_name(err));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (process_again(status_code));
|
|
||||||
|
|
||||||
if(status_code >=400 && status_code <=900){
|
|
||||||
sendMessaging(MESSAGING_ERROR,"Error: HTTP Status %d",status_code);
|
|
||||||
err=ESP_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
void ota_task_cleanup(const char * message, ...){
|
void ota_task_cleanup(const char * message, ...){
|
||||||
ota_status.bOTAThreadStarted=false;
|
ota_status.bOTAThreadStarted=false;
|
||||||
loc_displayer_progressbar(0);
|
loc_displayer_progressbar(0);
|
||||||
@@ -522,35 +439,26 @@ void ota_task_cleanup(const char * message, ...){
|
|||||||
task_fatal_error();
|
task_fatal_error();
|
||||||
}
|
}
|
||||||
esp_err_t ota_buffer_all(){
|
esp_err_t ota_buffer_all(){
|
||||||
int data_read=0;
|
|
||||||
esp_err_t err=ESP_OK;
|
esp_err_t err=ESP_OK;
|
||||||
if (ota_status.ota_type == OTA_TYPE_HTTP){
|
if (ota_status.ota_type == OTA_TYPE_HTTP){
|
||||||
GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Downloading file");
|
IF_DISPLAY(GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Downloading file"));
|
||||||
ota_http_client = esp_http_client_init(&http_client_config);
|
ota_http_client = esp_http_client_init(&http_client_config);
|
||||||
if (ota_http_client == NULL) {
|
if (ota_http_client == NULL) {
|
||||||
sendMessaging(MESSAGING_ERROR,"Error: Failed to initialize HTTP connection.");
|
sendMessaging(MESSAGING_ERROR,"Error: Failed to initialize HTTP connection.");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
_printMemStats();
|
_printMemStats();
|
||||||
// Open the http connection and follow any redirection
|
err = esp_http_client_perform(ota_http_client);
|
||||||
err = _http_connect(ota_http_client);
|
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
return err;
|
sendMessaging(MESSAGING_ERROR,"Error: Failed to execute HTTP download. %s",esp_err_to_name(err));
|
||||||
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ota_status.total_image_len<=0){
|
if(ota_status.total_image_len<=0){
|
||||||
sendMessaging(MESSAGING_ERROR,"Error: Invalid image length");
|
sendMessaging(MESSAGING_ERROR,"Error: Invalid image length");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
ota_status.bin_data= malloc(ota_status.total_image_len);
|
sendMessaging(MESSAGING_INFO,"Download success");
|
||||||
if(ota_status.bin_data==NULL){
|
|
||||||
sendMessaging(MESSAGING_ERROR,"Error: buffer alloc error");
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
data_read = esp_http_client_read(ota_http_client, ota_status.bin_data, ota_status.total_image_len);
|
|
||||||
if(data_read != ota_status.total_image_len){
|
|
||||||
sendMessaging(MESSAGING_ERROR,"Error: Binary incomplete");
|
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gettimeofday(&ota_status.OTA_start, NULL);
|
gettimeofday(&ota_status.OTA_start, NULL);
|
||||||
@@ -605,7 +513,7 @@ esp_err_t ota_header_check(){
|
|||||||
if (esp_ota_get_partition_description(ota_status.running, &running_app_info) == ESP_OK) {
|
if (esp_ota_get_partition_description(ota_status.running, &running_app_info) == ESP_OK) {
|
||||||
ESP_LOGI(TAG, "Running recovery version: %s", running_app_info.version);
|
ESP_LOGI(TAG, "Running recovery version: %s", running_app_info.version);
|
||||||
}
|
}
|
||||||
|
sendMessaging(MESSAGING_INFO,"New version is : %s",new_app_info.version);
|
||||||
esp_app_desc_t invalid_app_info;
|
esp_app_desc_t invalid_app_info;
|
||||||
if (esp_ota_get_partition_description(ota_status.last_invalid_app, &invalid_app_info) == ESP_OK) {
|
if (esp_ota_get_partition_description(ota_status.last_invalid_app, &invalid_app_info) == ESP_OK) {
|
||||||
ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version);
|
ESP_LOGI(TAG, "Last invalid firmware version: %s", invalid_app_info.version);
|
||||||
@@ -626,10 +534,10 @@ void ota_task(void *pvParameter)
|
|||||||
{
|
{
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
int data_read = 0;
|
int data_read = 0;
|
||||||
GDS_TextSetFont(display,2,GDS_GetHeight(display)>32?&Font_droid_sans_fallback_15x17:&Font_droid_sans_fallback_11x13,-2);
|
IF_DISPLAY(GDS_TextSetFont(display,2,GDS_GetHeight(display)>32?&Font_droid_sans_fallback_15x17:&Font_droid_sans_fallback_11x13,-2))
|
||||||
GDS_ClearExt(display, true);
|
IF_DISPLAY( GDS_ClearExt(display, true));
|
||||||
GDS_TextLine(display, 1, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Firmware update");
|
IF_DISPLAY(GDS_TextLine(display, 1, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Firmware update"));
|
||||||
GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Initializing");
|
IF_DISPLAY(GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Initializing"));
|
||||||
loc_displayer_progressbar(0);
|
loc_displayer_progressbar(0);
|
||||||
ESP_LOGD(TAG, "HTTP ota Thread started");
|
ESP_LOGD(TAG, "HTTP ota Thread started");
|
||||||
_printMemStats();
|
_printMemStats();
|
||||||
@@ -644,7 +552,6 @@ void ota_task(void *pvParameter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_printMemStats();
|
_printMemStats();
|
||||||
ota_status.bOTAStarted = true;
|
|
||||||
sendMessaging(MESSAGING_INFO,"Starting OTA...");
|
sendMessaging(MESSAGING_INFO,"Starting OTA...");
|
||||||
err=ota_buffer_all();
|
err=ota_buffer_all();
|
||||||
if(err!=ESP_OK){
|
if(err!=ESP_OK){
|
||||||
@@ -652,16 +559,16 @@ void ota_task(void *pvParameter)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(ota_header_check()!=ESP_OK){
|
if(ota_header_check()!=ESP_OK){
|
||||||
ota_task_cleanup(NULL);
|
ota_task_cleanup(NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Locate and erase ota application partition */
|
/* Locate and erase ota application partition */
|
||||||
ESP_LOGW(TAG,"**************** Expecting WATCHDOG errors below during flash erase. This is OK and not to worry about **************** ");
|
|
||||||
GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Formatting partition");
|
|
||||||
sendMessaging(MESSAGING_INFO,"Formatting OTA partition");
|
sendMessaging(MESSAGING_INFO,"Formatting OTA partition");
|
||||||
|
ESP_LOGW(TAG,"**************** Expecting WATCHDOG errors below during flash erase. This is OK and not to worry about **************** ");
|
||||||
|
IF_DISPLAY(GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Formatting partition"));
|
||||||
|
|
||||||
_printMemStats();
|
_printMemStats();
|
||||||
err=_erase_last_boot_app_partition(ota_status.ota_partition);
|
err=_erase_last_boot_app_partition(ota_status.ota_partition);
|
||||||
if(err!=ESP_OK){
|
if(err!=ESP_OK){
|
||||||
@@ -681,7 +588,7 @@ void ota_task(void *pvParameter)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "esp_ota_begin succeeded");
|
ESP_LOGD(TAG, "esp_ota_begin succeeded");
|
||||||
GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Writing image...");
|
IF_DISPLAY(GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Writing image..."));
|
||||||
while (ota_status.remain_image_len>0) {
|
while (ota_status.remain_image_len>0) {
|
||||||
|
|
||||||
data_read = ota_buffer_read();
|
data_read = ota_buffer_read();
|
||||||
@@ -730,9 +637,9 @@ void ota_task(void *pvParameter)
|
|||||||
if (err == ESP_OK) {
|
if (err == ESP_OK) {
|
||||||
ESP_LOGI(TAG,"OTA Process completed successfully!");
|
ESP_LOGI(TAG,"OTA Process completed successfully!");
|
||||||
sendMessaging(MESSAGING_INFO,"Success!");
|
sendMessaging(MESSAGING_INFO,"Success!");
|
||||||
GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Success!");
|
IF_DISPLAY(GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Success!"));
|
||||||
vTaskDelay(1500/ portTICK_PERIOD_MS); // wait here to give the UI a chance to refresh
|
vTaskDelay(1500/ portTICK_PERIOD_MS); // wait here to give the UI a chance to refresh
|
||||||
GDS_Clear(display,GDS_COLOR_BLACK);
|
IF_DISPLAY(GDS_Clear(display,GDS_COLOR_BLACK));
|
||||||
esp_restart();
|
esp_restart();
|
||||||
} else {
|
} else {
|
||||||
ota_task_cleanup("Error: Unable to update boot partition [%s]",esp_err_to_name(err));
|
ota_task_cleanup("Error: Unable to update boot partition [%s]",esp_err_to_name(err));
|
||||||
|
|||||||
@@ -595,7 +595,7 @@ void draw_VU(struct GDS_Device * display, const uint8_t *data, int level, int x,
|
|||||||
// use "fast" version as we are not beyond screen boundaries
|
// use "fast" version as we are not beyond screen boundaries
|
||||||
for (int r = 0; r < width; r++) {
|
for (int r = 0; r < width; r++) {
|
||||||
for (int c = 0; c < VU_HEIGHT; c++) {
|
for (int c = 0; c < VU_HEIGHT; c++) {
|
||||||
GDS_DrawPixelFast(display, r + x, c + y, *data++ >> scale);
|
GDS_DrawPixelFastExt(display, r + x, c + y, *data++ >> scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ idf_component_register( SRC_DIRS .
|
|||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#add_definitions(-DLOG_LOCAL_LEVEL=ESP_LOG_INFO)
|
||||||
@@ -671,7 +671,7 @@ function getMessages() {
|
|||||||
if (ota_data.hasOwnProperty('ota_dsc') && ota_data['ota_dsc'] != ''){
|
if (ota_data.hasOwnProperty('ota_dsc') && ota_data['ota_dsc'] != ''){
|
||||||
otadsc = ota_data['ota_dsc'];
|
otadsc = ota_data['ota_dsc'];
|
||||||
$("span#flash-status").html(otadsc);
|
$("span#flash-status").html(otadsc);
|
||||||
if (otadsc.match(/Error:/) || otapct > 95) {
|
if (msg.type =="MESSAGING_ERROR" || otapct > 95) {
|
||||||
blockFlashButton = false;
|
blockFlashButton = false;
|
||||||
enableStatusTimer = true;
|
enableStatusTimer = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function to process requests, decode URLs, serve files, etc. etc.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "http_server_handlers.h"
|
#include "http_server_handlers.h"
|
||||||
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
|
|
||||||
#include "esp_http_server.h"
|
#include "esp_http_server.h"
|
||||||
#include "cmd_system.h"
|
#include "cmd_system.h"
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|||||||
@@ -271,7 +271,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<h2>Firmware URL:</h2>
|
<h2>Firmware URL:</h2>
|
||||||
<textarea id="fwurl" maxlength="350"></textarea>
|
<textarea id="fwurl" maxlength="1000"></textarea>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<input type="button" id="flash" class="btn btn-danger" value="Flash!" /><span id="flash-status"></span>
|
<input type="button" id="flash" class="btn btn-danger" value="Flash!" /><span id="flash-status"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
41
github.pem
41
github.pem
@@ -1,41 +0,0 @@
|
|||||||
-----BEGIN CERTIFICATE-----
|
|
||||||
MIIHQjCCBiqgAwIBAgIQCgYwQn9bvO1pVzllk7ZFHzANBgkqhkiG9w0BAQsFADB1
|
|
||||||
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
|
|
||||||
d3cuZGlnaWNlcnQuY29tMTQwMgYDVQQDEytEaWdpQ2VydCBTSEEyIEV4dGVuZGVk
|
|
||||||
IFZhbGlkYXRpb24gU2VydmVyIENBMB4XDTE4MDUwODAwMDAwMFoXDTIwMDYwMzEy
|
|
||||||
MDAwMFowgccxHTAbBgNVBA8MFFByaXZhdGUgT3JnYW5pemF0aW9uMRMwEQYLKwYB
|
|
||||||
BAGCNzwCAQMTAlVTMRkwFwYLKwYBBAGCNzwCAQITCERlbGF3YXJlMRAwDgYDVQQF
|
|
||||||
Ewc1MTU3NTUwMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQG
|
|
||||||
A1UEBxMNU2FuIEZyYW5jaXNjbzEVMBMGA1UEChMMR2l0SHViLCBJbmMuMRMwEQYD
|
|
||||||
VQQDEwpnaXRodWIuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
|
|
||||||
xjyq8jyXDDrBTyitcnB90865tWBzpHSbindG/XqYQkzFMBlXmqkzC+FdTRBYyneZ
|
|
||||||
w5Pz+XWQvL+74JW6LsWNc2EF0xCEqLOJuC9zjPAqbr7uroNLghGxYf13YdqbG5oj
|
|
||||||
/4x+ogEG3dF/U5YIwVr658DKyESMV6eoYV9mDVfTuJastkqcwero+5ZAKfYVMLUE
|
|
||||||
sMwFtoTDJFmVf6JlkOWwsxp1WcQ/MRQK1cyqOoUFUgYylgdh3yeCDPeF22Ax8AlQ
|
|
||||||
xbcaI+GwfQL1FB7Jy+h+KjME9lE/UpgV6Qt2R1xNSmvFCBWu+NFX6epwFP/JRbkM
|
|
||||||
fLz0beYFUvmMgLtwVpEPSwIDAQABo4IDeTCCA3UwHwYDVR0jBBgwFoAUPdNQpdag
|
|
||||||
re7zSmAKZdMh1Pj41g8wHQYDVR0OBBYEFMnCU2FmnV+rJfQmzQ84mqhJ6kipMCUG
|
|
||||||
A1UdEQQeMByCCmdpdGh1Yi5jb22CDnd3dy5naXRodWIuY29tMA4GA1UdDwEB/wQE
|
|
||||||
AwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwdQYDVR0fBG4wbDA0
|
|
||||||
oDKgMIYuaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL3NoYTItZXYtc2VydmVyLWcy
|
|
||||||
LmNybDA0oDKgMIYuaHR0cDovL2NybDQuZGlnaWNlcnQuY29tL3NoYTItZXYtc2Vy
|
|
||||||
dmVyLWcyLmNybDBLBgNVHSAERDBCMDcGCWCGSAGG/WwCATAqMCgGCCsGAQUFBwIB
|
|
||||||
FhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMAcGBWeBDAEBMIGIBggrBgEF
|
|
||||||
BQcBAQR8MHowJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2ljZXJ0LmNvbTBS
|
|
||||||
BggrBgEFBQcwAoZGaHR0cDovL2NhY2VydHMuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0
|
|
||||||
U0hBMkV4dGVuZGVkVmFsaWRhdGlvblNlcnZlckNBLmNydDAMBgNVHRMBAf8EAjAA
|
|
||||||
MIIBfgYKKwYBBAHWeQIEAgSCAW4EggFqAWgAdgCkuQmQtBhYFIe7E6LMZ3AKPDWY
|
|
||||||
BPkb37jjd80OyA3cEAAAAWNBYm0KAAAEAwBHMEUCIQDRZp38cTWsWH2GdBpe/uPT
|
|
||||||
Wnsu/m4BEC2+dIcvSykZYgIgCP5gGv6yzaazxBK2NwGdmmyuEFNSg2pARbMJlUFg
|
|
||||||
U5UAdgBWFAaaL9fC7NP14b1Esj7HRna5vJkRXMDvlJhV1onQ3QAAAWNBYm0tAAAE
|
|
||||||
AwBHMEUCIQCi7omUvYLm0b2LobtEeRAYnlIo7n6JxbYdrtYdmPUWJQIgVgw1AZ51
|
|
||||||
vK9ENinBg22FPxb82TvNDO05T17hxXRC2IYAdgC72d+8H4pxtZOUI5eqkntHOFeV
|
|
||||||
CqtS6BqQlmQ2jh7RhQAAAWNBYm3fAAAEAwBHMEUCIQChzdTKUU2N+XcqcK0OJYrN
|
|
||||||
8EYynloVxho4yPk6Dq3EPgIgdNH5u8rC3UcslQV4B9o0a0w204omDREGKTVuEpxG
|
|
||||||
eOQwDQYJKoZIhvcNAQELBQADggEBAHAPWpanWOW/ip2oJ5grAH8mqQfaunuCVE+v
|
|
||||||
ac+88lkDK/LVdFgl2B6kIHZiYClzKtfczG93hWvKbST4NRNHP9LiaQqdNC17e5vN
|
|
||||||
HnXVUGw+yxyjMLGqkgepOnZ2Rb14kcTOGp4i5AuJuuaMwXmCo7jUwPwfLe1NUlVB
|
|
||||||
Kqg6LK0Hcq4K0sZnxE8HFxiZ92WpV2AVWjRMEc/2z2shNoDvxvFUYyY1Oe67xINk
|
|
||||||
myQKc+ygSBZzyLnXSFVWmHr3u5dcaaQGGAR42v6Ydr4iL38Hd4dOiBma+FXsXBIq
|
|
||||||
WUjbST4VXmdaol7uzFMojA4zkxQDZAvF5XgJlAFadfySna/teik=
|
|
||||||
-----END CERTIFICATE-----
|
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
idf_component_register(SRC_DIRS .
|
idf_component_register(SRC_DIRS .
|
||||||
PRIV_REQUIRES esp_common display wifi-manager pthread squeezelite-ota platform_console telnet
|
PRIV_REQUIRES esp_common wifi-manager pthread squeezelite-ota platform_console telnet display
|
||||||
INCLUDE_DIRS .
|
INCLUDE_DIRS .
|
||||||
EMBED_FILES ../server_certs/github.pem
|
EMBED_FILES ../server_certs/github.pem
|
||||||
)
|
)
|
||||||
|
#get_target_property(ill ${COMPONENT_LIB} INTERFACE_LINK_LIBRARIES)
|
||||||
|
#message("${COMPONENT_LIB} INTERFACE_LINK_LIBRARIES = ${ill}")
|
||||||
|
|
||||||
|
|||||||
@@ -144,9 +144,9 @@ esp_log_level_t get_log_level_from_char(char * level){
|
|||||||
void set_log_level(char * tag, char * level){
|
void set_log_level(char * tag, char * level){
|
||||||
esp_log_level_set(tag, get_log_level_from_char(level));
|
esp_log_level_set(tag, get_log_level_from_char(level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
esp_err_t update_certificates(){
|
esp_err_t update_certificates(){
|
||||||
// server_cert_pem_start
|
|
||||||
// server_cert_pem_end
|
|
||||||
|
|
||||||
nvs_handle handle;
|
nvs_handle handle;
|
||||||
esp_err_t esp_err;
|
esp_err_t esp_err;
|
||||||
@@ -155,28 +155,29 @@ esp_err_t update_certificates(){
|
|||||||
ESP_LOGI(TAG, "About to check if certificates need to be updated in flash");
|
ESP_LOGI(TAG, "About to check if certificates need to be updated in flash");
|
||||||
esp_err = nvs_open_from_partition(settings_partition, certs_namespace, NVS_READWRITE, &handle);
|
esp_err = nvs_open_from_partition(settings_partition, certs_namespace, NVS_READWRITE, &handle);
|
||||||
if (esp_err != ESP_OK) {
|
if (esp_err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Unable to open name namespace %s. Error %s", certs_namespace, esp_err_to_name(esp_err));
|
LOG_SEND(MESSAGING_INFO,"Unable to update HTTPS certificates. Could not open NVS namespace %s. Error %s", certs_namespace, esp_err_to_name(esp_err));
|
||||||
return esp_err;
|
return esp_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
const esp_partition_t *running = esp_ota_get_running_partition();
|
const esp_partition_t *running = esp_ota_get_running_partition();
|
||||||
if(running->subtype !=ESP_PARTITION_SUBTYPE_APP_FACTORY ){
|
if(running->subtype !=ESP_PARTITION_SUBTYPE_APP_FACTORY ){
|
||||||
ESP_LOGI(TAG, "Running partition [%s] type %d subtype %d (offset 0x%08x)", running->label, running->type, running->subtype, running->address);
|
ESP_LOGI(TAG, "Running partition [%s] type %d subtype %d (offset 0x%08x)", running->label, running->type, running->subtype, running->address);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) {
|
if (esp_ota_get_partition_description(running, &running_app_info) == ESP_OK) {
|
||||||
ESP_LOGI(TAG, "Running version: %s", running_app_info.version);
|
ESP_LOGI(TAG, "Running version: %s", running_app_info.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t len=0;
|
size_t len=0;
|
||||||
char *str=NULL;
|
char *str=NULL;
|
||||||
bool changed=false;
|
bool changed=false;
|
||||||
if ( (esp_err= nvs_get_str(handle, certs_version, NULL, &len)) == ESP_OK) {
|
if ( (esp_err= nvs_get_str(handle, certs_version, NULL, &len)) == ESP_OK) {
|
||||||
str=(char *)malloc(len);
|
str=(char *)malloc(len+1);
|
||||||
|
if(str){
|
||||||
|
memset(str,0x00,len+1);
|
||||||
if ( (esp_err = nvs_get_str(handle, certs_version, str, &len)) == ESP_OK) {
|
if ( (esp_err = nvs_get_str(handle, certs_version, str, &len)) == ESP_OK) {
|
||||||
ESP_LOGI(TAG,"String associated with key '%s' is %s", certs_version, str);
|
ESP_LOGI(TAG,"Certificate version: %s", str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(str!=NULL){
|
if(str!=NULL){
|
||||||
@@ -196,18 +197,20 @@ esp_err_t update_certificates(){
|
|||||||
|
|
||||||
esp_err = nvs_set_blob(handle, certs_key, server_cert_pem_start, (server_cert_pem_end-server_cert_pem_start));
|
esp_err = nvs_set_blob(handle, certs_key, server_cert_pem_start, (server_cert_pem_end-server_cert_pem_start));
|
||||||
if(esp_err!=ESP_OK){
|
if(esp_err!=ESP_OK){
|
||||||
ESP_LOGE(TAG, "Failed to store certificate data: %s", esp_err_to_name(esp_err));
|
LOG_SEND_ERROR("Failed to store certificate data: %s", esp_err_to_name(esp_err));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ESP_LOGI(TAG,"Updated stored https certificates");
|
|
||||||
esp_err = nvs_set_str(handle, certs_version, running_app_info.version);
|
esp_err = nvs_set_str(handle, certs_version, running_app_info.version);
|
||||||
if(esp_err!=ESP_OK){
|
if(esp_err!=ESP_OK){
|
||||||
ESP_LOGE(TAG, "Failed to store app version: %s", esp_err_to_name(esp_err));
|
LOG_SEND_ERROR("Unable to update HTTPS Certificates version: %s",esp_err_to_name(esp_err));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
esp_err = nvs_commit(handle);
|
esp_err = nvs_commit(handle);
|
||||||
if(esp_err!=ESP_OK){
|
if(esp_err!=ESP_OK){
|
||||||
ESP_LOGE(TAG, "Failed to commit certificate changes: %s", esp_err_to_name(esp_err));
|
LOG_SEND_ERROR("Failed to commit certificates changes : %s",esp_err_to_name(esp_err));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG_SEND_INFO("HTTPS Certificates were updated with version: %s",running_app_info.version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,19 +230,27 @@ const char * get_certificate(){
|
|||||||
size_t len;
|
size_t len;
|
||||||
esp_err = nvs_get_blob(handle, certs_key, NULL, &len);
|
esp_err = nvs_get_blob(handle, certs_key, NULL, &len);
|
||||||
if( esp_err == ESP_OK) {
|
if( esp_err == ESP_OK) {
|
||||||
blob = (char *)malloc(len);
|
blob = (char *)malloc(len+1);
|
||||||
|
if(!blob){
|
||||||
|
LOG_SEND_ERROR("Unable to retrieve HTTPS certificates. %s","Memory allocation failed");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
memset(blob,0x00,len+1);
|
||||||
esp_err = nvs_get_blob(handle, certs_key, blob, &len);
|
esp_err = nvs_get_blob(handle, certs_key, blob, &len);
|
||||||
if ( esp_err == ESP_OK) {
|
if ( esp_err == ESP_OK) {
|
||||||
printf("Blob associated with key '%s' is %d bytes long: \n", certs_key, len);
|
ESP_LOGD(TAG,"Certificates content is %d bytes long: ", len);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG_SEND_ERROR("Unable to retrieve HTTPS certificates. Get blob failed: %s", esp_err_to_name(esp_err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ESP_LOGE(TAG, "Unable to get the existing blob from namespace %s. [%s]", certs_namespace, esp_err_to_name(esp_err));
|
LOG_SEND_ERROR("Unable to retrieve HTTPS certificates. Get blob failed: %s",esp_err_to_name(esp_err));
|
||||||
}
|
}
|
||||||
nvs_close(handle);
|
nvs_close(handle);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ESP_LOGE(TAG, "Unable to open name namespace %s. [%s]", certs_namespace, esp_err_to_name(esp_err));
|
LOG_SEND_ERROR("Unable to retrieve HTTPS certificates. NVS name space %s open failed: %s",certs_namespace, esp_err_to_name(esp_err));
|
||||||
}
|
}
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
@@ -391,6 +402,7 @@ void app_main()
|
|||||||
|
|
||||||
ESP_LOGI(TAG,"Initializing display");
|
ESP_LOGI(TAG,"Initializing display");
|
||||||
display_init("SqueezeESP32");
|
display_init("SqueezeESP32");
|
||||||
|
|
||||||
if(is_recovery_running && display){
|
if(is_recovery_running && display){
|
||||||
GDS_ClearExt(display, true);
|
GDS_ClearExt(display, true);
|
||||||
GDS_SetFont(display, &Font_droid_sans_fallback_15x17 );
|
GDS_SetFont(display, &Font_droid_sans_fallback_15x17 );
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
# Name, Type, SubType, Offset, Size, Flags
|
|
||||||
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
|
|
||||||
nvs, data, nvs, 0x9000, 0x6000,
|
|
||||||
phy_init, data, phy, 0xf000, 0x1000,
|
|
||||||
factory, app, factory, 0x10000, 3M,settings,
|
|
||||||
data, nvs, , 0x10000,
|
|
||||||
|
13
sdkconfig
13
sdkconfig
@@ -436,11 +436,11 @@ CONFIG_HEAP_TRACING_OFF=y
|
|||||||
CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
|
CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
|
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
|
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set
|
CONFIG_LOG_DEFAULT_LEVEL_WARN=y
|
||||||
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
|
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
|
||||||
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
|
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
|
||||||
CONFIG_LOG_DEFAULT_LEVEL=3
|
CONFIG_LOG_DEFAULT_LEVEL=2
|
||||||
CONFIG_LOG_COLORS=y
|
CONFIG_LOG_COLORS=y
|
||||||
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
|
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
|
||||||
# CONFIG_LWIP_L2_TO_L3_COPY is not set
|
# CONFIG_LWIP_L2_TO_L3_COPY is not set
|
||||||
@@ -499,7 +499,12 @@ CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
|
|||||||
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
|
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
|
||||||
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384
|
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384
|
||||||
# CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set
|
# CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set
|
||||||
# CONFIG_MBEDTLS_DEBUG is not set
|
CONFIG_MBEDTLS_DEBUG=y
|
||||||
|
# CONFIG_MBEDTLS_DEBUG_LEVEL_WARN is not set
|
||||||
|
# CONFIG_MBEDTLS_DEBUG_LEVEL_INFO is not set
|
||||||
|
# CONFIG_MBEDTLS_DEBUG_LEVEL_DEBUG is not set
|
||||||
|
CONFIG_MBEDTLS_DEBUG_LEVEL_VERBOSE=y
|
||||||
|
CONFIG_MBEDTLS_DEBUG_LEVEL=4
|
||||||
# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
|
# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
|
||||||
# CONFIG_MBEDTLS_CMAC_C is not set
|
# CONFIG_MBEDTLS_CMAC_C is not set
|
||||||
CONFIG_MBEDTLS_HARDWARE_AES=y
|
CONFIG_MBEDTLS_HARDWARE_AES=y
|
||||||
|
|||||||
@@ -56,8 +56,11 @@ function(___create_new_target target_name)
|
|||||||
idf_build_get_property(bca BUILD_COMPONENT_ALIASES)
|
idf_build_get_property(bca BUILD_COMPONENT_ALIASES)
|
||||||
list(REMOVE_ITEM bca "idf::app_recovery")
|
list(REMOVE_ITEM bca "idf::app_recovery")
|
||||||
list(REMOVE_ITEM bca "idf::app_squeezelite")
|
list(REMOVE_ITEM bca "idf::app_squeezelite")
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(${target_elf} ${bca})
|
target_link_libraries(${target_elf} ${bca})
|
||||||
target_link_libraries(${target_elf} idf::app_squeezelite)
|
target_link_libraries(${target_elf} idf::app_squeezelite)
|
||||||
|
|
||||||
set(target_name_mapfile "${target_name}.map")
|
set(target_name_mapfile "${target_name}.map")
|
||||||
target_link_libraries(${target_elf} "-Wl,--cref -Wl,--Map=${CMAKE_BINARY_DIR}/${target_name_mapfile}")
|
target_link_libraries(${target_elf} "-Wl,--cref -Wl,--Map=${CMAKE_BINARY_DIR}/${target_name_mapfile}")
|
||||||
|
|
||||||
@@ -67,7 +70,6 @@ function(___create_new_target target_name)
|
|||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET ${target_elf}
|
TARGET ${target_elf}
|
||||||
|
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "Generating ${build_dir}/${target_name}.bin"
|
COMMAND ${CMAKE_COMMAND} -E echo "Generating ${build_dir}/${target_name}.bin"
|
||||||
COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} -o "${build_dir}/${target_name}.bin" "${target_name}.elf"
|
COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} -o "${build_dir}/${target_name}.bin" "${target_name}.elf"
|
||||||
@@ -102,11 +104,13 @@ add_custom_command(
|
|||||||
TARGET recovery.elf
|
TARGET recovery.elf
|
||||||
PRE_LINK
|
PRE_LINK
|
||||||
COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
|
COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
|
||||||
|
# COMMAND xtensa-esp32-elf-objcopy --globalize-symbol GDS_DrawPixelFast ${build_dir}/esp-idf/display/libdisplay.a
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET squeezelite.elf
|
TARGET squeezelite.elf
|
||||||
PRE_LINK
|
PRE_LINK
|
||||||
COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
|
COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a
|
||||||
|
# COMMAND xtensa-esp32-elf-objcopy --globalize-symbol GDS_DrawPixelFast ${build_dir}/esp-idf/display/libdisplay.a
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user