ESP32自制小板无法连接wifi 但是蓝牙正常,wifi可以扫描
Posted: Tue May 17, 2022 8:17 am
- 自制ESP32 电路板,WIFI sta模式下,蓝牙正常,wifi扫描AP 正常,但是无法连接AP 密码和账号正常,使用ESP32devkit 官方开发板功能正常,可以直接连接成功,自己的板子就没法正常连接,或者显示连接失败,请问一下有大佬知道怎么处理吗?IDF 版本V4.4
[16:13:05.299]收←◆WIFI 扫描完成
扫描到:10个ap信息
[0]: ssid:zzq123 rssi:-35 auth:3
[1]: ssid:305 rssi:-48 auth:4
[2]: ssid:305-dev rssi:-53 auth:4
[3]: ssid:TQLS-YFB rssi:-58 auth:4
[4]: ssid:TQLS-MY-LeiWY rssi:-63 auth:4
[5]: ssid:TQLSFYGS rssi:-64 auth:4
[6]: ssid:DIRECT-81-HP B310 rssi:-65 auth:3
[7]: ssid:LiQ_mytqls rssi:-72 auth:4
[8]: ssid:DIRECT-9E-EPSON-C887FF rssi:-77 auth:3
[9]: ssid:TP-LINK_C636 rssi:-87 auth:4
找到相似可以连接的wifi: zzq123
[0]: ssid:zzq123 rssi:-35 auth:3
(char *)wifi_config.sta.ssid == zzq123
(char *)wifi_config.sta.ssid == 12345678
开始连接新的WIFI释放内存
I (146237) wifi:flush txq
I (146238) wifi:stop sw txq
I (146241) wifi:lmac stop hw txq
[16:13:07.330]收←◆I (148269) wifi:mode : sta (30:c6:f7:56:3a:b4)
I (148270) wifi:enable tsf
重新启动完成
wifi heart0
wifi 启动事件
[16:13:07.356]收←◆I (148300) wifi<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
[16:13:07.819]收←◆wifi heart1
[16:13:08.138]收←◆I (149094) wifi:state: init -> auth (b0)
[16:13:08.202]收←◆I (149155) wifi:state: auth -> assoc (0)
I (149169) wifi:state: assoc -> run (10)
[16:13:08.314]收←◆wifi heart2
[16:13:08.810]收←◆wifi heart3
[16:13:09.306]收←◆wifi h
[16:13:09.328]收←◆eart4
[16:13:09.817]收←◆wifi heart5
[16:13:10.313]收←◆wifi heart6
[16:13:10.809]收←◆wifi heart7
[16:13:11.240]收←◆I (152202) wifi:state: run -> init (fc0)
I (152203)
[16:13:11.266]收←◆wifi<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (152204) wifi<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
wifi 断开事件
下面是代码,请大佬看指教一下
- do
- {
- printf("WIFI 开始扫描\r\n");
- if(esp_wifi_scan_start(NULL,true) != ESP_OK) // 开启扫描 将会扫描 1500ms 1.5s
- {
- printf("WIFI 扫描失败\r\n");
- break;
- }
- printf("WIFI 扫描完成\r\n");
- esp_wifi_scan_get_ap_num(&san_num);
- if(!ap_record)
- {
- ap_record = malloc(san_num *sizeof(wifi_ap_record_t));
- }
- if(!ap_record){printf("内存分配错误,等待下次扫描\r\n");scan_t = 50;break;}
- printf("扫描到:%d个ap信息\r\n",san_num);
- if(esp_wifi_scan_get_ap_records(&san_num,ap_record) != ESP_OK)
- {
- printf("AP信息获得失败\r\n");
- if(ap_record){printf("释放内存\r\n");free(ap_record);ap_record = NULL;}
- break;
- }
- for(u8 i = 0;i < san_num;i++)
- {
- printf("[%d]:\t ssid:%s\t rssi:%d auth:%d\t\r\n",i,ap_record[i].ssid,ap_record[i].rssi,ap_record[i].authmode);
- }
- for(u8 i = 0;i < san_num;i++)
- {
- if(memcmp(ap_record[i].ssid,"zzq123",3) == 0)
- {
- printf("找到相似可以连接的wifi: %s\r\n",ap_record[i].ssid);
- printf("[%d]:\t ssid:%s\t rssi:%d auth:%d\t\r\n",i,ap_record[i].ssid,ap_record[i].rssi,ap_record[i].authmode);
- strcpy((char *)wifi_config.sta.ssid,(char *)ap_record[i].ssid);
- strcpy((char *)wifi_config.sta.password,"12345678");
- printf("(char *)wifi_config.sta.ssid == %s\r\n",(char *)wifi_config.sta.ssid);
- printf("(char *)wifi_config.sta.ssid == %s\r\n",(char *)wifi_config.sta.password);
- strcpy(Config.wifi_sta_ssid,(char *)ap_record[i].ssid);
- printf("开始连接新的WIFI");
- if(ap_record){printf("释放内存\r\n");free(ap_record);ap_record = NULL;}
- esp_wifi_scan_stop();
- esp_wifi_disconnect();
- esp_wifi_stop();
- delay_ms(1000);
- esp_wifi_set_mode(WIFI_MODE_STA);
- ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); // 配置参数
- delay_ms(1000);
- ESP_ERROR_CHECK(esp_wifi_start()); // 开启扫描功能
- printf("重新启动完成\r\n");
- break;
- }
- }
- if(ap_record){printf("释放内存\r\n");free(ap_record);ap_record = NULL;}
- }while(0);