Browse Source

fix boot loop caused by competing wifi_manager and cmd_wifi

It is now possible to set a default autoexec command to automatically
join wifi when wifi_manager is disabled. To test wifi stability without
wifi_manager, use the following commands:

nvs_set bypass_wm str -v "1"
nvs_set autoexec str -v "1"
nvs_set autoexec1 str -v "squeezelite -o I2S -b 500:2000 -d all=info -m
nvs_set autoexec2 str -v "join <ssid> <password>"
ESP32"
restart

Note that squeezelite occupies the "autoexec1" slot to avoid conflicts
with the wifi manager web configuration page when it is re-enabled. To
re-enable the wifi-manager, use the following commands:

nvs_set bypass_wm str -v "0"
restart

--
Additional change:  Credits page now has a button to enable the nvs
editor even in ota mode
Sebastien 5 năm trước cách đây
mục cha
commit
04b82e5bf6
4 tập tin đã thay đổi với 31 bổ sung16 xóa
  1. 0 8
      components/wifi-manager/wifi_manager.c
  2. 5 3
      main/cmd_wifi.c
  3. 19 3
      main/console.c
  4. 7 2
      main/esp_app_main.c

+ 0 - 8
components/wifi-manager/wifi_manager.c

@@ -543,14 +543,6 @@ char* wifi_manager_get_ap_list_json(){
 
 
 static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){
-//    if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
-//		led_blink_pushed(LED_GREEN, 250, 250);
-//        esp_wifi_connect();
-//        xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
-//    } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
-//		led_unpush(LED_GREEN);
-//        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
-//    }
 
     if(event_base== WIFI_EVENT){
 		switch(event_id) {

+ 5 - 3
main/cmd_wifi.c

@@ -32,7 +32,7 @@
 #include "tcpip_adapter.h"
 #include "esp_event.h"
 #include "led.h"
-
+extern bool bypass_wifi_manager;
 #define JOIN_TIMEOUT_MS (10000)
 
 extern EventGroupHandle_t wifi_event_group;
@@ -92,7 +92,7 @@ static void initialise_wifi(void)
         return;
     }
     tcpip_adapter_init();
-    wifi_event_group = xEventGroupCreate();
+    // Now moved to esp_app_main: wifi_event_group = xEventGroupCreate();
     ESP_ERROR_CHECK(esp_event_loop_create_default());
     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
     ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
@@ -194,5 +194,7 @@ void register_wifi_join()
 void register_wifi()
 {
     register_wifi_join();
-    initialise_wifi();
+    if(bypass_wifi_manager){
+    	initialise_wifi();
+    }
 }

+ 19 - 3
main/console.c

@@ -32,7 +32,7 @@ pthread_t thread_console;
 static void * console_thread();
 void console_start();
 static const char * TAG = "console";
-
+extern bool bypass_wifi_manager;
 
 
 /* Prompt to be printed before each line.
@@ -56,6 +56,12 @@ void process_autoexec(){
 	uint8_t autoexec_flag=0;
 
 	char * str_flag = get_nvs_value_alloc(NVS_TYPE_STR, "autoexec");
+	if(!bypass_wifi_manager){
+		ESP_LOGW(TAG, "Procesing autoexec commands while wifi_manager active.  Wifi related commands will be ignored.");
+	}
+#if RECOVERY_APPLICATION
+	ESP_LOGD(TAG, "Processing autoexec commands in recovery mode.  Squeezelite commands will be ignored.")
+#endif
 
 	if(str_flag !=NULL ){
 		autoexec_flag=atoi(str_flag);
@@ -66,8 +72,18 @@ void process_autoexec(){
 				ESP_LOGD(TAG,"Getting command name %s", autoexec_name);
 				autoexec_value= get_nvs_value_alloc(NVS_TYPE_STR, autoexec_name);
 				if(autoexec_value!=NULL ){
-					ESP_LOGI(TAG,"Running command %s = %s", autoexec_name, autoexec_value);
-					run_command(autoexec_value);
+					if(!bypass_wifi_manager && strstr(autoexec_value, "join ")!=NULL ){
+						ESP_LOGW(TAG,"Ignoring wifi join command.");
+					}
+#if RECOVERY_APPLICATION
+					else if(!strstr(autoexec_value, "squeezelite " ) ){
+						ESP_LOGW(TAG,"Ignoring command. ");
+					}
+#endif
+					else {
+						ESP_LOGI(TAG,"Running command %s = %s", autoexec_name, autoexec_value);
+						run_command(autoexec_value);
+					}
 					ESP_LOGD(TAG,"Freeing memory for command %s name", autoexec_name);
 					free(autoexec_value);
 				}

+ 7 - 2
main/esp_app_main.c

@@ -49,6 +49,7 @@ EventGroupHandle_t wifi_event_group;
 bool enable_bt_sink=false;
 bool enable_airplay=false;
 bool jack_mutes_amp=false;
+bool bypass_wifi_manager=false;
 const int CONNECTED_BIT = BIT0;
 #define JOIN_TIMEOUT_MS (10000)
 
@@ -216,10 +217,14 @@ void app_main()
 	/* start the wifi manager */
 	led_blink(LED_GREEN, 250, 250);
 	char * bypass_wm = get_nvs_value_alloc_default(NVS_TYPE_STR, "bypass_wm", "0", 0);
-	if((strcmp(bypass_wm,"1")==0 ||strcasecmp(bypass_wm,"y")==0)){
-		ESP_LOGW(TAG,"wifi manager is disabled. Please use wifi commands to connect to your wifi access point.");
+	bypass_wifi_manager=(strcmp(bypass_wm,"1")==0 ||strcasecmp(bypass_wm,"y")==0);
+
+
+	if(bypass_wifi_manager){
+		ESP_LOGW(TAG,"\n\nwifi manager is disabled. Please use wifi commands to connect to your wifi access point.\n\n");
 	}
 	else {
+		ESP_LOGW(TAG,"\n\nwifi manager is ENABLED. Starting...\n\n");
 		wifi_manager_start();
 		wifi_manager_set_callback(EVENT_STA_GOT_IP, &cb_connection_got_ip);
 		wifi_manager_set_callback(WIFI_EVENT_STA_DISCONNECTED, &cb_connection_sta_disconnected);