#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_event_loop.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "nvs_flash.h"
#define MAXIMUM_AP 20
static char *auth_mode_type(wifi_auth_mode_t auth_mode)
{
char *types[] = {"OPEN", "WEP", "WPA PSK", "WPA2 PSK", "WPA WPA2 PSK", "MAX"};
return types[auth_mode];
}
void wifiInit() {
ESP_ERROR_CHECK(nvs_flash_init());
wifi_init_config_t wifi_config = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&wifi_config));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_start());
}
void app_main()
{
wifiInit();
wifi_scan_config_t scan_config = {
.ssid = 0,
.bssid = 0,
.channel = 0,
.show_hidden = true
};
ESP_ERROR_CHECK(esp_wifi_scan_start(&scan_config, true));
wifi_ap_record_t wifi_records[MAXIMUM_AP];
uint16_t max_records = MAXIMUM_AP;
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&max_records, wifi_records));
printf("Number of Access Points Found: %d\n", max_records);
printf("\n");
printf(" SSID | Channel | RSSI | Authentication Mode \n");
printf("***************************************************************\n");
for (int i = 0; i < max_records; i++)
printf("%32s | %7d | %4d | %12s\n", (char *)wifi_records[i].ssid, wifi_records[i].primary, wifi_records[i].rssi, auth_mode_type(wifi_records[i].authmode));
printf("***************************************************************\n");
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK