-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
重设参数无法让设备WiFi重连,回调函数无响应 (IDFGH-13868) #14713
Comments
很奇怪的一点就是在 |
在优化加入判断逻辑后,就没有出现这样的问题,但是我还是不能理解,如果在下一次连接WiFi前,我并没有调用 |
// 判断重连标志
EventBits_t current_bits = xEventGroupGetBits(s_wifi_event_group);
if (current_bits & WIFI_RESET_BIT) {
ESP_ERROR_CHECK(esp_wifi_connect());
ESP_LOGI(TAG, "WIFI_RESET_BIT is set, indicating a reset is needed.");
} |
@cannnnnnnnnnnn |
Hi @hansw123 感谢你的解答,我是参考的官方例程去实现的功能,但是我在该功能的基础上修改成了需要多次连接和当设备连接该网络的情况下可以连接其他网络的需求,我现在的实际问题已经解决,但是在回调函数的响应问题上我还是疑惑 |
我通过实际的测试发现函数 // WIFI连接
esp_err_t wifi_connect(const char *ssid, const char *passwd)
{
wifi_config_t wifi_sta_config = {
.sta = {
.ssid = {0},
.password = {0},
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
}};
// 显式地复制字符串到结构体成员
strlcpy((char *)wifi_sta_config.sta.ssid, (const char *)ssid, sizeof(wifi_sta_config.sta.ssid));
strlcpy((char *)wifi_sta_config.sta.password, (const char *)passwd, sizeof(wifi_sta_config.sta.password));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_sta_config));
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
pdFALSE,
pdFALSE,
portMAX_DELAY);
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
* happened. */
if (bits & WIFI_CONNECTED_BIT) {
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",ssid, passwd);
} else {
// 清除标志位
xEventGroupClearBits(s_wifi_event_group, WIFI_CONNECTED_BIT | WIFI_FAIL_BIT);
ESP_LOGI(TAG, "Failed to connect to SSID:%s password:%s", ssid, passwd);
}
return ESP_OK;
} 我在初始化完成后第一次使用,连接错误的WiFi密码我在回调函数里面设置的五次回调都有信息输出,但是我在第二次调用设置错误的WiFi名称和密码回调函数就没有响应,起初我还以为是标志位设置的有问题,但是在调试中发现不是这样的问题。 当我在后面的调试解决问题的过程中发现,在调用 |
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { 因为这边wifi 连接操作是看到WIFI_EVENT_STA_START 事件,这个事件要esp_wifi_start() 触发 |
https://github.com/espressif/esp-idf/blob/master/examples/wifi/getting_started/station/main/station_example_main.c |
Hi @hansw123 好的,感谢你的解答 |
Answers checklist.
General issue report
逻辑代码如下:
我希望在不影响AP工作状态的情况下去配置连接另一个WiFi应如何操作呢?
The text was updated successfully, but these errors were encountered: