ESP32 WiFi Library –WiFiMulti.setScanActiveMinTime

Home / References / ESP32 Library / WiFi API / WiFiScan

Description

The WiFi.setScanActiveMinTime method is part of the ESP32 WiFi Library and is used to set the minimum time (in milliseconds) that the ESP32 spends actively scanning each WiFi channel during a scan operation. This method allows developers to fine-tune the scanning process, balancing between scan speed and thoroughness, which is particularly useful for IoT projects requiring efficient network detection.


Syntax and Usage

Below is the syntax and how to use the WiFi.setScanActiveMinTime method in your ESP32 projects:

WiFi.setScanActiveMinTime(time)

This method can only be used with an argument specifying the minimum active scan time. Here’s the usage scenario:

  • With Argument: Sets the minimum time the ESP32 will spend actively scanning each channel. This is the primary way to use this method, allowing customization of the scan duration for better control over performance.

Argument(s)

  • time: An integer representing the minimum time in milliseconds that the ESP32 will spend actively scanning each WiFi channel. The value must be greater than or equal to 0. A higher value increases the scan duration per channel, potentially improving detection accuracy, while a lower value speeds up the scan process.

Return Value

The WiFi.setScanActiveMinTime method does not return a value. It is a void function that configures the scanning behavior of the ESP32 WiFi module.


Example Codes

Basic Usage to Set Minimum Scan Time

Note: This example demonstrates how to set a minimum active scan time of 100 milliseconds per channel before performing a WiFi scan. Upload this code to your ESP32 and open the Serial Monitor at 115200 baud to see the list of detected networks.

/*
 * Author: Avant Maker
 * Date: February 21, 2025
 * Version: 1.0
 * Description: This example code demonstrates how to 
 * set a minimum active scan time of 100 milliseconds per channel 
 * before performing a WiFi scan. Upload this code to your ESP32 
 * and open the Serial Monitor at 115200 baud to see the list of 
 * detected networks.
 *
 * License: MIT 
 * 
 * Code Source: This example code is sourced from the Comprehensive 
 * Guide to the ESP32 Arduino Core Library, accessible on 
 * AvantMaker.com. For additional code examples and in-depth 
 * documentation related to the ESP32 Arduino Core Library, 
 * please visit:
 *
 * https://avantmaker.com/references/esp32-arduino-core-index/
 *
 * AvantMaker.com, your premier destination for all things 
 * DIY, AI, IoT, Smart Home, and STEM projects. We are dedicated 
 * to empowering makers, learners, and enthusiasts with the resources
 * they need to bring their innovative ideas to life.
 */

#include <WiFi.h>

void setup() {
    Serial.begin(115200);

    // Set WiFi to station mode
    WiFi.mode(WIFI_STA);

    // Set the minimum active scan time to 100 milliseconds per channel
    WiFi.setScanActiveMinTime(100);

    // Start scanning for WiFi networks
    int networkCount = WiFi.scanNetworks();

    // Print the results
    if (networkCount == 0) {
        Serial.println("No networks found.");
    } else {
        Serial.print(networkCount);
        Serial.println(" networks found:");
        for (int i = 0; i < networkCount; i++) {
            Serial.print(i + 1);
            Serial.print(": ");
            Serial.print(WiFi.SSID(i));
            Serial.print(" (");
            Serial.print(WiFi.RSSI(i));
            Serial.println(" dBm)");
        }
    }
}

void loop() {
    // Nothing to do here
}

AvantMaker Tutorial Suggestion

If you want to learn more about the ESP32’s WiFi capabilities, we’ve created a beginner-friendly guide that explains them in detail. Just click the link below, and you’ll be teleported to that page. It will clear up any confusion you may have while connecting your ESP32 to WiFi or setting it up as a WiFi access point (AP).

ESP32 Essential Guide – Network Section – WiFi Chapter

ESP32 Library Index

ESP32 Arduino Core Library


FAQ

Ready to experiment and explore more about ESP32? Visit our website’s All About ESP32 Resources Hub, packed with tutorials, guides, and tools to inspire your maker journey. Experiment, explore, and elevate your skills with everything you need to master this powerful microcontroller platform!

error: Content is protected !!