
初级技术员

- 积分
- 46

- 在线时间
- 15 小时
- 精华
- 0
- 注册时间
- 2013-6-30
- 最后登录
- 2020-11-20
|
3.开机自动连wifi
在bk7221u_release\applications\main.c中添加如下代码:(参考bk7221u_release\samples\airkiss\airkiss.c)
- #ifdef AUTO_CONNETC_AP
- static void iot_wlan_sta_connected_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
- {
- <b><font color="#ff0000"> rt_kprintf("wlan sta connected event callback \n");</font></b>
- }
- static void iot_wlan_sta_disconnected_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
- {
- rt_kprintf("wlan sta disconnected event callback \n");
- }
- static int iot_station_connect(char *ssid, char *passwd)
- {
- rt_err_t result = RT_EOK;
- struct rt_wlan_info info;
- struct rt_wlan_device *wlan;
- rt_tick_t tick = 0;
- wlan = (struct rt_wlan_device *)rt_device_find(WIFI_DEVICE_STA_NAME);
- if (!wlan)
- {
- rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_STA_NAME);
- return -1;
- }
- result = rt_wlan_init(wlan, WIFI_STATION);
- rt_wlan_register_event_handler(wlan, WIFI_EVT_STA_CONNECTED, iot_wlan_sta_connected_event);
- rt_wlan_register_event_handler(wlan, WIFI_EVT_STA_DISCONNECTED, iot_wlan_sta_disconnected_event);
- rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_AES_PSK, ssid);
- result = rt_wlan_connect(wlan, &info, passwd);
- rt_wlan_info_deinit(&info);
- return result;
- }
- #endif
复制代码 然后在main函数添加调用:
- #ifdef AUTO_CONNETC_AP
- iot_station_connect("哈喽","12345678");
- #endif
复制代码
编译,打包,下载;
开机就可看到log如下:
- [I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.
- ROMFS File System initialized!
- ===sd card open:0===
- msh />cmd 1:3
- found a Ver2.00 or later SDCard
- support 2.7~3.6V
- send cmd55&cmd41 complete, card is ready
- Standard Capacity SD Memory Card
- cmd3 is ok, card rca:0x1
- size:200 total_block:77800
- Bsize:200;Total_block:77800
- sdcard initialize is done
- [SDIO]:rt_sdcard_control, CMD=16
- SD File System initialized!
- [I/FAL] The FAL MTD NOR device (filesystem) created successfully
- LFS Filesystem initialized! filesystem ==> /flash0
- [Flash]EasyFlash V3.0.4 is initialize success.
- [Flash]You can get the latest version on https://github.com/armink/EasyFlash .
- Enter normal mode...
- app_init finished
- [I/player] RT-Thread lightweight player v1.2.7-c1f72849-249590703_Release [build Sep 7 2019]
- set_volume 65-65
- adc-buf:00900dc4, adc-buf-len:5120, ch:1
- audio_device_mic_opened
- [DRV_WLAN]drivers\wlan\drv_wlan.c L917 beken_wlan_control cmd: case WIFI_INIT!
- [wifi_connect]: fast connect
- psk = 51efed97b72487536861353ba363b98d4132d5f47eddfe9f5f75fdcd96df2486
- [sa_sta]MM_RESET_REQ
- [sa_sta]ME_CONFIG_REQ
- [sa_sta]ME_CHAN_CONFIG_REQ
- [sa_sta]MM_START_REQ
- bssid bc-54-fc-f8-aa-4a
- security2cipher 2 2 16 16 security=5
- cipher2security 2 2 16 16
- hapd_intf_add_vif,type:2, s:0, id:0
- wpa_dInit
- wpa_supplicant_req_scan
- Setting scan request: 0.100000 sec
- MANUAL_SCAN_REQ
- wpa_supplicant_scan
- Cancelling scan request
- wpa_driver_associate
- scan_start_req_handler
- sm_auth_send:1
- sm_auth_handler
- sm_assoc_rsp_handler
- rc_init: station_id=0 format_mod=2 pre_type=0 short_gi=1 max_bw=0
- rc_init: nss_max=0 mcs_max=7 r_idx_min=0 r_idx_max=3 no_samples=10
- ---------SM_CONNECT_IND_ok
- wpa_driver_assoc_cb
- get_scan_rst_null
- Cancelling scan request
- get_scan_rst_null
- hapd_intf_add_key CCMP
- add sta_mgmt_get_sta
- sta:0, vif:0, key:0
- sta_mgmt_add_key
- add hw key idx:24
- hapd_intf_add_key CCMP
- add is_broadcast_ether_addr
- sta:255, vif:0, key:1
- add hw key idx:1
- ctrl_port_hdl:1
- [wlan_connect]:start tick = 1457, connect done tick = 1834, total = 377
- [wlan_connect]:start tick = 1457, connect done tick = 1840, total = 383
- <b><font color="#ff0000">wlan sta connected event callback </font></b>
- sta_ip_start
- configuring interface mlan (with DHCP client)
- dhcp_check_status_init_timer
- IP UP: 192.168.30.175
- [ip_up]:start tick = 1457, ip_up tick = 3763, total = 2306
- msh />
复制代码
4.下期预告:
麻雀一号上云;
谢谢大家。
|
|