diff --git a/components/esp8266/include/esp_wifi.h b/components/esp8266/include/esp_wifi.h index 4fc2b319..8379a19a 100644 --- a/components/esp8266/include/esp_wifi.h +++ b/components/esp8266/include/esp_wifi.h @@ -90,6 +90,9 @@ extern "C" { #define ESP_WIFI_PARAM_USE_NVS 0 +#define WIFI_PROTOCAL_11B 1 +#define WIFI_PROTOCAL_11G 2 +#define WIFI_PROTOCAL_11N 4 /** * @brief WiFi stack configuration parameters passed to esp_wifi_init call. */ diff --git a/components/esp8266/include/esp_wifi_types.h b/components/esp8266/include/esp_wifi_types.h index 72b24fc6..5e525ab8 100755 --- a/components/esp8266/include/esp_wifi_types.h +++ b/components/esp8266/include/esp_wifi_types.h @@ -92,6 +92,7 @@ typedef enum { WIFI_REASON_AUTH_FAIL = 202, WIFI_REASON_ASSOC_FAIL = 203, WIFI_REASON_HANDSHAKE_TIMEOUT = 204, + WIFI_REASON_BASIC_RATE_NOT_SUPPORT = 205, } wifi_err_reason_t; typedef enum { diff --git a/components/esp8266/lib/VERSION b/components/esp8266/lib/VERSION index 0f59d208..5c01ef87 100644 --- a/components/esp8266/lib/VERSION +++ b/components/esp8266/lib/VERSION @@ -1,6 +1,6 @@ gwen: core: 0dd3307 - net80211: 381d974 + net80211: aceeb79 pp: 522f8df wpa: 33a48e5 espnow: da96924 diff --git a/components/esp8266/lib/libnet80211.a b/components/esp8266/lib/libnet80211.a index c3b07977..f85f007c 100644 Binary files a/components/esp8266/lib/libnet80211.a and b/components/esp8266/lib/libnet80211.a differ diff --git a/components/esp8266/lib/libnet80211_dbg.a b/components/esp8266/lib/libnet80211_dbg.a index 5e8a9545..22cfa8c7 100644 Binary files a/components/esp8266/lib/libnet80211_dbg.a and b/components/esp8266/lib/libnet80211_dbg.a differ diff --git a/components/mqtt/esp-mqtt/examples/emitter-client/main/app_main.c b/components/mqtt/esp-mqtt/examples/emitter-client/main/app_main.c index 756e8985..f8e64817 100755 --- a/components/mqtt/esp-mqtt/examples/emitter-client/main/app_main.c +++ b/components/mqtt/esp-mqtt/examples/emitter-client/main/app_main.c @@ -29,6 +29,9 @@ const static int CONNECTED_BIT = BIT0; static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -38,6 +41,11 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/docs/en/general-notes/index.rst b/docs/en/general-notes/index.rst old mode 100644 new mode 100755 index 01ae81be..b18e03bf --- a/docs/en/general-notes/index.rst +++ b/docs/en/general-notes/index.rst @@ -19,3 +19,9 @@ and now upgrade to the new SDK, please disable the following configuration in th ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ESP8285 or ESP8266 + 1MB flash can use "Copy OTA Mode" for OTA, more details are in the `examples/system/ota `_. + + +3. 802.11n only AP +^^^^^^^^^^^^^^^^^^ + +For better compatibility, the SDK is in bg mode by default. And application can set it to be bgn mode for reconnecting when it fails to connect some 11n only APs, refer to the `examples/wifi/simple_wifi `_. diff --git a/examples/protocols/aws_iot/subscribe_publish/main/subscribe_publish_sample.c b/examples/protocols/aws_iot/subscribe_publish/main/subscribe_publish_sample.c index 947ea441..15eaf8ff 100644 --- a/examples/protocols/aws_iot/subscribe_publish/main/subscribe_publish_sample.c +++ b/examples/protocols/aws_iot/subscribe_publish/main/subscribe_publish_sample.c @@ -151,6 +151,9 @@ static void get_time() static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -159,8 +162,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/aws_iot/thing_shadow/main/thing_shadow_sample.c b/examples/protocols/aws_iot/thing_shadow/main/thing_shadow_sample.c index 70d82701..c8001447 100644 --- a/examples/protocols/aws_iot/thing_shadow/main/thing_shadow_sample.c +++ b/examples/protocols/aws_iot/thing_shadow/main/thing_shadow_sample.c @@ -170,6 +170,9 @@ static void get_time() static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -178,8 +181,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/coap_client/main/coap_client_example_main.c b/examples/protocols/coap_client/main/coap_client_example_main.c index 98f003e1..f28df68d 100644 --- a/examples/protocols/coap_client/main/coap_client_example_main.c +++ b/examples/protocols/coap_client/main/coap_client_example_main.c @@ -159,6 +159,9 @@ static void coap_example_task(void *p) static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -167,8 +170,11 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/coap_server/main/coap_server_example_main.c b/examples/protocols/coap_server/main/coap_server_example_main.c index b3ea7030..9ec2be39 100644 --- a/examples/protocols/coap_server/main/coap_server_example_main.c +++ b/examples/protocols/coap_server/main/coap_server_example_main.c @@ -145,6 +145,9 @@ static void coap_example_thread(void *p) static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -153,8 +156,11 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/esp-mqtt/ssl/main/app_main.c b/examples/protocols/esp-mqtt/ssl/main/app_main.c index 913ba6cf..17818e4e 100644 --- a/examples/protocols/esp-mqtt/ssl/main/app_main.c +++ b/examples/protocols/esp-mqtt/ssl/main/app_main.c @@ -29,6 +29,9 @@ const static int CONNECTED_BIT = BIT0; static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -38,6 +41,11 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/esp-mqtt/ssl_mutual_auth/main/app_main.c b/examples/protocols/esp-mqtt/ssl_mutual_auth/main/app_main.c index 2ebce48b..adf5db9a 100644 --- a/examples/protocols/esp-mqtt/ssl_mutual_auth/main/app_main.c +++ b/examples/protocols/esp-mqtt/ssl_mutual_auth/main/app_main.c @@ -29,6 +29,9 @@ const static int CONNECTED_BIT = BIT0; static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -38,6 +41,11 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/esp-mqtt/tcp/main/app_main.c b/examples/protocols/esp-mqtt/tcp/main/app_main.c index 0d294bd4..ea37a740 100644 --- a/examples/protocols/esp-mqtt/tcp/main/app_main.c +++ b/examples/protocols/esp-mqtt/tcp/main/app_main.c @@ -75,6 +75,9 @@ static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event) static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -84,6 +87,11 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/esp-mqtt/ws/main/app_main.c b/examples/protocols/esp-mqtt/ws/main/app_main.c index 1db33278..6b1e18c8 100644 --- a/examples/protocols/esp-mqtt/ws/main/app_main.c +++ b/examples/protocols/esp-mqtt/ws/main/app_main.c @@ -72,6 +72,9 @@ static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event) static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -81,6 +84,11 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/esp-mqtt/wss/main/app_main.c b/examples/protocols/esp-mqtt/wss/main/app_main.c index e337ea10..06f6307d 100644 --- a/examples/protocols/esp-mqtt/wss/main/app_main.c +++ b/examples/protocols/esp-mqtt/wss/main/app_main.c @@ -29,6 +29,9 @@ const static int CONNECTED_BIT = BIT0; static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -38,6 +41,11 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/esp_http_client/main/app_wifi.c b/examples/protocols/esp_http_client/main/app_wifi.c index da5ac44d..7d8d8d97 100644 --- a/examples/protocols/esp_http_client/main/app_wifi.c +++ b/examples/protocols/esp_http_client/main/app_wifi.c @@ -29,6 +29,9 @@ const int CONNECTED_BIT = BIT0; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -37,8 +40,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/http_request/main/http_request_example_main.c b/examples/protocols/http_request/main/http_request_example_main.c index 37b92679..23266c33 100644 --- a/examples/protocols/http_request/main/http_request_example_main.c +++ b/examples/protocols/http_request/main/http_request_example_main.c @@ -53,6 +53,9 @@ static const char *REQUEST = "GET " WEB_URL " HTTP/1.0\r\n" static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -61,8 +64,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/http_server/advanced_tests/main/main.c b/examples/protocols/http_server/advanced_tests/main/main.c index de32966c..48dead08 100644 --- a/examples/protocols/http_server/advanced_tests/main/main.c +++ b/examples/protocols/http_server/advanced_tests/main/main.c @@ -20,6 +20,8 @@ static const char *TAG="TEST_WIFI"; static esp_err_t event_handler(void *ctx, system_event_t *event) { httpd_handle_t *hd = (httpd_handle_t *) ctx; + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; switch(event->event_id) { case SYSTEM_EVENT_STA_START: @@ -39,6 +41,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED"); + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } ESP_ERROR_CHECK(esp_wifi_connect()); // Stop webserver tests diff --git a/examples/protocols/http_server/persistent_sockets/main/main.c b/examples/protocols/http_server/persistent_sockets/main/main.c index b3535592..4bebbed8 100644 --- a/examples/protocols/http_server/persistent_sockets/main/main.c +++ b/examples/protocols/http_server/persistent_sockets/main/main.c @@ -193,6 +193,8 @@ void stop_webserver(httpd_handle_t server) static esp_err_t event_handler(void *ctx, system_event_t *event) { httpd_handle_t *server = (httpd_handle_t *) ctx; + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; switch(event->event_id) { case SYSTEM_EVENT_STA_START: @@ -211,6 +213,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED"); + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } ESP_ERROR_CHECK(esp_wifi_connect()); /* Stop the webserver */ diff --git a/examples/protocols/http_server/simple/main/main.c b/examples/protocols/http_server/simple/main/main.c index d4b7b386..d29ccaac 100644 --- a/examples/protocols/http_server/simple/main/main.c +++ b/examples/protocols/http_server/simple/main/main.c @@ -220,6 +220,8 @@ void stop_webserver(httpd_handle_t server) static esp_err_t event_handler(void *ctx, system_event_t *event) { httpd_handle_t *server = (httpd_handle_t *) ctx; + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; switch(event->event_id) { case SYSTEM_EVENT_STA_START: @@ -238,6 +240,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED"); + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } ESP_ERROR_CHECK(esp_wifi_connect()); /* Stop the web server */ diff --git a/examples/protocols/https_mbedtls/main/https_mbedtls_example_main.c b/examples/protocols/https_mbedtls/main/https_mbedtls_example_main.c index f455080a..c2879f55 100644 --- a/examples/protocols/https_mbedtls/main/https_mbedtls_example_main.c +++ b/examples/protocols/https_mbedtls/main/https_mbedtls_example_main.c @@ -90,6 +90,9 @@ extern const uint8_t server_root_cert_pem_end[] asm("_binary_server_root_cert_ static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -98,8 +101,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/https_request/main/https_request_example_main.c b/examples/protocols/https_request/main/https_request_example_main.c index d270eb57..027ca28e 100644 --- a/examples/protocols/https_request/main/https_request_example_main.c +++ b/examples/protocols/https_request/main/https_request_example_main.c @@ -88,6 +88,9 @@ extern const uint8_t server_root_cert_pem_end[] asm("_binary_server_root_cert_ static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -96,8 +99,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/https_wolfssl/main/https_wolfssl_example_main.c b/examples/protocols/https_wolfssl/main/https_wolfssl_example_main.c index 6c62760f..560e3efb 100644 --- a/examples/protocols/https_wolfssl/main/https_wolfssl_example_main.c +++ b/examples/protocols/https_wolfssl/main/https_wolfssl_example_main.c @@ -71,6 +71,9 @@ char recv_data[1024] = {0}; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -79,8 +82,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/ibm-mqtt/main/MQTTEcho.c b/examples/protocols/ibm-mqtt/main/MQTTEcho.c index eab14d5f..dcddaaf7 100644 --- a/examples/protocols/ibm-mqtt/main/MQTTEcho.c +++ b/examples/protocols/ibm-mqtt/main/MQTTEcho.c @@ -46,6 +46,9 @@ static const char *TAG = "example"; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -56,8 +59,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/mdns/main/mdns_example_main.c b/examples/protocols/mdns/main/mdns_example_main.c index 1cfcf3e2..6023c0b4 100755 --- a/examples/protocols/mdns/main/mdns_example_main.c +++ b/examples/protocols/mdns/main/mdns_example_main.c @@ -46,6 +46,9 @@ static bool auto_reconnect = true; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -64,6 +67,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) /* This is a workaround as ESP32 WiFi libs don't currently auto-reassociate. */ if (auto_reconnect) { + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); } xEventGroupClearBits(wifi_event_group, IP4_CONNECTED_BIT | IP6_CONNECTED_BIT); diff --git a/examples/protocols/openssl_client/main/openssl_client_example_main.c b/examples/protocols/openssl_client/main/openssl_client_example_main.c index 5a3f2775..a0e63b8e 100644 --- a/examples/protocols/openssl_client/main/openssl_client_example_main.c +++ b/examples/protocols/openssl_client/main/openssl_client_example_main.c @@ -79,6 +79,9 @@ static char recv_buf[OPENSSL_CLIENT_RECV_BUF_LEN]; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -87,8 +90,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/openssl_demo/main/openssl_demo_example_main.c b/examples/protocols/openssl_demo/main/openssl_demo_example_main.c index f4a995eb..a5242542 100644 --- a/examples/protocols/openssl_demo/main/openssl_demo_example_main.c +++ b/examples/protocols/openssl_demo/main/openssl_demo_example_main.c @@ -60,6 +60,9 @@ static char recv_buf[OPENSSL_DEMO_RECV_BUF_LEN]; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -70,8 +73,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/openssl_server/main/openssl_server_example_main.c b/examples/protocols/openssl_server/main/openssl_server_example_main.c index db62ef49..4eef63c3 100644 --- a/examples/protocols/openssl_server/main/openssl_server_example_main.c +++ b/examples/protocols/openssl_server/main/openssl_server_example_main.c @@ -79,6 +79,9 @@ static char recv_buf[OPENSSL_SERVER_RECV_BUF_LEN]; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -87,8 +90,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/sntp/main/sntp_example_main.c b/examples/protocols/sntp/main/sntp_example_main.c index b6e8c903..50687a26 100644 --- a/examples/protocols/sntp/main/sntp_example_main.c +++ b/examples/protocols/sntp/main/sntp_example_main.c @@ -72,6 +72,9 @@ static void obtain_time(void) static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -82,8 +85,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP8266 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/protocols/sockets/tcp_client/main/tcp_client.c b/examples/protocols/sockets/tcp_client/main/tcp_client.c index f2ab52e5..cd546ddb 100644 --- a/examples/protocols/sockets/tcp_client/main/tcp_client.c +++ b/examples/protocols/sockets/tcp_client/main/tcp_client.c @@ -52,6 +52,9 @@ static const char *payload = "Message from ESP32 "; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -68,7 +71,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP"); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT); #ifdef CONFIG_EXAMPLE_IPV6 diff --git a/examples/protocols/sockets/tcp_server/main/tcp_server.c b/examples/protocols/sockets/tcp_server/main/tcp_server.c index 597c4e36..d7c6472a 100644 --- a/examples/protocols/sockets/tcp_server/main/tcp_server.c +++ b/examples/protocols/sockets/tcp_server/main/tcp_server.c @@ -45,6 +45,9 @@ static const char *TAG = "example"; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -61,7 +64,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP"); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT); #ifdef CONFIG_EXAMPLE_IPV6 diff --git a/examples/protocols/sockets/udp_client/main/udp_client.c b/examples/protocols/sockets/udp_client/main/udp_client.c index 187f33d5..79f9aaa5 100644 --- a/examples/protocols/sockets/udp_client/main/udp_client.c +++ b/examples/protocols/sockets/udp_client/main/udp_client.c @@ -52,6 +52,9 @@ static const char *payload = "Message from ESP32 "; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -68,7 +71,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP"); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT); #ifdef CONFIG_EXAMPLE_IPV6 diff --git a/examples/protocols/sockets/udp_multicast/main/udp_multicast_example_main.c b/examples/protocols/sockets/udp_multicast/main/udp_multicast_example_main.c index a21c24a6..5dea3f6a 100644 --- a/examples/protocols/sockets/udp_multicast/main/udp_multicast_example_main.c +++ b/examples/protocols/sockets/udp_multicast/main/udp_multicast_example_main.c @@ -61,6 +61,9 @@ static const char *V6TAG = "mcast-ipv6"; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -73,8 +76,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT); xEventGroupClearBits(wifi_event_group, IPV6_GOTIP_BIT); diff --git a/examples/protocols/sockets/udp_server/main/udp_server.c b/examples/protocols/sockets/udp_server/main/udp_server.c index eb02fdea..2e81d0c5 100644 --- a/examples/protocols/sockets/udp_server/main/udp_server.c +++ b/examples/protocols/sockets/udp_server/main/udp_server.c @@ -45,6 +45,9 @@ static const char *TAG = "example"; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -61,7 +64,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP"); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT); #ifdef CONFIG_EXAMPLE_IPV6 diff --git a/examples/provisioning/custom_config/main/app_prov.c b/examples/provisioning/custom_config/main/app_prov.c index f183f644..ad7253e3 100644 --- a/examples/provisioning/custom_config/main/app_prov.c +++ b/examples/provisioning/custom_config/main/app_prov.c @@ -215,6 +215,10 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event) /* If none of the expected reasons, * retry connecting to host SSID */ g_prov->wifi_state = WIFI_PROV_STA_CONNECTING; + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); } break; diff --git a/examples/provisioning/softap_prov/main/app_prov.c b/examples/provisioning/softap_prov/main/app_prov.c index 69aed5a5..864fe7fc 100644 --- a/examples/provisioning/softap_prov/main/app_prov.c +++ b/examples/provisioning/softap_prov/main/app_prov.c @@ -198,6 +198,10 @@ esp_err_t app_prov_event_handler(void *ctx, system_event_t *event) g_prov->wifi_disconnect_reason = WIFI_PROV_STA_AP_NOT_FOUND; break; default: + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } /* If none of the expected reasons, * retry connecting to host SSID */ g_prov->wifi_state = WIFI_PROV_STA_CONNECTING; diff --git a/examples/system/console/main/cmd_wifi.c b/examples/system/console/main/cmd_wifi.c index 52be40ef..c60f1e81 100644 --- a/examples/system/console/main/cmd_wifi.c +++ b/examples/system/console/main/cmd_wifi.c @@ -25,11 +25,19 @@ const int CONNECTED_BIT = BIT0; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_GOT_IP: xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGI(__func__, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/system/ota/native_ota/1MB_flash/new_to_new_no_old/main/ota_example_main.c b/examples/system/ota/native_ota/1MB_flash/new_to_new_no_old/main/ota_example_main.c index e53d94ca..4f1838da 100644 --- a/examples/system/ota/native_ota/1MB_flash/new_to_new_no_old/main/ota_example_main.c +++ b/examples/system/ota/native_ota/1MB_flash/new_to_new_no_old/main/ota_example_main.c @@ -78,6 +78,9 @@ const int CONNECTED_BIT = BIT0; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -86,8 +89,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/system/ota/native_ota/1MB_flash/new_to_new_no_old_copy/main/ota_example_main.c b/examples/system/ota/native_ota/1MB_flash/new_to_new_no_old_copy/main/ota_example_main.c index 8024c22b..4df5a494 100644 --- a/examples/system/ota/native_ota/1MB_flash/new_to_new_no_old_copy/main/ota_example_main.c +++ b/examples/system/ota/native_ota/1MB_flash/new_to_new_no_old_copy/main/ota_example_main.c @@ -78,6 +78,9 @@ const int CONNECTED_BIT = BIT0; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -86,8 +89,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/system/ota/native_ota/1MB_flash/new_to_new_with_old/main/ota_example_main.c b/examples/system/ota/native_ota/1MB_flash/new_to_new_with_old/main/ota_example_main.c index 159aa1b6..a8188b9c 100644 --- a/examples/system/ota/native_ota/1MB_flash/new_to_new_with_old/main/ota_example_main.c +++ b/examples/system/ota/native_ota/1MB_flash/new_to_new_with_old/main/ota_example_main.c @@ -78,6 +78,9 @@ const int CONNECTED_BIT = BIT0; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -86,8 +89,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/system/ota/native_ota/2+MB_flash/new_to_new_no_old/main/ota_example_main.c b/examples/system/ota/native_ota/2+MB_flash/new_to_new_no_old/main/ota_example_main.c index 8024c22b..4df5a494 100644 --- a/examples/system/ota/native_ota/2+MB_flash/new_to_new_no_old/main/ota_example_main.c +++ b/examples/system/ota/native_ota/2+MB_flash/new_to_new_no_old/main/ota_example_main.c @@ -78,6 +78,9 @@ const int CONNECTED_BIT = BIT0; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -86,8 +89,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/system/ota/native_ota/2+MB_flash/new_to_new_with_old/main/ota_example_main.c b/examples/system/ota/native_ota/2+MB_flash/new_to_new_with_old/main/ota_example_main.c index 159aa1b6..a8188b9c 100644 --- a/examples/system/ota/native_ota/2+MB_flash/new_to_new_with_old/main/ota_example_main.c +++ b/examples/system/ota/native_ota/2+MB_flash/new_to_new_with_old/main/ota_example_main.c @@ -78,6 +78,9 @@ const int CONNECTED_BIT = BIT0; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -86,8 +89,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/system/ota/simple_ota_example/main/simple_ota_example.c b/examples/system/ota/simple_ota_example/main/simple_ota_example.c index 880cf7f3..039b1dbe 100644 --- a/examples/system/ota/simple_ota_example/main/simple_ota_example.c +++ b/examples/system/ota/simple_ota_example/main/simple_ota_example.c @@ -101,6 +101,9 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt) static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -109,8 +112,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: - /* This is a workaround as ESP32 WiFi libs don't currently - auto-reassociate. */ + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/wifi/simple_wifi/main/simple_wifi.c b/examples/wifi/simple_wifi/main/simple_wifi.c index 11571dde..975d393e 100644 --- a/examples/wifi/simple_wifi/main/simple_wifi.c +++ b/examples/wifi/simple_wifi/main/simple_wifi.c @@ -39,6 +39,9 @@ static const char *TAG = "simple wifi"; static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); @@ -59,6 +62,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) event->event_info.sta_disconnected.aid); break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, WIFI_CONNECTED_BIT); break; diff --git a/examples/wifi/smart_config/main/smartconfig_main.c b/examples/wifi/smart_config/main/smartconfig_main.c index 0839c4ce..5bca3459 100644 --- a/examples/wifi/smart_config/main/smartconfig_main.c +++ b/examples/wifi/smart_config/main/smartconfig_main.c @@ -35,6 +35,9 @@ void smartconfig_example_task(void * parm); static esp_err_t event_handler(void *ctx, system_event_t *event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch(event->event_id) { case SYSTEM_EVENT_STA_START: xTaskCreate(smartconfig_example_task, "smartconfig_example_task", 4096, NULL, 3, NULL); @@ -43,6 +46,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; diff --git a/examples/wifi/wps/main/wps.c b/examples/wifi/wps/main/wps.c index efbd9f27..bef9ebb8 100644 --- a/examples/wifi/wps/main/wps.c +++ b/examples/wifi/wps/main/wps.c @@ -41,6 +41,9 @@ static esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_TEST_MODE); static esp_err_t event_handler(void* ctx, system_event_t* event) { + /* For accessing reason codes in case of disconnection */ + system_event_info_t *info = &event->event_info; + switch (event->event_id) { case SYSTEM_EVENT_STA_START: ESP_LOGI(TAG, "SYSTEM_EVENT_STA_START"); @@ -54,6 +57,11 @@ static esp_err_t event_handler(void* ctx, system_event_t* event) case SYSTEM_EVENT_STA_DISCONNECTED: ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED"); + ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason); + if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) { + /*Switch to 802.11 bgn mode */ + esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCAL_11B | WIFI_PROTOCAL_11G | WIFI_PROTOCAL_11N); + } ESP_ERROR_CHECK(esp_wifi_connect()); break;