Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 15 additions & 5 deletions libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ std::function<void(int)> ESP8266WiFiScanClass::_onComplete;

/**
* 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 (NULL for all ssid's)
* @param async run in async mode
* @param show_hidden show hidden networks
* @param passive scan type passive or active
* @param max_ms_per_chan scan time per channel
* @param channel scan only this channel (0 for all channels)
* @param ssid* scan for only this ssid (NULL for all ssid's)
* @return Number of discovered networks
*/
int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden, uint8 channel, uint8* ssid) {
int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden, bool passive, uint32_t max_ms_per_chan, uint8_t channel, uint8* ssid) {
if(ESP8266WiFiScanClass::_scanStarted) {
return WIFI_SCAN_RUNNING;
}
Expand All @@ -87,6 +89,14 @@ int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden, uint8 ch
config.ssid = ssid;
config.channel = channel;
config.show_hidden = show_hidden;
if(passive){
config.scan_type = WIFI_SCAN_TYPE_PASSIVE;
config.scan_time.passive = max_ms_per_chan;
} else {
config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
config.scan_time.active.min = 100;
config.scan_time.active.max = max_ms_per_chan;
}
if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiScanClass::_scanDone))) {
ESP8266WiFiScanClass::_scanComplete = false;
ESP8266WiFiScanClass::_scanStarted = true;
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ESP8266WiFiScanClass {

public:

int8_t scanNetworks(bool async = false, bool show_hidden = false, uint8 channel = 0, uint8* ssid = NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a breaking change.
What about leaving the former API without the default values ?

+ int8_t scanNetworks(bool async = false, bool show_hidden = false, uint8 channel, uint8* ssid);

Copy link
Contributor Author

@dok-net dok-net May 24, 2021

Choose a reason for hiding this comment

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

Looks fishy, and indeed, it leads to an ambiguity error for the case of default ssid argument, because the compiler cannot distiguish the actual parameter for bool passive from uint8_t channel. Better break once, for good, in the breaking 3.0 release.

        //scanResult = WiFi.scanNetworks(/*async=*/false, /*hidden=*/true, /*passive=*/ false);
        scanResult = WiFi.scanNetworks(/*async=*/false, /*hidden=*/true, /*channel=*/0);
WiFiScan.ino: 25:54: error: call of overloaded 'scanNetworks(bool, bool, int)' is ambiguous
   25 |         scanResult = WiFi.scanNetworks(/*async=*/false, /*hidden=*/true, /*channel=*/0)
   |                                                      ^
 
ESP8266WiFi.h:36: In file included from
WiFiScan.ino:7: from
ESP8266WiFiScan.h:37: note  candidate  int8_t ESP8266WiFiScanClass  scanNetworks(bool, bool, uint8, uint8*)
   37 |         int8_t scanNetworks(bool async, bool show_hidden, uint8 channel, uint8* ssid = NULL) __attribute__((deprecated)) {
   |                ^~~~~~~~~~~~
ESP8266WiFiScan.h:40: note  candidate  int8_t ESP8266WiFiScanClass  scanNetworks(bool, bool, bool, uint32_t, uint8_t, uint8*)
   40 |         int8_t scanNetworks(bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300, uint8_t channel = 0, uint8* ssid = NULL)
   |                ^~~~~~~~~~~~

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

int8_t scanComplete();
Expand Down