wifi scan模式可以简单理解为ESP32模块像手机一样扫描周围的wifi模块。
由于在此章节中开始使用包含头文件和.C文件的方式,只记录核心函数源码。最后验证的结果还是通过ESP32的监视器指令直接打印扫描信息。
首先是qy_wifi_scan.h文件:
#ifndef _QY_WIFI_SCAN_H_
#define _QY_WIFI_SCAN_H_
void qy_wifi_scan_start(void);
void qy_wifi_scan_stop(void);
#endif
然后是qy_wifi_scan.c文件:
#include "qy_wifi_scan.h"
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "esp_event.h"
#include "nvs_flash.h"
#define CONFIG_EXAMPLE_SCAN_LIST_SIZE 10
#define DEFAULT_SCAN_LIST_SIZE CONFIG_EXAMPLE_SCAN_LIST_SIZE
static const char *TAG = "scan";
static void print_auth_mode(int authmode)
{
switch (authmode) {
case WIFI_AUTH_OPEN:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_OPEN");
break;
case WIFI_AUTH_WEP:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WEP");
break;
case WIFI_AUTH_WPA_PSK:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA_PSK");
break;
case WIFI_AUTH_WPA2_PSK:
ESP_LOGI(TAG, "Authmode \tWIFI_AUTH_WPA2_PSK");
break;