资讯专栏INFORMATION COLUMN

ESP32-C3入门教程 网络篇①——WiFi Scan 快速扫描附近AP无线热点

Simon_Zhou / 1880人阅读

摘要:,初始化底层堆栈,创建默认事件循环。,使用默认配置创建对象,将连接到并注册默认处理程序。,为驱动初始化分配资源,如控制结构缓冲区结构等,这个也启动任务。必须先调用此,然后才能调用所有其他,设置工作模式为或,默认模式为模式。

一、快速运行

  • 示例项目中,选择WiFi—>scan
  • menuconfig配置ESP32C3-Specific—>Rec 0
  • 芯片选择ESP32-C3(Built-in USB JTAG)
  • 快速运行ESP-IDF Build, Flash and Monitor(左下角)

二、运行效果


三、程序流程

  • nvs_flash_init,初始化默认 NVS 分区。
  • esp_netif_init,初始化底层TCP/IP堆栈
  • esp_event_loop_create_default,创建默认事件循环。
  • esp_netif_create_default_wifi_sta,使用默认WiFi Station配置创建esp_netif对象,将netif连接到WiFi并注册默认WiFi处理程序。
  • esp_wifi_init,为 WiFi 驱动初始化 WiFi 分配资源,如 WiFi 控制结构、RX/TX 缓冲区、WiFi NVS 结构等,这个 WiFi 也启动 WiFi 任务。必须先调用此API,然后才能调用所有其他WiFi API
  • esp_wifi_set_mode,设置WiFi工作模式为station、soft-AP或station+soft-AP,默认模式为soft-AP模式。本程序设置为station
  • esp_wifi_start,根据配置,启动WiFi
  • esp_wifi_scan_start,扫描所有有效的AP
  • esp_wifi_scan_get_ap_records,获取上次扫描中找到的AP列表
  • esp_wifi_scan_get_ap_num,获取上次扫描中找到的AP数

四、关键函数

4.1 扫描所有有效的AP

  • config,扫描的配置
  • block,是否堵塞程序运行
/**  * @brief     Scan all available APs.  *  * @attention If this API is called, the found APs are stored in WiFi driver dynamic allocated memory and the  *            will be freed in esp_wifi_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records to cause  *            the memory to be freed once the scan is done  * @attention The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds.  *            Values above 1500ms may cause station to disconnect from AP and are not recommended.  *  * @param     config  configuration of scanning  * @param     block if block is true, this API will block the caller until the scan is done, otherwise  *                         it will return immediately  *  * @return  *    - ESP_OK: succeed  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init  *    - ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start  *    - ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout  *    - ESP_ERR_WIFI_STATE: wifi still connecting when invoke esp_wifi_scan_start  *    - others: refer to error code in esp_err.h  */esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *config, bool block);

4.2 获取上次扫描中找到的AP列表

  • number,返回的最大ap个数
  • ap_records,返回的app记录数组
/**  * @brief     Get AP list found in last scan  *  * @param[inout]  number As input param, it stores max AP number ap_records can hold.  *                As output param, it receives the actual AP number this API returns.  * @param         ap_records  wifi_ap_record_t array to hold the found APs  *  * @return  *    - ESP_OK: succeed  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init  *    - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start  *    - ESP_ERR_INVALID_ARG: invalid argument  *    - ESP_ERR_NO_MEM: out of memory  */esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records);

4.3 获取上次扫描中找到的AP数

  • number,存储上次扫描中找到的API数
/**  * @brief     Get number of APs found in last scan  *  * @param[out] number  store number of APs found in last scan  *  * @attention This API can only be called when the scan is completed, otherwise it may get wrong value.  *  * @return  *    - ESP_OK: succeed  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init  *    - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start  *    - ESP_ERR_INVALID_ARG: invalid argument  */esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number);

觉得好,就一键三连呗(点赞+收藏+关注)

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/121072.html

相关文章

  • ESP32-S2上使用SPI接口芯片DM9051NP转以太网的无线物联网网关开发指导

    摘要:前言芯片接口占用管脚数量比以太网的少,版线布局可更精简。网卡芯片介绍接口网卡芯片是为方物联网行业进以太网通信而开发出的解决方案。此应用可用于监控家庭物联网网关搭建等。 前言     DM9051NP芯片 SPI接口占用管脚数量比以太网PHY的RMII/MII少,PCBA版线布局可更精简。...

    wangjuntytl 评论0 收藏0
  • wifi破解方法总结(精华)

    摘要:方法五针对有功能的路由器,使用码破解方法五针对有功能的路由器,使用码破解简单来说,对于开启了功能的路由器,当你知道了它的码,就可以连接到并获取明文密码,不再需要其他认证措施。 目录 方法一:默认密码大猜想 方法二:推荐使用wifi万能钥匙 方法三:抓不到握手包的情况下,使用网卡爆破(用字典和...

    _DangJin 评论0 收藏1
  • 《安富莱嵌入式周报》第228期:2021.08.30--2021.09.05

    摘要:论坛下载由于库是不带中值滤波器的,需要自己实现,所以花了点时间制作了一个章节。红色线是波形高斯白噪声均匀白噪声。第版教程发布中文显示章节论坛下载可以直接运行界面效果,也可以使用可以直接编译运行。上位机已经整合主机,下一版发布 往期周报汇总地址:http://www.armbbs.cn/for...

    刘东 评论0 收藏0
  • kali破解WiFi密码

    实验环境 VMware Workstation Pro 虚拟机 kali linux 2021.2 kali Linux系统 无线网卡 支持监听 这些自己准备好,我们直接进入主题 一,查看信息 ifconfig 查看网卡名 二,激活网卡 ifconfig wlan0 up 激活网卡 执行完命令,我们可以看到下面没有什么提示,说明我们的网卡激活成功了! 三,结束干扰进程` airmon-ng...

    xiaotianyi 评论0 收藏0
  • Ubuntu台式机如何用usb无线网卡共享网络

    摘要:台式机如何用无线网卡共享网络由于工作需要,要在台式机上搭建一个热点,供手机联网,在这里记录一下,因为确实有很多坑。无线网卡的选择,要满足两个条件,支持模拟功能,和支持系统或能找到对应芯片组的驱动。 Ubuntu台式机如何用usb无线网卡共享网络Walker Xu 由于工作需要,要在ubuntu台式机上搭建一个wifi热点,供手机联网,在这里记录一下,因为确实有很多坑。usb无线网卡的选...

    HollisChuang 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<