Fix spotify configuration UI- release

This commit is contained in:
Sebastien L
2022-11-25 13:48:32 -05:00
parent 37f48d4bc8
commit 8462de1c16
7 changed files with 72 additions and 45 deletions

View File

@@ -13,7 +13,7 @@ add_definitions(-DHIERARCHICAL_STATES=1)
#add_definitions(-DNETWORK_ETHERNET_LOG_LEVEL=ESP_LOG_DEBUG) #add_definitions(-DNETWORK_ETHERNET_LOG_LEVEL=ESP_LOG_DEBUG)
#uncomment line below to get network status debug logs #uncomment line below to get network status debug logs
#add_definitions(-DNETWORK_STATUS_LOG_LEVEL=ESP_LOG_DEBUG) #add_definitions(-DNETWORK_STATUS_LOG_LEVEL=ESP_LOG_DEBUG)
#add_definitions(-DNETWORK_HANDLERS_LOG_LEVEL=ESP_LOG_DEBUG) #add_definitions(-DNETWORK_HANDLERS_LOG_LEVEL=ESP_LOG_DEBUG)
#add_definitions(-DNETWORK_WIFI_LOG_LEVEL=ESP_LOG_DEBUG) #add_definitions(-DNETWORK_WIFI_LOG_LEVEL=ESP_LOG_DEBUG)
#add_definitions(-DNETWORK_MANAGER_LOG_LEVEL=ESP_LOG_DEBUG) #add_definitions(-DNETWORK_MANAGER_LOG_LEVEL=ESP_LOG_DEBUG)
#add_definitions(-DNETWORK_HTTP_SERVER_LOG_LEVEL=ESP_LOG_DEBUG) #add_definitions(-DNETWORK_HTTP_SERVER_LOG_LEVEL=ESP_LOG_DEBUG)

View File

@@ -83,25 +83,28 @@ static void bt_app_task_handler(void *arg)
esp_bt_controller_mem_release(ESP_BT_MODE_BLE); esp_bt_controller_mem_release(ESP_BT_MODE_BLE);
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE ){
if ((err = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
ESP_LOGE(TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(err));
goto exit; if ((err = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
} ESP_LOGE(TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(err));
goto exit;
}
if ((err = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)) != ESP_OK) { if ((err = esp_bt_controller_enable(ESP_BT_MODE_BTDM)) != ESP_OK) {
ESP_LOGE(TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(err)); ESP_LOGE(TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(err));
goto exit; goto exit;
} }
if ((err = esp_bluedroid_init()) != ESP_OK) { if ((err = esp_bluedroid_init()) != ESP_OK) {
ESP_LOGE(TAG, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(err)); ESP_LOGE(TAG, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(err));
goto exit; goto exit;
} }
if ((err = esp_bluedroid_enable()) != ESP_OK) { if ((err = esp_bluedroid_enable()) != ESP_OK) {
ESP_LOGE(TAG, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(err)); ESP_LOGE(TAG, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(err));
goto exit; goto exit;
}
} }
/* Bluetooth device name, connection mode and profile set up */ /* Bluetooth device name, connection mode and profile set up */

View File

@@ -634,7 +634,7 @@ cJSON * config_alloc_get_cjson(const char *key){
} }
return conf_json; return conf_json;
} }
esp_err_t config_set_cjson_str(const char *key, cJSON *value){ esp_err_t config_set_cjson_str_and_free(const char *key, cJSON *value){
char * value_str = cJSON_PrintUnformatted(value); char * value_str = cJSON_PrintUnformatted(value);
if(value_str==NULL){ if(value_str==NULL){
ESP_LOGE(TAG, "Unable to print cJSON for key [%s]", key); ESP_LOGE(TAG, "Unable to print cJSON for key [%s]", key);

View File

@@ -53,7 +53,7 @@ void config_init();
void * config_alloc_get_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size); void * config_alloc_get_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size);
void * config_alloc_get_str(const char *key, char *lead, char *fallback); void * config_alloc_get_str(const char *key, char *lead, char *fallback);
cJSON * config_alloc_get_cjson(const char *key); cJSON * config_alloc_get_cjson(const char *key);
esp_err_t config_set_cjson_str(const char *key, cJSON *value); esp_err_t config_set_cjson_str_and_free(const char *key, cJSON *value);
void config_get_uint16t_from_str(const char *key, uint16_t *value, uint16_t default_value); void config_get_uint16t_from_str(const char *key, uint16_t *value, uint16_t default_value);
void config_delete_key(const char *key); void config_delete_key(const char *key);
void config_set_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size); void config_set_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size);

View File

