mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
Merge branch 'bugfix/scan_example_cosmetic_fixes' into 'master'
Bugfix/Wi-Fi scan example cosmetic fixes See merge request !1539
This commit is contained in:
@ -8,13 +8,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
this example shows how to use all channel scan or fast scan to connect
|
This example shows how to use the All Channel Scan or Fast Scan to connect
|
||||||
In the fast scan mode, scan will end after find matched AP, in this mode, you
|
to a Wi-Fi network.
|
||||||
can set the threshold of auth mode and signal, the filter will ignore the AP
|
|
||||||
whose auth mode and rssi below the threshold.
|
In the Fast Scan mode, the scan will stop as soon as the first network matching
|
||||||
In the all channel scan, scan will end after scan all the channel, and will
|
the SSID is found. In this mode, an application can set threshold for the
|
||||||
the best AP to connect, you can sort by signal or auth mode, auth mode is follow
|
authentication mode and the Signal strength. Networks that do not meet the
|
||||||
the rule WPA2>WPA>WEP.
|
threshold requirements will be ignored.
|
||||||
|
|
||||||
|
In the All Channel Scan mode, the scan will end only after all the channels
|
||||||
|
are scanned, and connection will start with the best network. The networks
|
||||||
|
can be sorted based on Authentication Mode or Signal Strength. The priority
|
||||||
|
for the Authentication mode is: WPA2 > WPA > WEP > Open
|
||||||
*/
|
*/
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
@ -23,7 +28,7 @@
|
|||||||
#include "esp_event_loop.h"
|
#include "esp_event_loop.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
|
|
||||||
/*set the ssid and password via "make menuconfig"*/
|
/*Set the SSID and Password via "make menuconfig"*/
|
||||||
#define DEFAULT_SSID CONFIG_WIFI_SSID
|
#define DEFAULT_SSID CONFIG_WIFI_SSID
|
||||||
#define DEFAULT_PWD CONFIG_WIFI_PASSWORD
|
#define DEFAULT_PWD CONFIG_WIFI_PASSWORD
|
||||||
|
|
||||||
@ -65,43 +70,43 @@ static const char *TAG = "scan";
|
|||||||
|
|
||||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||||
{
|
{
|
||||||
switch(event->event_id) {
|
switch (event->event_id) {
|
||||||
case SYSTEM_EVENT_STA_START:
|
case SYSTEM_EVENT_STA_START:
|
||||||
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_START");
|
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_START");
|
||||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_STA_GOT_IP:
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP");
|
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_GOT_IP");
|
||||||
ESP_LOGI(TAG, "got ip:%s\n",
|
ESP_LOGI(TAG, "Got IP: %s\n",
|
||||||
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||||
break;
|
break;
|
||||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED");
|
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_DISCONNECTED");
|
||||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*init wifi as sta and set scan method*/
|
/* Initialize Wi-Fi as sta and set scan method */
|
||||||
static void wifi_scan(void)
|
static void wifi_scan(void)
|
||||||
{
|
{
|
||||||
tcpip_adapter_init();
|
tcpip_adapter_init();
|
||||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||||
|
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
wifi_config_t wifi_config = {
|
wifi_config_t wifi_config = {
|
||||||
.sta = {
|
.sta = {
|
||||||
.ssid = DEFAULT_SSID,
|
.ssid = DEFAULT_SSID,
|
||||||
.password = DEFAULT_PWD,
|
.password = DEFAULT_PWD,
|
||||||
.scan_method = DEFAULT_SCAN_METHOD,
|
.scan_method = DEFAULT_SCAN_METHOD,
|
||||||
.sort_method = DEFAULT_SORT_METHOD,
|
.sort_method = DEFAULT_SORT_METHOD,
|
||||||
.threshold.rssi = DEFAULT_RSSI,
|
.threshold.rssi = DEFAULT_RSSI,
|
||||||
.threshold.authmode = DEFAULT_AUTHMODE,
|
.threshold.authmode = DEFAULT_AUTHMODE,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||||
|
Reference in New Issue
Block a user