-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Function Signature
int16_t WiFi.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
);
async (default: false)
• true → Starts a non-blocking (async) scan, allowing the ESP32 to perform other tasks while scanning. You must later check WiFi.scanComplete().
• false → Starts a blocking (sync) scan, meaning execution halts until scanning is finished.
show_hidden (default: false)
• true → Detects hidden SSIDs (slightly higher power consumption).
• false → Ignores hidden SSIDs (default, lower power).
passive (default: false)
• true → Active Scan: The ESP32 sends probe requests to nearby APs, which makes scanning faster but increases power consumption.
• false → Passive Scan: The ESP32 only listens for AP beacons instead of sending probes. This is slower but saves power.
Since async scanning doesn’t block execution, you must check when it’s done:
// Start active scan async, showing hidden AP's, active
WiFi.scanNetworks(true, true, true);
// Later in loop()
if (WiFi.scanComplete() >= 0) {
Serial.println("Scan finished!");
}
WiFi.scanComplete() Return Value, Meaning
>= 0, Scan is complete, and the return value is the number of networks found.
-1, Scan is still running (not finished yet).
-2, Scan failed due to an error (e.g., Wi-Fi not in station mode).