@@ -593,7 +593,6 @@ static int is_valid_gpio_number(int gpio, const char * name, FILE *f, bool manda
return 0; return 0;
} }
static int do_cspot_config(int argc, char **argv){ static int do_cspot_config(int argc, char **argv){
char * name = NULL;
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&cspot_args); int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&cspot_args);
if (nerrors != 0) { if (nerrors != 0) {
return 1; return 1;
@@ -610,25 +609,30 @@ static int do_cspot_config(int argc, char **argv){
cJSON * cspot_config = config_alloc_get_cjson("cspot_config"); cJSON * cspot_config = config_alloc_get_cjson("cspot_config");
if(!cspot_config){ if(!cspot_config){
nerrors++; nerrors++;
fprintf(f,"error: Unable to get cspot config.\n"); fprintf(f,"error: Unable to get default cspot config.\n");
} }
else { if(cspot_args.deviceName->count>0){
cjson_update_string(&cspot_config,cspot_args.deviceName->hdr.longopts,cspot_args.deviceName->count>0?cspot_args.deviceName->sval[0]:NULL); cjson_update_string(&cspot_config,cspot_args.deviceName->hdr.longopts,cspot_args.deviceName->sval[0]);
// cjson_update_number(&cspot_config,cspot_args.volume->hdr.longopts,cspot_args.volume->count>0?cspot_args.volume->ival[0]:0);
cjson_update_number(&cspot_config,cspot_args.bitrate->hdr.longopts,cspot_args.bitrate->count>0?cspot_args.bitrate->ival[0]:0);
} }
if(cspot_args.bitrate->count>0){
cjson_update_number(&cspot_config,cspot_args.bitrate->hdr.longopts,cspot_args.bitrate->ival[0]);
}
if(!nerrors ){ if(!nerrors ){
fprintf(f,"Storing cspot parameters.\n"); fprintf(f,"Storing cspot parameters.\n");
nerrors+=(config_set_cjson_str("cspot_config",cspot_config) !=ESP_OK); nerrors+=(config_set_cjson_str_and_free("cspot_config",cspot_config) !=ESP_OK);
} }
if(nerrors==0){ if(nerrors==0 ){
fprintf(f,"Device name changed to %s\n",name); if(cspot_args.deviceName->count>0){
fprintf(f,"Device name changed to %s\n",cspot_args.deviceName->sval[0]);
}
if(cspot_args.bitrate->count>0){
fprintf(f,"Bitrate changed to %u\n",cspot_args.bitrate->ival[0]);
}
} }
if(!nerrors ){ if(!nerrors ){
fprintf(f,"Done.\n"); fprintf(f,"Done.\n");
} }
FREE_AND_NULL(name);
fflush (f); fflush (f);
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf); cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
fclose(f); fclose(f);
@@ -761,10 +765,7 @@ cJSON * cspot_cb(){
if(cspot_values){ if(cspot_values){
cJSON_AddNumberToObject(values,cspot_args.bitrate->hdr.longopts,cJSON_GetNumberValue(cspot_values)); cJSON_AddNumberToObject(values,cspot_args.bitrate->hdr.longopts,cJSON_GetNumberValue(cspot_values));
} }
// cspot_values = cJSON_GetObjectItem(cspot_config,cspot_args.volume->hdr.longopts);
// if(cspot_values){
// cJSON_AddNumberToObject(values,cspot_args.volume->hdr.longopts,cJSON_GetNumberValue(cspot_values));
// }
cJSON_Delete(cspot_config); cJSON_Delete(cspot_config);
return values; return values;
} }

View File

@@ -281,28 +281,39 @@ void register_default_string_val(const char * key, char * value){
FREE_AND_NULL(existing); FREE_AND_NULL(existing);
} }
void register_default_with_mac(const char* key, char* defval) { char * alloc_get_string_with_mac(const char * val) {
uint8_t mac[6]; uint8_t mac[6];
char macStr[LOCAL_MAC_SIZE + 1]; char macStr[LOCAL_MAC_SIZE + 1];
char* fullvalue = NULL; char* fullvalue = NULL;
esp_read_mac((uint8_t*)&mac, ESP_MAC_WIFI_STA); esp_read_mac((uint8_t*)&mac, ESP_MAC_WIFI_STA);
snprintf(macStr, LOCAL_MAC_SIZE - 1, "-%x%x%x", mac[3], mac[4], mac[5]); snprintf(macStr, LOCAL_MAC_SIZE - 1, "-%x%x%x", mac[3], mac[4], mac[5]);
fullvalue = malloc_init_external(strlen(defval)+sizeof(macStr)+1); fullvalue = malloc_init_external(strlen(val)+sizeof(macStr)+1);
if(fullvalue){ if(fullvalue){
strcpy(fullvalue, defval); strcpy(fullvalue, val);
strcat(fullvalue, macStr); strcat(fullvalue, macStr);
}
else {
ESP_LOGE(TAG,"Memory allocation failed when getting mac value for %s", val);
}
return fullvalue;
}
void register_default_with_mac(const char* key, char* defval) {
char * fullvalue=alloc_get_string_with_mac(defval);
if(fullvalue){
register_default_string_val(key,fullvalue); register_default_string_val(key,fullvalue);
FREE_AND_NULL(fullvalue); FREE_AND_NULL(fullvalue);
} }
else { else {
ESP_LOGE(TAG,"Memory allocation failed when registering default value for %s", key); ESP_LOGE(TAG,"Memory allocation failed when registering default value for %s", key);
} }
} }
void register_default_nvs(){ void register_default_nvs(){
#ifdef CONFIG_CSPOT_SINK #ifdef CONFIG_CSPOT_SINK
register_default_string_val("enable_cspot", STR(CONFIG_CSPOT_SINK)); register_default_string_val("enable_cspot", STR(CONFIG_CSPOT_SINK));
#else
register_default_string_val("enable_cspot", "0");
#endif #endif
#ifdef CONFIG_AIRPLAY_SINK #ifdef CONFIG_AIRPLAY_SINK
@@ -368,10 +379,23 @@ void register_default_nvs(){
register_default_string_val("ethtmout","8"); register_default_string_val("ethtmout","8");
register_default_string_val("dhcp_tmout","8"); register_default_string_val("dhcp_tmout","8");
register_default_string_val("target", CONFIG_TARGET); register_default_string_val("target", CONFIG_TARGET);
#ifdef CONFIG_CSPOT_SINK
register_default_string_val("enable_cspot", STR(CONFIG_CSPOT_SINK)); cJSON * cspot_config=config_alloc_get_cjson("cspot_config");
register_default_string_val("cspot_config", ""); if(!cspot_config){
#endif char * name = alloc_get_string_with_mac(DEFAULT_HOST_NAME);
if(name){
cjson_update_string(&cspot_config,"deviceName",name);
cjson_update_number(&cspot_config,"bitrate",160);
// the call below saves the config and frees the json pointer
config_set_cjson_str_and_free("cspot_config",cspot_config);
FREE_AND_NULL(name);
}
else {
register_default_string_val("cspot_config", "");
}
}
wait_for_commit(); wait_for_commit();
ESP_LOGD(TAG,"Done setting default values in nvs."); ESP_LOGD(TAG,"Done setting default values in nvs.");
} }
@@ -523,8 +547,7 @@ void app_main()
network_register_state_callback(NETWORK_INITIALIZING_STATE,-1, "handle_ap_connect", &handle_ap_connect); network_register_state_callback(NETWORK_INITIALIZING_STATE,-1, "handle_ap_connect", &handle_ap_connect);
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE,ETH_ACTIVE_LINKDOWN_STATE, "handle_network_up", &handle_network_up); network_register_state_callback(NETWORK_ETH_ACTIVE_STATE,ETH_ACTIVE_LINKDOWN_STATE, "handle_network_up", &handle_network_up);
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE,WIFI_INITIALIZING_STATE, "handle_network_up", &handle_network_up); network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE,WIFI_INITIALIZING_STATE, "handle_network_up", &handle_network_up);
MEMTRACE_PRINT_DELTA(); MEMTRACE_PRINT_DELTA();
} }
MEMTRACE_PRINT_DELTA_MESSAGE("Starting Console"); MEMTRACE_PRINT_DELTA_MESSAGE("Starting Console");
console_start(); console_start();

View File

@@ -134,7 +134,7 @@ buildMap(sdkconfig).then((sdkConfigResult ) => {
} }
} }
} }
console.log(`\n\nproperties that are different between the 2 files \n**************************`); console.log(`\n\nproperties that are different ${sdkconfig}<->${comparedFile} \n**************************`);
for (const prop in sdkconfigMap) { for (const prop in sdkconfigMap) {
entry = sdkconfigMap[prop]; entry = sdkconfigMap[prop];
if(entry.type==map_types.COMMENT) continue; if(entry.type==map_types.COMMENT) continue;
@@ -159,7 +159,7 @@ buildMap(sdkconfig).then((sdkConfigResult ) => {
} }
}); });
console.log(`\n\${comparedFile} with missing properties\n**************************`); console.log(`\n\n${comparedFile} with missing properties\n**************************`);
newlines.forEach(line => { newlines.forEach(line => {
console.log(line); console.log(line);
}); });