【已解决】关于ESP32-C3 WIFI 在STA模式下配网问题
【已解决】关于ESP32-C3 WIFI 在STA模式下配网问题
ESP32-C3 模块WIFI运行于STA模式,通过蓝牙配置SSID和password, 输入正确的SSID和password成功连接到AP, 在连接状态下,再次输入原来的SSID,但password密码是错的,结果有时密码错也能连上AP, 有时连不上。这是什么情况呢?用的是STA例程的代码修改的。需要密码错时不连上AP。
Re: 关于ESP32-C3 WIFI 在STA模式下配网问题
https://github.com/espressif/esp-idf/bl ... ple_main.c 是基于该示例设置正确密码时,可以连接,修改为错误密码时依然可以连接,对吗?
Re: 关于ESP32-C3 WIFI 在STA模式下配网问题
在https://github.com/espressif/esp-idf/blob/v5.0.2/examples/wifi/getting_started/station/main/station_example_main.c的基础上添加了以下重新配置ssid 和password的语句, wifi_ssid 和wifi_pwd是配置时用户输入的热点ssid和password. 如果网络正常连接的情况下,输入的ssid和错误的password,依然能够获取ip(192.168....之类的)。以下为重新配置时的语句。
wifi_config_t wifi_config = {
.sta = {
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
},
};
ESP_LOGI(TAG, "wifi reconnect start");
bzero(&wifi_config, sizeof(wifi_config_t));
memset(wifi_config.sta.ssid, 0, sizeof(wifi_config.sta.ssid));
memset(wifi_config.sta.password, 0, sizeof(wifi_config.sta.password));
memcpy(wifi_config.sta.ssid, wifi_ssid, sizeof(wifi_config.sta.ssid));
memcpy(wifi_config.sta.password, wifi_pwd, sizeof(wifi_config.sta.password));
ESP_ERROR_CHECK(esp_wifi_disconnect());
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
esp_wifi_connect();
wifi_config_t wifi_config = {
.sta = {
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
},
};
ESP_LOGI(TAG, "wifi reconnect start");
bzero(&wifi_config, sizeof(wifi_config_t));
memset(wifi_config.sta.ssid, 0, sizeof(wifi_config.sta.ssid));
memset(wifi_config.sta.password, 0, sizeof(wifi_config.sta.password));
memcpy(wifi_config.sta.ssid, wifi_ssid, sizeof(wifi_config.sta.ssid));
memcpy(wifi_config.sta.password, wifi_pwd, sizeof(wifi_config.sta.password));
ESP_ERROR_CHECK(esp_wifi_disconnect());
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
esp_wifi_connect();
Re: 关于ESP32-C3 WIFI 在STA模式下配网问题
是的,输入正确的ssid和密码,连接上AP热点和mqtt后,然后通过蓝牙传入ssid和错误密码,结果还是能连上AP和mqtt。ESP_LiuH wrote: ↑Tue Jun 06, 2023 11:20 amhttps://github.com/espressif/esp-idf/bl ... ple_main.c 是基于该示例设置正确密码时,可以连接,修改为错误密码时依然可以连接,对吗?
Re: 关于ESP32-C3 WIFI 在STA模式下配网问题
首先调用 ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
然后调用 ESP_ERROR_CHECK(esp_wifi_disconnect());
```
wifi_config_t wifi_config = {
.sta = {
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
},
};
ESP_LOGI(TAG, "wifi reconnect start");
bzero(&wifi_config, sizeof(wifi_config_t));
memset(wifi_config.sta.ssid, 0, sizeof(wifi_config.sta.ssid));
memset(wifi_config.sta.password, 0, sizeof(wifi_config.sta.password));
memcpy(wifi_config.sta.ssid, wifi_ssid, sizeof(wifi_config.sta.ssid));
memcpy(wifi_config.sta.password, wifi_pwd, sizeof(wifi_config.sta.password));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_disconnect());
esp_wifi_connect();
```
然后调用 ESP_ERROR_CHECK(esp_wifi_disconnect());
```
wifi_config_t wifi_config = {
.sta = {
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
},
};
ESP_LOGI(TAG, "wifi reconnect start");
bzero(&wifi_config, sizeof(wifi_config_t));
memset(wifi_config.sta.ssid, 0, sizeof(wifi_config.sta.ssid));
memset(wifi_config.sta.password, 0, sizeof(wifi_config.sta.password));
memcpy(wifi_config.sta.ssid, wifi_ssid, sizeof(wifi_config.sta.ssid));
memcpy(wifi_config.sta.password, wifi_pwd, sizeof(wifi_config.sta.password));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_disconnect());
esp_wifi_connect();
```
Re: 关于ESP32-C3 WIFI 在STA模式下配网问题
问题已经解决了,在上面的代码和handle里加了一个flag和判断。但你的方案应该是最简洁的。ESP_LiuH wrote: ↑Tue Jun 13, 2023 12:38 pm首先调用 ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
然后调用 ESP_ERROR_CHECK(esp_wifi_disconnect());
```
wifi_config_t wifi_config = {
.sta = {
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
},
};
ESP_LOGI(TAG, "wifi reconnect start");
bzero(&wifi_config, sizeof(wifi_config_t));
memset(wifi_config.sta.ssid, 0, sizeof(wifi_config.sta.ssid));
memset(wifi_config.sta.password, 0, sizeof(wifi_config.sta.password));
memcpy(wifi_config.sta.ssid, wifi_ssid, sizeof(wifi_config.sta.ssid));
memcpy(wifi_config.sta.password, wifi_pwd, sizeof(wifi_config.sta.password));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_disconnect());
esp_wifi_connect();
```
Who is online
Users browsing this forum: No registered users and 147 guests