1 代码说明
- 初始化Wi-Fi协议栈,可以使用
mxos_network_init只初始化Wi-Fi协议栈,也可以使用mxos_system_init初始化系统顺便初始化Wi-Fi协议栈 - 使用
mxos_system_notify_register注册【扫描完成】事件的回调函数wifi_scan_notify - 调用
mwifi_scan开始扫描模组周围的SSID
1.1 函数mxos_system_notify_register
/*** @brief Register a user function to a MXOS notification.* @param notify_type: The type of MXOS notification.* @param functionAddress: The address of user function.* @param arg: The address of argument, which will be called by registered user function.* @retval kNoErr is returned on success, otherwise, kXXXErr is returned.*/merr_t mxos_system_notify_register( mxos_notify_types_t notify_type, void* functionAddress, void* arg );
第一个入参是业务场景需要关注的wifi相关的事件类型。
第二个入参是一个函数指针,当发生对应wifi事件时系统会通过函数指针调用传入的这个函数,因此,传入的函数指针所指向的函数不建议做太多工作,除非你知道你在干什么;另外,第一个参数不同,函数指针指向的函数定义可能也不同。
第三个入参是一个指向任意类型数据的指针,本文用不到。
1.2 回调函数
scan用到的回调函数,第一个参数为扫描到的SSID数量,第二个参数是一个结构体的数组
static void wifi_scan_notify(int num, mwifi_ap_info_t *ap_list);
结构体定义如下
typedef struct{int rssi; /**< Signal strength of the AP */char ssid[33]; /**< SSID of the AP */uint8_t bssid[6]; /**< BSSID of the AP */int channel; /**< Channel of the AP */mwifi_security_t security; /**< security of the AP */} mwifi_ap_info_t;
1.3 mwifi_scan
void mwifi_scan(const char *ssid);
- 该函数会启动一个线程做扫描,所以调用该函数的线程不会被阻塞。
- 函数有一个入参:如果不为NULL,表示扫描指定的SSID;如果为NULL,表示扫描模组周围所有SSID。
2 各模组情况
| No | 芯片 | 编译命令 | 备注 |
|---|---|---|---|
| 1 | MX1300 | mdev build wifi/scan/ emc3080mdev build wifi/scan/ emc3180 |
|
| 2 | MX131x | mdev build wifi/scan/ emc3280mdev build wifi/scan/ emc3380 |
暂不可用 |
| 3 | TG7100C | mdev不支持对此芯片执行-f操作,需要使用其他软件烧录固件 |
|
| 4 | |||
| 5 | |||
| 6 |
