Skip to content

Commit

Permalink
feat(scan): Allow setting scan timeout in milliseconds (#9738)
Browse files Browse the repository at this point in the history
  • Loading branch information
me-no-dev authored Jun 3, 2024
1 parent 58e61ef commit 2122811
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libraries/WiFi/src/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ extern "C" {

bool WiFiScanClass::_scanAsync = false;
uint32_t WiFiScanClass::_scanStarted = 0;
uint32_t WiFiScanClass::_scanTimeout = 10000;
uint32_t WiFiScanClass::_scanTimeout = 60000;
uint16_t WiFiScanClass::_scanCount = 0;
void *WiFiScanClass::_scanResult = 0;

void WiFiScanClass::setScanTimeout(uint32_t ms) {
WiFiScanClass::_scanTimeout = ms;
}

/**
* Start scan WiFi networks available
* @param async run in async mode
Expand All @@ -60,7 +64,6 @@ int16_t
return WIFI_SCAN_RUNNING;
}

WiFiScanClass::_scanTimeout = max_ms_per_chan * 20;
WiFiScanClass::_scanAsync = async;

WiFi.enableSTA(true);
Expand Down Expand Up @@ -92,7 +95,7 @@ int16_t
if (WiFiScanClass::_scanAsync) {
return WIFI_SCAN_RUNNING;
}
if (WiFiGenericClass::waitStatusBits(WIFI_SCAN_DONE_BIT, 10000)) {
if (WiFiGenericClass::waitStatusBits(WIFI_SCAN_DONE_BIT, _scanTimeout)) {
return (int16_t)WiFiScanClass::_scanCount;
}
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/WiFi/src/WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
class WiFiScanClass {

public:
void setScanTimeout(uint32_t ms);

int16_t scanNetworks(
bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300, uint8_t channel = 0, const char *ssid = nullptr,
const uint8_t *bssid = nullptr
Expand Down

0 comments on commit 2122811

Please sign in to comment.