Home / References / ESP32 Library / WiFi API / WiFiMulti
Description
The WiFiMulti.setAllowOpenAP
method allows or disallows connections to open (unsecured) access points when using the WiFiMulti
class in the ESP32 WiFi Library.
Syntax and Usage
– Allows connection to open access points.
WiFiMulti.setAllowOpenAP(true);
– Disallows connection to open access points.
WiFiMulti.setAllowOpenAP(false);
Argument(s)
bool allow
– A boolean value to allow (true
) or disallow (false
) connection to open APs.
Return Value
This method does not return any value.
Example Codes
Example: Allowing connection to open APs
This code demonstrates how to use the ESP32 WiFiMulti class’s setAllowOpenAP()
method to enable or disable connections to open (password-less) WiFi networks. By calling setAllowOpenAP(true)
, the ESP32 is allowed to connect to open networks, which are typically less secure but can be useful in certain environments. This method provides flexibility when managing a mix of secured and unsecured networks in your WiFiMulti setup.
To use this code, replace “OpenNetwork” with the name of an open WiFi network you want to connect to. Upload the code to your ESP32 and open the Serial Monitor at 115200 baud. The code adds an open network using addAP()
and enables connections to open networks with setAllowOpenAP(true)
. If the connection is successful, it prints the IP address; otherwise, it notifies of the failure. Ensure the ESP32 is within range of the specified open network for a successful connection.
/*
* Author: Avant Maker
* Date: February 18, 2025
* Version: 1.0
* Description: This example code demonstrates how to
* use WiFiMulti.setAllowOpenAP to configure the ESP32 so it can
* connect to open (unsecured) WiFi access points (APs).
*
* 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>
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
void setup() {
Serial.begin(115200);
wifiMulti.addAP("OpenNetwork", ""); // Open network with no password
wifiMulti.setAllowOpenAP(true);
if (wifiMulti.run() == WL_CONNECTED) {
Serial.println("Connected to Open Network");
Serial.println(WiFi.localIP());
} else {
Serial.println("Failed to connect");
}
}
void loop() {}
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 Library Index
- ESP32 WiFiClient Library
- ESP32 HTTPClient Library
- ESP32 WiFiClientSecure Library
- ESP32 WebServer Library
- ESP32 WiFi Library
- Which ESP32 Boards are Recommended for Learners
- How to Copy Codes from AvantMaker.com
- What is SPIFFS and how to upload files to it?
- What is LIttleFS and how to upload files to it?
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!