mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
feat(esp_wifi): Showcases the new scan by bitmap config
- Showcases the ability to scan by the bitmap config newly added to the wifi_scan_config_t by implementing it in the scan config
This commit is contained in:
parent
9a88dab748
commit
0d7c909e87
@ -23,7 +23,8 @@ Open the project configuration menu (`idf.py menuconfig`).
|
||||
In the `Example Configuration` menu:
|
||||
|
||||
* Set the Example configuration.
|
||||
* Use `Max size of scan list` to set the maximum nunber of access points in the list.
|
||||
* Use `Max size of scan list` to set the maximum number of access points in the list.
|
||||
* Use 'Scan Channel list' to list specific channels you wish to scan. For eg. 1,6,9,11. By Default all channels will be scanned.
|
||||
|
||||
### Build and Flash
|
||||
|
||||
@ -47,7 +48,7 @@ As you run the example, you will see the following log:
|
||||
I (443) wifi:wifi firmware version: 6bff005
|
||||
I (443) wifi:wifi certification version: v7.0
|
||||
I (443) wifi:config NVS flash: enabled
|
||||
I (443) wifi:config nano formating: disabled
|
||||
I (443) wifi:config nano formatting: disabled
|
||||
I (453) wifi:Init data frame dynamic rx buffer num: 32
|
||||
I (453) wifi:Init management frame dynamic rx buffer num: 32
|
||||
I (463) wifi:Init management short buffer num: 32
|
||||
|
@ -7,4 +7,11 @@ menu "Example Configuration"
|
||||
help
|
||||
The size of array that will be used to retrieve the list of access points.
|
||||
|
||||
config EXAMPLE_USE_SCAN_CHANNEL_BITMAP
|
||||
bool "Scan only non overlapping channels using Channel bitmap"
|
||||
default 0
|
||||
help
|
||||
Enable this to scan only the non overlapping channels i.e 1,6,11 by mentioning a channel bitmap
|
||||
in scan config. If you wish to scan a different set of specific channels, please edit the channel_list
|
||||
array in scan.c. Channels for a 2.4 ghz network range should range from 1-14.
|
||||
endmenu
|
||||
|
@ -17,9 +17,16 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_event.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "regex.h"
|
||||
|
||||
#define DEFAULT_SCAN_LIST_SIZE CONFIG_EXAMPLE_SCAN_LIST_SIZE
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_USE_SCAN_CHANNEL_BITMAP
|
||||
#define USE_CHANNEL_BTIMAP 1
|
||||
#define CHANNEL_LIST_SIZE 3
|
||||
static uint8_t channel_list[CHANNEL_LIST_SIZE] = {1, 6, 11};
|
||||
#endif /*CONFIG_EXAMPLE_USE_SCAN_CHANNEL_BITMAP*/
|
||||
|
||||
static const char *TAG = "scan";
|
||||
|
||||
static void print_auth_mode(int authmode)
|
||||
@ -133,6 +140,17 @@ static void print_cipher_type(int pairwise_cipher, int group_cipher)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_CHANNEL_BTIMAP
|
||||
static void array_2_channel_bitmap(const uint8_t channel_list[], const uint8_t channel_list_size, wifi_scan_config_t *scan_config) {
|
||||
|
||||
for(uint8_t i = 0; i < channel_list_size; i++) {
|
||||
uint8_t channel = channel_list[i];
|
||||
scan_config->channel_bitmap.ghz_2_channels |= (1 << channel);
|
||||
}
|
||||
}
|
||||
#endif /*USE_CHANNEL_BTIMAP*/
|
||||
|
||||
|
||||
/* Initialize Wi-Fi as sta and set scan method */
|
||||
static void wifi_scan(void)
|
||||
{
|
||||
@ -149,9 +167,23 @@ static void wifi_scan(void)
|
||||
uint16_t ap_count = 0;
|
||||
memset(ap_info, 0, sizeof(ap_info));
|
||||
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
#ifdef USE_CHANNEL_BTIMAP
|
||||
wifi_scan_config_t *scan_config = (wifi_scan_config_t *)calloc(1,sizeof(wifi_scan_config_t));
|
||||
if (!scan_config) {
|
||||
ESP_LOGE(TAG, "Memory Allocation for scan config failed!");
|
||||
return;
|
||||
}
|
||||
array_2_channel_bitmap(channel_list, CHANNEL_LIST_SIZE, scan_config);
|
||||
esp_wifi_scan_start(scan_config, true);
|
||||
|
||||
#else
|
||||
esp_wifi_scan_start(NULL, true);
|
||||
#endif /*USE_CHANNEL_BTIMAP*/
|
||||
|
||||
ESP_LOGI(TAG, "Max AP number ap_info can hold = %u", number);
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));
|
||||
@ -165,7 +197,6 @@ static void wifi_scan(void)
|
||||
}
|
||||
ESP_LOGI(TAG, "Channel \t\t%d", ap_info[i].primary);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
|
Loading…
x
Reference in New Issue
Block a user