1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-02 18:12:20 +01:00

Add support for passive WiFi scanning (#4666)

* Add support for passive WiFi scanning.

* Apply suggestions from code review

Made changes suggested by @jesserockz

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

---------

Co-authored-by: BellaCoola <unknown>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Bella Coola
2023-04-20 03:53:42 +00:00
committed by GitHub
parent afc2b3b74f
commit 4c39631428
7 changed files with 36 additions and 15 deletions

View File

@@ -736,7 +736,7 @@ WiFiSTAConnectStatus WiFiComponent::wifi_sta_connect_status_() {
}
return WiFiSTAConnectStatus::IDLE;
}
bool WiFiComponent::wifi_scan_start_() {
bool WiFiComponent::wifi_scan_start_(bool passive) {
// enable STA
if (!this->wifi_mode_(true, {}))
return false;
@@ -746,9 +746,13 @@ bool WiFiComponent::wifi_scan_start_() {
config.bssid = nullptr;
config.channel = 0;
config.show_hidden = true;
config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
config.scan_time.active.min = 100;
config.scan_time.active.max = 300;
config.scan_type = passive ? WIFI_SCAN_TYPE_PASSIVE : WIFI_SCAN_TYPE_ACTIVE;
if (passive) {
config.scan_time.passive = 300;
} else {
config.scan_time.active.min = 100;
config.scan_time.active.max = 300;
}
esp_err_t err = esp_wifi_scan_start(&config, false);
if (err != ESP_OK) {