cmake on esp-idf V4.0 - testing version - release

This commit is contained in:
Sebastien
2020-04-09 23:08:40 -04:00
parent 602b5564b0
commit 811451f24e
24 changed files with 3833 additions and 206 deletions

View File

@@ -22,7 +22,7 @@
#include "platform_config.h"
#include "nvs_utilities.h"
#include "platform_esp32.h"
#include "trace.h"
#include <stdio.h>
#include <string.h>
#include "esp_system.h"
@@ -58,7 +58,7 @@ extern esp_err_t nvs_load_config();
void config_raise_change(bool flag);
cJSON_bool config_is_entry_changed(cJSON * entry);
bool config_set_group_bit(int bit_num,bool flag);
cJSON * config_set_value_safe(nvs_type_t nvs_type, const char *key, void * value);
cJSON * config_set_value_safe(nvs_type_t nvs_type, const char *key,const void * value);
static void vCallbackFunction( TimerHandle_t xTimer );
void config_set_entry_changed_flag(cJSON * entry, cJSON_bool flag);
#define IMPLEMENT_SET_DEFAULT(t,nt) void config_set_default_## t (const char *key, t value){\
@@ -126,7 +126,7 @@ nvs_type_t config_get_item_type(cJSON * entry){
}
cJSON * config_set_value_safe(nvs_type_t nvs_type, const char *key, void * value){
cJSON * config_set_value_safe(nvs_type_t nvs_type, const char *key, const void * value){
cJSON * entry = cJSON_CreateObject();
double numvalue = 0;
@@ -346,21 +346,24 @@ void * config_safe_alloc_get_entry_value(nvs_type_t nvs_type, cJSON * entry){
char * entry_str = cJSON_PrintUnformatted(entry);
if(entry_str!=NULL){
ESP_LOGE(TAG, "requested value type string, config type is different. key: %s, value: %s, type %d, Object: \n%s",
entry_value->string,
entry_value->valuestring,
entry_value->type,
entry_str);
str_or_null(entry_value->string),
str_or_null(entry_value->valuestring),
entry_value->type,
str_or_null(entry_str));
free(entry_str);
}
else {
ESP_LOGE(TAG, "requested value type string, config type is different. key: %s, value: %s, type %d",
entry_value->string,
entry_value->valuestring,
entry_value->type);
str_or_null(entry_value->string),
str_or_null(entry_value->valuestring),
entry_value->type);
}
}
else {
value=(void *)strdup(cJSON_GetStringValue(entry_value));
size_t len=strlen(cJSON_GetStringValue(entry_value));
value=(void *)heap_caps_malloc(len+1, MALLOC_CAP_DMA);
memset(value,0x00,len+1);
memcpy(value,cJSON_GetStringValue(entry_value),len);
if(value==NULL){
char * entry_str = cJSON_PrintUnformatted(entry);
if(entry_str!=NULL){
@@ -380,7 +383,6 @@ void * config_safe_alloc_get_entry_value(nvs_type_t nvs_type, cJSON * entry){
void config_commit_to_nvs(){
ESP_LOGI(TAG,"Committing configuration to nvs. Locking config object.");
ESP_LOGV(TAG,"config_commit_to_nvs. Locking config object.");
if(!config_lock(LOCK_MAX_WAIT/portTICK_PERIOD_MS)){
ESP_LOGE(TAG, "config_commit_to_nvs: Unable to lock config for commit ");
return ;
@@ -403,8 +405,14 @@ void config_commit_to_nvs(){
nvs_type_t type = config_get_entry_type(entry);
void * value = config_safe_alloc_get_entry_value(type, entry);
if(value!=NULL){
esp_err_t err = store_nvs_value(type,entry->string,value);
size_t len=strlen(entry->string);
char * key=(void *)heap_caps_malloc(len+1, MALLOC_CAP_DMA);
memset(key,0x00,len+1);
memcpy(key,entry->string,len);
esp_err_t err = store_nvs_value(type,key,value);
free(key);
free(value);
if(err!=ESP_OK){
char * entry_str = cJSON_PrintUnformatted(entry);
if(entry_str!=NULL){
@@ -440,6 +448,7 @@ void config_commit_to_nvs(){
config_raise_change(false);
ESP_LOGV(TAG,"config_commit_to_nvs. Releasing the lock object.");
config_unlock();
ESP_LOGI(TAG,"Done Committing configuration to nvs.");
}
bool config_has_changes(){
return (xEventGroupGetBits(config_group) & CONFIG_NO_COMMIT_PENDING)==0;

View File

@@ -6,7 +6,7 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include <stdio.h>
#include "cmd_i2ctools.h"
#include "argtable3/argtable3.h"
@@ -507,6 +507,10 @@ static int do_i2cconfig_cmd(int argc, char **argv)
if((err=i2c_master_driver_install())!=ESP_OK){
res=1;
}
else
{
ESP_LOGI(TAG,"i2c driver successfully started.");
}
}
else {
ESP_LOGE(TAG,"I2C initialization failed. %s", esp_err_to_name(err));

View File

@@ -6,7 +6,7 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#define LOG_LOCAL_LEVEL ESP_LOG_INFO
#include <stdio.h>
#include <string.h>
#include <ctype.h>
@@ -49,7 +49,7 @@ static void register_restart_ota();
#if WITH_TASKS_INFO
static void register_tasks();
#endif
extern BaseType_t wifi_manager_task;
void register_system()
{
register_free();
@@ -435,13 +435,13 @@ static int light_sleep(int argc, char **argv)
if (io_count > 0) {
ESP_ERROR_CHECK( esp_sleep_enable_gpio_wakeup() );
}
if (CONFIG_CONSOLE_UART_NUM <= UART_NUM_1) {
if (CONFIG_ESP_CONSOLE_UART_NUM <= UART_NUM_1) {
ESP_LOGI(TAG, "Enabling UART wakeup (press ENTER to exit light sleep)");
ESP_ERROR_CHECK( uart_set_wakeup_threshold(CONFIG_CONSOLE_UART_NUM, 3) );
ESP_ERROR_CHECK( esp_sleep_enable_uart_wakeup(CONFIG_CONSOLE_UART_NUM) );
ESP_ERROR_CHECK( uart_set_wakeup_threshold(CONFIG_ESP_CONSOLE_UART_NUM, 3) );
ESP_ERROR_CHECK( esp_sleep_enable_uart_wakeup(CONFIG_ESP_CONSOLE_UART_NUM) );
}
fflush(stdout);
uart_tx_wait_idle(CONFIG_CONSOLE_UART_NUM);
uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM);
esp_light_sleep_start();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
const char *cause_str;

View File

@@ -121,14 +121,13 @@ void initialize_console() {
CONFIG_CONSOLE_UART_BAUDRATE, .data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1,
.use_ref_tick = true };
ESP_ERROR_CHECK(uart_param_config(CONFIG_CONSOLE_UART_NUM, &uart_config));
ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
/* Install UART driver for interrupt-driven reads and writes */
ESP_ERROR_CHECK(
uart_driver_install(CONFIG_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
ESP_ERROR_CHECK( uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
/* Tell VFS to use UART driver */
esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM);
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
/* Initialize the console */
esp_console_config_t console_config = { .max_cmdline_args = 22,

View File

@@ -6,6 +6,7 @@
#include "mdns.h"
#include "nvs.h"
#include "tcpip_adapter.h"
// IDF-V4++ #include "esp_netif.h"
#include "esp_log.h"
#include "esp_console.h"
#include "esp_pthread.h"

View File

@@ -24,6 +24,7 @@
#include <iphlpapi.h>
#else
#include "tcpip_adapter.h"
// IDF-V4++ #include "esp_netif.h"
#include <ctype.h>
#endif

View File

@@ -15,6 +15,7 @@ extern "C" {
#include "esp_err.h"
#include "tcpip_adapter.h"
// IDF-V4++ #include "esp_netif.h"
#ifdef CONFIG_EXAMPLE_CONNECT_ETHERNET
#define EXAMPLE_INTERFACE TCPIP_ADAPTER_IF_ETH

View File

@@ -19,8 +19,9 @@
#include "nvs_flash.h"
#include "cmd_system.h"
#include "esp_err.h"
#include "tcpip_adapter.h"
#include "squeezelite-ota.h"
#include "tcpip_adapter.h"
// IDF-V4++ #include "esp_netif.h"
#include "platform_config.h"
#include <time.h>
#include <sys/time.h>
@@ -64,10 +65,11 @@ typedef enum {
OTA_TYPE_INVALID
} ota_type_t;
static struct {
uint32_t actual_image_len;
uint32_t total_image_len;
uint32_t remain_image_len;
typedef struct {
size_t actual_image_len;
float downloaded_image_len;
float total_image_len;
float remain_image_len;
ota_type_t ota_type;
char * ota_write_data;
char * bin_data;
@@ -75,6 +77,7 @@ static struct {
size_t buffer_size;
uint8_t lastpct;
uint8_t newpct;
uint8_t newdownloadpct;
struct timeval OTA_start;
bool bOTAThreadStarted;
const esp_partition_t *configured;
@@ -82,7 +85,9 @@ static struct {
const esp_partition_t * update_partition;
const esp_partition_t* last_invalid_app ;
const esp_partition_t * ota_partition;
} ota_status;
} ota_status_t;
ota_status_t * ota_status;
struct timeval tv;
static esp_http_client_config_t http_client_config;
@@ -95,8 +100,12 @@ void _printMemStats(){
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
}
uint8_t ota_get_pct_complete(){
return ota_status.total_image_len==0?0:
(uint8_t)((float)ota_status.actual_image_len/(float)ota_status.total_image_len*100.0f);
return ota_status->total_image_len==0?0:
(uint8_t)((float)ota_status->actual_image_len/ota_status->total_image_len*100.0f);
}
uint8_t ota_get_pct_downloaded(){
return ota_status->total_image_len==0?0:
(uint8_t)(ota_status->downloaded_image_len/ota_status->total_image_len*100.0f);
}
typedef struct {
int x1,y1,x2,y2,width,height;
@@ -219,24 +228,35 @@ esp_err_t handle_http_on_data(esp_http_client_event_t *evt){
if(http_status == 200){
if(!ota_status.bOTAStarted)
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_INFO,"Downloading firmware");
ota_status->bOTAStarted = true;
ota_status->total_image_len=esp_http_client_get_content_length(evt->client);
ota_status->downloaded_image_len = 0;
ota_status->newdownloadpct = 0;
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;
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);
ota_status->downloaded_image_len +=evt->data_len;
recv_ptr+=evt->data_len;
}
if(ota_get_pct_downloaded()%5 == 0 && ota_get_pct_downloaded()%5!=ota_status->newdownloadpct) {
ota_status->newdownloadpct= ota_get_pct_downloaded();
loc_displayer_progressbar(ota_status->newdownloadpct);
gettimeofday(&tv, NULL);
uint32_t elapsed_ms= (tv.tv_sec-ota_status->OTA_start.tv_sec )*1000+(tv.tv_usec-ota_status->OTA_start.tv_usec)/1000;
ESP_LOGI(TAG,"OTA download progress : %f/%f (%d pct), %f KB/s", ota_status->downloaded_image_len, ota_status->total_image_len, ota_status->newdownloadpct, elapsed_ms>0?ota_status->downloaded_image_len*1000/elapsed_ms/1024:0);
sendMessaging(MESSAGING_INFO,"Downloading firmware %%%3d.",ota_status->newdownloadpct);
}
}
@@ -266,13 +286,13 @@ 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");
if(ota_status.bOTAStarted) sendMessaging(MESSAGING_INFO,"HTTP Connected");
ota_status.total_image_len=0;
ota_status.actual_image_len=0;
ota_status.lastpct=0;
ota_status.remain_image_len=0;
ota_status.newpct=0;
gettimeofday(&ota_status.OTA_start, NULL);
if(ota_status->bOTAStarted) sendMessaging(MESSAGING_INFO,"HTTP Connected");
ota_status->total_image_len=0;
ota_status->actual_image_len=0;
ota_status->lastpct=0;
ota_status->remain_image_len=0;
ota_status->newpct=0;
gettimeofday(&ota_status->OTA_start, NULL);
break;
case HTTP_EVENT_HEADER_SENT:
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
@@ -283,8 +303,8 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
// ESP_LOGW(TAG,"OTA will redirect to url: %s",evt->header_value);
// }
// if (strcasecmp(evt->header_key, "content-length") == 0) {
// 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);
// 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);
// }
break;
case HTTP_EVENT_ON_DATA:
@@ -304,26 +324,26 @@ esp_err_t init_config(ota_thread_parms_t * p_ota_thread_parms){
memset(&http_client_config, 0x00, sizeof(http_client_config));
sendMessaging(MESSAGING_INFO,"Initializing...");
loc_displayer_progressbar(0);
ota_status.ota_type= OTA_TYPE_INVALID;
ota_status->ota_type= OTA_TYPE_INVALID;
if(p_ota_thread_parms->url !=NULL && strlen(p_ota_thread_parms->url)>0 ){
ota_status.ota_type= OTA_TYPE_HTTP;
ota_status->ota_type= OTA_TYPE_HTTP;
}
else if(p_ota_thread_parms->bin!=NULL && p_ota_thread_parms->length > 0) {
ota_status.ota_type= OTA_TYPE_BUFFER;
ota_status->ota_type= OTA_TYPE_BUFFER;
}
if( ota_status.ota_type== OTA_TYPE_INVALID ){
if( ota_status->ota_type== OTA_TYPE_INVALID ){
ESP_LOGE(TAG,"HTTP OTA called without a url or a binary buffer");
return ESP_ERR_INVALID_ARG;
}
ota_status.buffer_size = BUFFSIZE;
ota_status.ota_write_data = heap_caps_malloc(ota_status.buffer_size+1 , (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT));
if(ota_status.ota_write_data== NULL){
ota_status->buffer_size = BUFFSIZE;
ota_status->ota_write_data = heap_caps_malloc(ota_status->buffer_size+1 , (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT));
if(ota_status->ota_write_data== NULL){
ESP_LOGE(TAG,"Error allocating the ota buffer");
return ESP_ERR_NO_MEM;
}
switch (ota_status.ota_type) {
switch (ota_status->ota_type) {
case OTA_TYPE_HTTP:
http_client_config.cert_pem =get_certificate();
http_client_config.event_handler = _http_event_handler;
@@ -337,8 +357,8 @@ esp_err_t init_config(ota_thread_parms_t * p_ota_thread_parms){
//http_client_config.timeout_ms = 5000;
break;
case OTA_TYPE_BUFFER:
ota_status.bin_data = p_ota_thread_parms->bin;
ota_status.total_image_len = p_ota_thread_parms->length;
ota_status->bin_data = p_ota_thread_parms->bin;
ota_status->total_image_len = p_ota_thread_parms->length;
break;
default:
return ESP_FAIL;
@@ -421,7 +441,7 @@ esp_err_t _erase_last_boot_app_partition(const esp_partition_t *ota_partition)
}
void ota_task_cleanup(const char * message, ...){
ota_status.bOTAThreadStarted=false;
ota_status->bOTAThreadStarted=false;
loc_displayer_progressbar(0);
if(message!=NULL){
va_list args;
@@ -429,18 +449,18 @@ void ota_task_cleanup(const char * message, ...){
sendMessaging(MESSAGING_ERROR,message, args);
va_end(args);
}
FREE_RESET(ota_status.ota_write_data);
FREE_RESET(ota_status.bin_data);
FREE_RESET(ota_status->ota_write_data);
FREE_RESET(ota_status->bin_data);
if(ota_http_client!=NULL) {
esp_http_client_cleanup(ota_http_client);
ota_http_client=NULL;
}
ota_status.bOTAStarted = false;
ota_status->bOTAStarted = false;
task_fatal_error();
}
esp_err_t ota_buffer_all(){
esp_err_t err=ESP_OK;
if (ota_status.ota_type == OTA_TYPE_HTTP){
if (ota_status->ota_type == OTA_TYPE_HTTP){
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);
if (ota_http_client == NULL) {
@@ -454,68 +474,68 @@ esp_err_t ota_buffer_all(){
return ESP_FAIL;
}
if(ota_status.total_image_len<=0){
if(ota_status->total_image_len<=0){
sendMessaging(MESSAGING_ERROR,"Error: Invalid image length");
return ESP_FAIL;
}
sendMessaging(MESSAGING_INFO,"Download success");
}
else {
gettimeofday(&ota_status.OTA_start, NULL);
gettimeofday(&ota_status->OTA_start, NULL);
}
ota_status.remain_image_len=ota_status.total_image_len;
ota_status->remain_image_len=ota_status->total_image_len;
return err;
}
int ota_buffer_read(){
int data_read=0;
if(ota_status.remain_image_len >ota_status.buffer_size){
data_read = ota_status.buffer_size;
if(ota_status->remain_image_len >ota_status->buffer_size){
data_read = ota_status->buffer_size;
} else {
data_read = ota_status.remain_image_len;
data_read = ota_status->remain_image_len;
}
memcpy(ota_status.ota_write_data, &ota_status.bin_data[ota_status.actual_image_len], data_read);
memcpy(ota_status->ota_write_data, &ota_status->bin_data[ota_status->actual_image_len], data_read);
ota_status.actual_image_len += data_read;
ota_status.remain_image_len -= data_read;
ota_status->actual_image_len += data_read;
ota_status->remain_image_len -= data_read;
return data_read;
}
esp_err_t ota_header_check(){
esp_app_desc_t new_app_info;
esp_app_desc_t running_app_info;
ota_status.configured = esp_ota_get_boot_partition();
ota_status.running = esp_ota_get_running_partition();
ota_status.last_invalid_app= esp_ota_get_last_invalid_partition();
ota_status.ota_partition = _get_ota_partition(ESP_PARTITION_SUBTYPE_APP_OTA_0);
ota_status->configured = esp_ota_get_boot_partition();
ota_status->running = esp_ota_get_running_partition();
ota_status->last_invalid_app= esp_ota_get_last_invalid_partition();
ota_status->ota_partition = _get_ota_partition(ESP_PARTITION_SUBTYPE_APP_OTA_0);
ESP_LOGI(TAG, "Running partition [%s] type %d subtype %d (offset 0x%08x)", ota_status.running->label, ota_status.running->type, ota_status.running->subtype, ota_status.running->address);
if (ota_status.total_image_len > ota_status.ota_partition->size){
ota_task_cleanup("Error: Image size too large to fit in partition.");
ESP_LOGI(TAG, "Running partition [%s] type %d subtype %d (offset 0x%08x)", ota_status->running->label, ota_status->running->type, ota_status->running->subtype, ota_status->running->address);
if (ota_status->total_image_len > ota_status->ota_partition->size){
ota_task_cleanup("Error: Image size (%d) too large to fit in partition (%d).",ota_status->ota_partition->size,ota_status->total_image_len );
return ESP_FAIL;
}
if(ota_status.ota_partition == NULL){
if(ota_status->ota_partition == NULL){
ESP_LOGE(TAG,"Unable to locate OTA application partition. ");
ota_task_cleanup("Error: OTA partition not found");
return ESP_FAIL;
}
if (ota_status.configured != ota_status.running) {
ESP_LOGW(TAG, "Configured OTA boot partition at offset 0x%08x, but running from offset 0x%08x", ota_status.configured->address, ota_status.running->address);
if (ota_status->configured != ota_status->running) {
ESP_LOGW(TAG, "Configured OTA boot partition at offset 0x%08x, but running from offset 0x%08x", ota_status->configured->address, ota_status->running->address);
ESP_LOGW(TAG, "(This can happen if either the OTA boot data or preferred boot image become corrupted somehow.)");
}
ESP_LOGI(TAG, "Next ota update partition is: [%s] subtype %d at offset 0x%x",
ota_status.update_partition->label, ota_status.update_partition->subtype, ota_status.update_partition->address);
ota_status->update_partition->label, ota_status->update_partition->subtype, ota_status->update_partition->address);
if (ota_status.total_image_len >= IMAGE_HEADER_SIZE) {
if (ota_status->total_image_len >= IMAGE_HEADER_SIZE) {
// check current version with downloading
memcpy(&new_app_info, &ota_status.bin_data[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t));
memcpy(&new_app_info, &ota_status->bin_data[sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t)], sizeof(esp_app_desc_t));
ESP_LOGI(TAG, "New firmware version: %s", new_app_info.version);
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);
}
sendMessaging(MESSAGING_INFO,"New version is : %s",new_app_info.version);
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);
}
@@ -542,7 +562,7 @@ void ota_task(void *pvParameter)
ESP_LOGD(TAG, "HTTP ota Thread started");
_printMemStats();
ota_status.update_partition = esp_ota_get_next_update_partition(NULL);
ota_status->update_partition = esp_ota_get_next_update_partition(NULL);
ESP_LOGI(TAG,"Initializing OTA configuration");
err = init_config(pvParameter);
@@ -570,7 +590,7 @@ void ota_task(void *pvParameter)
IF_DISPLAY(GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, "Formatting partition"));
_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){
ota_task_cleanup("Error: Unable to erase last APP partition. (%s)",esp_err_to_name(err));
return;
@@ -582,35 +602,36 @@ void ota_task(void *pvParameter)
// Call OTA Begin with a small partition size - this minimizes the time spent in erasing partition,
// which was already done above
esp_ota_handle_t update_handle = 0 ;
err = esp_ota_begin(ota_status.ota_partition, 512, &update_handle);
gettimeofday(&ota_status->OTA_start, NULL);
err = esp_ota_begin(ota_status->ota_partition, 512, &update_handle);
if (err != ESP_OK) {
ota_task_cleanup("esp_ota_begin failed (%s)", esp_err_to_name(err));
return;
}
ESP_LOGD(TAG, "esp_ota_begin succeeded");
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();
if (data_read <= 0) {
ota_task_cleanup("Error: Data read error");
return;
} else if (data_read > 0) {
err = esp_ota_write( update_handle, (const void *)ota_status.ota_write_data, data_read);
err = esp_ota_write( update_handle, (const void *)ota_status->ota_write_data, data_read);
if (err != ESP_OK) {
ota_task_cleanup("Error: OTA Partition write failure. (%s)",esp_err_to_name(err));
return;
}
ESP_LOGD(TAG, "Written image length %d", ota_status.actual_image_len);
ESP_LOGD(TAG, "Written image length %d", ota_status->actual_image_len);
if(ota_get_pct_complete()%5 == 0) ota_status.newpct = ota_get_pct_complete();
if(ota_status.lastpct!=ota_status.newpct ) {
loc_displayer_progressbar(ota_status.newpct);
if(ota_get_pct_complete()%5 == 0) ota_status->newpct = ota_get_pct_complete();
if(ota_status->lastpct!=ota_status->newpct ) {
loc_displayer_progressbar(ota_status->newpct);
gettimeofday(&tv, NULL);
uint32_t elapsed_ms= (tv.tv_sec-ota_status.OTA_start.tv_sec )*1000+(tv.tv_usec-ota_status.OTA_start.tv_usec)/1000;
ESP_LOGI(TAG,"OTA progress : %d/%d (%d pct), %d KB/s", ota_status.actual_image_len, ota_status.total_image_len, ota_status.newpct, elapsed_ms>0?ota_status.actual_image_len*1000/elapsed_ms/1024:0);
sendMessaging(MESSAGING_INFO,"Writing binary file.");
ota_status.lastpct=ota_status.newpct;
uint32_t elapsed_ms= (tv.tv_sec-ota_status->OTA_start.tv_sec )*1000+(tv.tv_usec-ota_status->OTA_start.tv_usec)/1000;
ESP_LOGI(TAG,"OTA progress : %d/%.0f (%d pct), %d KB/s", ota_status->actual_image_len, ota_status->total_image_len, ota_status->newpct, elapsed_ms>0?ota_status->actual_image_len*1000/elapsed_ms/1024:0);
sendMessaging(MESSAGING_INFO,"Writing binary file %%%3d.",ota_status->newpct);
ota_status->lastpct=ota_status->newpct;
}
taskYIELD();
@@ -620,8 +641,8 @@ void ota_task(void *pvParameter)
}
}
ESP_LOGI(TAG, "Total Write binary data length: %d", ota_status.actual_image_len);
if (ota_status.total_image_len != ota_status.actual_image_len) {
ESP_LOGI(TAG, "Total Write binary data length: %d", ota_status->actual_image_len);
if (ota_status->total_image_len != ota_status->actual_image_len) {
ota_task_cleanup("Error: Error in receiving complete file");
return;
}
@@ -633,7 +654,7 @@ void ota_task(void *pvParameter)
return;
}
_printMemStats();
err = esp_ota_set_boot_partition(ota_status.ota_partition);
err = esp_ota_set_boot_partition(ota_status->ota_partition);
if (err == ESP_OK) {
ESP_LOGI(TAG,"OTA Process completed successfully!");
sendMessaging(MESSAGING_INFO,"Success!");
@@ -652,12 +673,14 @@ void ota_task(void *pvParameter)
esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t length){
int ret = 0;
uint16_t stack_size, task_priority;
if(ota_status.bOTAThreadStarted){
if(ota_status && ota_status->bOTAThreadStarted){
ESP_LOGE(TAG,"OTA Already started. ");
return ESP_FAIL;
}
memset(&ota_status, 0x00, sizeof(ota_status));
ota_status.bOTAThreadStarted=true;
ota_status = heap_caps_malloc(sizeof(ota_status_t) , (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT));
memset(ota_status, 0x00, sizeof(ota_status_t));
ota_status->bOTAThreadStarted=true;
if(bin_url){
ota_thread_parms.url =strdup(bin_url);
@@ -689,7 +712,8 @@ esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t
}
ESP_LOGD(TAG,"OTA task stack size %d, priority %d (%d %s ESP_TASK_MAIN_PRIO)",stack_size , task_priority, abs(task_priority-ESP_TASK_MAIN_PRIO), task_priority-ESP_TASK_MAIN_PRIO>0?"above":"below");
ret=xTaskCreatePinnedToCore(&ota_task, "ota_task", stack_size , (void *)&ota_thread_parms, task_priority, NULL, OTA_CORE);
// ret=xTaskCreatePinnedToCore(&ota_task, "ota_task", stack_size , (void *)&ota_thread_parms, task_priority, NULL, OTA_CORE);
ret=xTaskCreate(&ota_task, "ota_task", stack_size , (void *)&ota_thread_parms, task_priority, NULL);
if (ret != pdPASS) {
ESP_LOGI(TAG, "create thread %s failed", "ota_task");
return ESP_FAIL;

View File

@@ -34,6 +34,7 @@
extern const char unknown_string_placeholder[];
extern const char * str_or_unknown(const char * str);
extern const char * str_or_null(const char * str);
#ifndef FREE_AND_NULL
#define FREE_AND_NULL(x) if(x) { free(x); x=NULL; }

View File

@@ -6,4 +6,3 @@ idf_component_register( SRC_DIRS .
)
#add_definitions(-DLOG_LOCAL_LEVEL=ESP_LOG_INFO)

View File

@@ -40,7 +40,7 @@ var commandHeader = 'squeezelite -b 500:2000 -d all=info ';
var pname, ver, otapct, otadsc;
var blockAjax = false;
var blockFlashButton = false;
var dblclickCounter=0;
var apList = null;
var selectedSSID = "";
var refreshAPInterval = null;
@@ -208,7 +208,7 @@ $(document).ready(function(){
$("input#autoexec-cb").on("click", function() {
var data = { 'timestamp': Date.now() };
autoexec = (this.checked)?1:0;
autoexec = (this.checked)?"1":"0";
data['config'] = {};
data['config'] = {
autoexec : {
@@ -548,6 +548,19 @@ $(document).ready(function(){
html: true,
placement : 'right',
});
$('a[href^="#tab-firmware"]').dblclick(function () {
dblclickCounter++;
if(dblclickCounter>=2)
{
dblclickCounter=0;
blockFlashButton=false;
alert("Unocking flash button!");
}
});
$('a[href^="#tab-firmware"]').click(function () {
// when navigating back to this table, reset the counter
if(!this.classList.contains("active")) dblclickCounter=0;
});
});
function setURL(button) {

View File

@@ -40,7 +40,7 @@ Contains the freeRTOS task for the DNS server that processes the requests.
#include <freertos/event_groups.h>
#include <esp_system.h>
#include <esp_wifi.h>
#include <esp_event_loop.h>
#include <esp_event.h>
#include <esp_log.h>
#include <esp_err.h>
#include <nvs_flash.h>

View File

@@ -43,7 +43,7 @@ function to process requests, decode URLs, serve files, etc. etc.
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include <esp_event.h>
#include "nvs_flash.h"
#include "esp_log.h"
#include "driver/gpio.h"

View File

@@ -41,8 +41,10 @@ Contains the freeRTOS task and all necessary support
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include <esp_event.h>
#include "esp_event_loop.h"
#include "tcpip_adapter.h"
// IDF-V4++ #include "esp_netif.h"
#include "esp_event.h"
#include "esp_wifi.h"
#include "esp_wifi_types.h"
@@ -71,12 +73,14 @@ Contains the freeRTOS task and all necessary support
#endif
#define STR_OR_BLANK(p) p==NULL?"":p
BaseType_t wifi_manager_task;
/* objects used to manipulate the main queue of events */
QueueHandle_t wifi_manager_queue;
SemaphoreHandle_t wifi_manager_json_mutex = NULL;
SemaphoreHandle_t wifi_manager_sta_ip_mutex = NULL;
char *wifi_manager_sta_ip = NULL;
#define STA_IP_LEN sizeof(char) * IP4ADDR_STRLEN_MAX
bool bHasConnected=false;
uint16_t ap_num = MAX_AP_NUM;
wifi_ap_record_t *accessp_records=NULL;
@@ -148,6 +152,7 @@ const int WIFI_MANAGER_SCAN_BIT = BIT7;
/* @brief When set, means user requested for a disconnect */
const int WIFI_MANAGER_REQUEST_DISCONNECT_BIT = BIT8;
char * get_disconnect_code_desc(uint8_t reason){
switch (reason) {
case 1 : return "UNSPECIFIED"; break;
@@ -195,6 +200,9 @@ void set_host_name(){
if((err=tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, host_name)) !=ESP_OK){
ESP_LOGE(TAG, "Unable to set host name. Error: %s",esp_err_to_name(err));
}
// if((err=tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_AP, host_name)) !=ESP_OK){
// ESP_LOGE(TAG, "Unable to set host name. Error: %s",esp_err_to_name(err));
// }
free(host_name);
}
@@ -267,8 +275,9 @@ void wifi_manager_init_wifi(){
if (gpio36_39_used) {
ESP_LOGW(TAG, "GPIO 36 or 39 are in use, need to disable WiFi PowerSave!");
esp_wifi_set_ps(WIFI_PS_NONE);
}
}
ESP_ERROR_CHECK( esp_wifi_start() );
taskYIELD();
ESP_LOGD(TAG, "Initializing wifi. done");
}
@@ -302,7 +311,7 @@ void wifi_manager_start(){
}
ESP_LOGD(TAG, "About to set the STA IP String to 0.0.0.0");
wifi_manager_sta_ip = (char*)malloc(sizeof(char) * IP4ADDR_STRLEN_MAX);
wifi_manager_sta_ip = (char*)malloc(STA_IP_LEN);
wifi_manager_safe_update_sta_ip_string(NULL);
ESP_LOGD(TAG, "Getting release url ");
@@ -319,7 +328,7 @@ void wifi_manager_start(){
/* start wifi manager task */
ESP_LOGD(TAG, "Creating wifi manager task");
xTaskCreate(&wifi_manager, "wifi_manager", 4096, NULL, WIFI_MANAGER_TASK_PRIORITY, &task_wifi_manager);
wifi_manager_task= xTaskCreate(&wifi_manager, "wifi_manager", 4096, NULL, WIFI_MANAGER_TASK_PRIORITY, &task_wifi_manager);
}
@@ -485,9 +494,9 @@ void wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code)
/* rest of the information is copied after the ssid */
tcpip_adapter_ip_info_t ip_info;
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
cJSON_AddItemToObject(ip_info_cjson, "ip", cJSON_CreateString(ip4addr_ntoa(&ip_info.ip)));
cJSON_AddItemToObject(ip_info_cjson, "netmask", cJSON_CreateString(ip4addr_ntoa(&ip_info.netmask)));
cJSON_AddItemToObject(ip_info_cjson, "gw", cJSON_CreateString(ip4addr_ntoa(&ip_info.gw)));
cJSON_AddItemToObject(ip_info_cjson, "ip", cJSON_CreateString(ip4addr_ntoa((ip4_addr_t *)&ip_info.ip)));
cJSON_AddItemToObject(ip_info_cjson, "netmask", cJSON_CreateString(ip4addr_ntoa((ip4_addr_t *)&ip_info.netmask)));
cJSON_AddItemToObject(ip_info_cjson, "gw", cJSON_CreateString(ip4addr_ntoa((ip4_addr_t *)&ip_info.gw)));
}
}
ESP_LOGV(TAG, "wifi_manager_generate_ip_info_json done");
@@ -674,9 +683,13 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
case WIFI_EVENT_STA_WPS_ER_PIN:
ESP_LOGD(TAG, "WIFI_EVENT_STA_WPS_ER_PIN");
break;
case WIFI_EVENT_AP_STACONNECTED: /* a user disconnected from the SoftAP */
ESP_LOGI(TAG, "WIFI_EVENT_AP_STACONNECTED");
case WIFI_EVENT_AP_STACONNECTED:{ /* a user disconnected from the SoftAP */
wifi_event_ap_staconnected_t * stac = (wifi_event_ap_staconnected_t *)event_data;
char * mac = get_mac_string(stac->mac);
ESP_LOGI(TAG, "WIFI_EVENT_AP_STACONNECTED. aid: %d, mac: %s",stac->aid,STR_OR_BLANK(mac));
FREE_AND_NULL(mac);
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_AP_STA_CONNECTED_BIT);
}
break;
case WIFI_EVENT_AP_STADISCONNECTED:
ESP_LOGI(TAG, "WIFI_EVENT_AP_STADISCONNECTED");
@@ -788,19 +801,15 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
// Whether the assigned IP has changed or not
ip_event_got_ip_t * s =(ip_event_got_ip_t*)event_data;
tcpip_adapter_if_t index = s->if_index;
char * ip=strdup(ip4addr_ntoa(&(s->ip_info.ip)));
char * gw=strdup(ip4addr_ntoa(&(s->ip_info.gw)));
char * nm=strdup(ip4addr_ntoa(&(s->ip_info.netmask)));
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP. IP=%s, Gateway=%s, NetMask=%s, Interface: %s %s",
ip,
gw,
nm,
index==TCPIP_ADAPTER_IF_STA?"TCPIP_ADAPTER_IF_STA":index==TCPIP_ADAPTER_IF_AP?"TCPIP_ADAPTER_IF_AP":index==TCPIP_ADAPTER_IF_ETH?"TCPIP_ADAPTER_IF_ETH":"Unknown",
//tcpip_adapter_if_t index = s->if_index;
const tcpip_adapter_ip_info_t *ip_info = &s->ip_info;
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP. IP="IPSTR", Gateway="IPSTR", NetMask="IPSTR", %s",
IP2STR(&ip_info->ip),
IP2STR(&ip_info->gw),
IP2STR(&ip_info->netmask),
s->ip_changed?"Address was changed":"Address unchanged");
FREE_AND_NULL(ip);
FREE_AND_NULL(gw);
FREE_AND_NULL(nm);
// todo: if ip address was changed, we probably need to restart, as all sockets
// will become abnormal
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_WIFI_CONNECTED_BIT);
last_connected = esp_timer_get_time();
@@ -977,6 +986,8 @@ void wifi_manager_register_handlers(){
void wifi_manager_config_ap(){
/* SoftAP - Wifi Access Point configuration setup */
tcpip_adapter_ip_info_t info;
esp_err_t err=ESP_OK;
tcpip_adapter_dhcp_status_t state;
memset(&info, 0x00, sizeof(info));
char * value = NULL;
wifi_config_t ap_config = {
@@ -985,8 +996,12 @@ void wifi_manager_config_ap(){
},
};
ESP_LOGI(TAG, "Configuring Access Point.");
ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP)); /* stop AP DHCP server */
ESP_LOGI(TAG,"Stopping DHCP on interface ");
if((err= tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP))!=ESP_OK) /* stop AP DHCP server */
{
ESP_LOGW(TAG, "Stopping DHCP failed. Error %s",esp_err_to_name(err));
}
/*
* Set access point mode IP adapter configuration
*/
@@ -1010,8 +1025,10 @@ void wifi_manager_config_ap(){
FREE_AND_NULL(value);
ESP_LOGD(TAG, "Setting tcp_ip info for interface TCPIP_ADAPTER_IF_AP");
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info));
if((err=tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info))!=ESP_OK){
ESP_LOGE(TAG, "Setting tcp_ip info for interface TCPIP_ADAPTER_IF_AP. Error %s",esp_err_to_name(err));
return;
}
/*
* Set Access Point configuration
*/
@@ -1046,20 +1063,50 @@ void wifi_manager_config_ap(){
ESP_LOGI(TAG, "Max Connections: %d", ap_config.ap.max_connection);
ESP_LOGI(TAG, "Beacon interval: %d", ap_config.ap.beacon_interval);
ESP_LOGD(TAG, "Starting dhcps on interface TCPIP_ADAPTER_IF_AP");
ESP_ERROR_CHECK(tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP)); /* start AP DHCP server */
ESP_LOGD(TAG, "");
if((err= esp_wifi_set_mode(WIFI_MODE_APSTA))!=ESP_OK) /* stop AP DHCP server */
{
ESP_LOGE(TAG, "Setting wifi mode as WIFI_MODE_APSTA failed. Error %s",esp_err_to_name(err));
return;
}
ESP_LOGD(TAG, "Setting wifi mode as WIFI_MODE_APSTA");
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
ESP_LOGD(TAG, "Setting wifi AP configuration for WIFI_IF_AP");
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &ap_config));
if((err= esp_wifi_set_config(WIFI_IF_AP, &ap_config))!=ESP_OK) /* stop AP DHCP server */
{
ESP_LOGE(TAG, "Setting wifi AP configuration for WIFI_IF_AP failed. Error %s",esp_err_to_name(err));
return;
}
ESP_LOGD(TAG, "Setting wifi bandwidth (%d) for WIFI_IF_AP",DEFAULT_AP_BANDWIDTH);
ESP_ERROR_CHECK(esp_wifi_set_bandwidth(WIFI_IF_AP, DEFAULT_AP_BANDWIDTH));
if((err=esp_wifi_set_bandwidth(WIFI_IF_AP, DEFAULT_AP_BANDWIDTH))!=ESP_OK) /* stop AP DHCP server */
{
ESP_LOGE(TAG, "Setting wifi bandwidth for WIFI_IF_AP failed. Error %s",esp_err_to_name(err));
return;
}
ESP_LOGD(TAG, "Setting wifi power save (%d) for WIFI_IF_AP",DEFAULT_STA_POWER_SAVE);
ESP_ERROR_CHECK(esp_wifi_set_ps(DEFAULT_STA_POWER_SAVE));
if((err=esp_wifi_set_ps(DEFAULT_STA_POWER_SAVE))!=ESP_OK) /* stop AP DHCP server */
{
ESP_LOGE(TAG, "Setting wifi power savefor WIFI_IF_AP failed. Error %s",esp_err_to_name(err));
return;
}
ESP_LOGD(TAG, "Starting dhcps on interface TCPIP_ADAPTER_IF_AP");
if((err=tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP))!=ESP_OK) /* stop AP DHCP server */
{
ESP_LOGE(TAG, "Starting dhcp on TCPIP_ADAPTER_IF_AP failed. Error %s",esp_err_to_name(err));
return;
}
ESP_LOGD(TAG, "Done configuring Soft Access Point");
dns_server_start();
}
void wifi_manager( void * pvParameters ){
@@ -1067,6 +1114,7 @@ void wifi_manager( void * pvParameters ){
BaseType_t xStatus;
EventBits_t uxBits;
uint8_t retries = 0;
esp_err_t err=ESP_OK;
/* start http server */
http_server_start();
@@ -1084,10 +1132,17 @@ void wifi_manager( void * pvParameters ){
/* As input param, it stores max AP number ap_records can hold. As output param, it receives the actual AP number this API returns.
* As a consequence, ap_num MUST be reset to MAX_AP_NUM at every scan */
ESP_LOGD(TAG, "Getting AP list records");
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_num));
if((err=esp_wifi_scan_get_ap_num(&ap_num))!=ESP_OK) {
ESP_LOGE(TAG, "Failed to retrieve scan results count. Error %s",esp_err_to_name(err));
break;
}
if(ap_num>0){
accessp_records = (wifi_ap_record_t*)malloc(sizeof(wifi_ap_record_t) * ap_num);
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&ap_num, accessp_records));
if((err=esp_wifi_scan_get_ap_records(&ap_num, accessp_records))!=ESP_OK) {
ESP_LOGE(TAG, "Failed to retrieve scan results list. Error %s",esp_err_to_name(err));
break;
}
/* make sure the http server isn't trying to access the list while it gets refreshed */
ESP_LOGD(TAG, "Preparing to build ap JSON list");
if(wifi_manager_lock_json_buffer( pdMS_TO_TICKS(1000) )){
@@ -1212,14 +1267,23 @@ void wifi_manager( void * pvParameters ){
if( WIFI_MODE_APSTA != mode && WIFI_MODE_STA !=mode ){
// the soft ap is not started, so let's set the WiFi mode to STA
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - setting mode WIFI_MODE_STA");
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
if((err=esp_wifi_set_mode(WIFI_MODE_STA))!=ESP_OK) {
ESP_LOGE(TAG, "Failed to set wifi mode to STA. Error %s",esp_err_to_name(err));
break;
}
}
ESP_LOGD(TAG, "MESSAGE: ORDER_CONNECT_STA - setting config for WIFI_IF_STA");
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, wifi_manager_get_wifi_sta_config()));
if((err=esp_wifi_set_config(WIFI_IF_STA, wifi_manager_get_wifi_sta_config()))!=ESP_OK) {
ESP_LOGE(TAG, "Failed to set STA configuration. Error %s",esp_err_to_name(err));
break;
}
set_host_name();
ESP_LOGI(TAG, "Wifi Connecting...");
ESP_ERROR_CHECK(esp_wifi_connect());
if((err=esp_wifi_connect())!=ESP_OK) {
ESP_LOGE(TAG, "Failed to initiate wifi connection. Error %s",esp_err_to_name(err));
break;
}
}
/* callback */