At times, it may be necessary to move your ESP32 device between different locations, such as using your home WiFi at home, office WiFi at work, or mobile WiFi while on the move. It would be convenient to register multiple access points on the ESP32 development board so that it can automatically choose and connect to the available AP.
In this article, we will guide you on how to achieve this. The ESP32 will intelligently select the AP with the strongest signal among the available options to establish a connection.
It is called WiFi Multi Mode.
The main method is wifiMulti.run(). Essentially, this helper method performs three tasks:
- Conducts a WiFi scan to identify available access points (APs).
- Selects the best AP based on signal strength and the lists you provided.
- Attempts to connect to the chosen AP within a default timeout of 5 seconds.
By utilizing this method, you no longer need to manually implement a while loop or handle the connection process yourself, as typically done in basic WiFi mode. This method simplifies the process by handling all the necessary steps on your behalf.
|wifiMulti.addAP(SSID, PWD)||Add a Wireless AP|
|wifiMulti.run()||Connect to the best AP. Default timeout is 5 seconds.|
|wifiMulti.run(3000)||Change default connection timeout to 3 seconds|
One drawback of the mentioned method is that it requires scanning all available WiFi networks, which results in longer execution time and increased power consumption. If you are utilizing an ESP32 device powered by a battery, it is highly recommended to use the basic WiFi mode with a fixed IP address to optimize power efficiency.