Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added channel, ssid scan #4636

Merged
merged 4 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,53 @@ int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden) {

}

/**
* Start scan WiFi networks available
* @param async run in async mode
* @param show_hidden show hidden networks
* @param channel scan only this channel (0 for all channels)
* @param ssid* scan for only this ssid

* @return Number of discovered networks
*/
int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden, uint8 channel, uint8* ssid) {
if(ESP8266WiFiScanClass::_scanStarted) {
return WIFI_SCAN_RUNNING;
}

ESP8266WiFiScanClass::_scanAsync = async;

WiFi.enableSTA(true);

int status = wifi_station_get_connect_status();
if(status != STATION_GOT_IP && status != STATION_IDLE) {
wifi_station_disconnect();
}

scanDelete();

struct scan_config config;
memset(&config, 0, sizeof(config));
config.ssid = ssid;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference between the original method and your overloaded one are these two lines:
config.ssid = ssid;
config.channel = channel;

where ssid and channel are new arguments.

Instead of duplicating the entire method, please just add the two arguments to the original method, and in the .h put set default values to keep the current behavior (i.e.: channel = 0 and ssid = nullptr, because of the memset).

config.channel = channel;
config.show_hidden = show_hidden;
if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiScanClass::_scanDone))) {
ESP8266WiFiScanClass::_scanComplete = false;
ESP8266WiFiScanClass::_scanStarted = true;

if(ESP8266WiFiScanClass::_scanAsync) {
delay(0); // time for the OS to trigger the scan
return WIFI_SCAN_RUNNING;
}

esp_yield();
return ESP8266WiFiScanClass::_scanCount;
} else {
return WIFI_SCAN_FAILED;
}

}

/**
* Starts scanning WiFi networks available in async mode
* @param onComplete the event handler executed when the scan is done
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP8266WiFi/src/ESP8266WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ESP8266WiFiScanClass {
public:

int8_t scanNetworks(bool async = false, bool show_hidden = false);
int8_t scanNetworks(bool async, bool show_hidden, uint8 channel, uint8* ssid = NULL);
void scanNetworksAsync(std::function<void(int)> onComplete, bool show_hidden = false);

int8_t scanComplete();
Expand Down