1. Introduction
All the previous demonstrations which are related to WiFi, ESP32 operate in Station mode in which ESP32 will become a client of a WiFi network. In this demonstration, we will make it an Access Point in which it is a WiFi emission point so that WiFi clients can connect to it. Note that ESP32 can operation in both Station and Access Point mode where it is a WiFi client and emit WiFi as well.
2. Hardware
You do not need any extra hardware.
3. Software
In order to set the WiFi mode for ESP32 we will use the function:
- WiFi.mode(mode): where mode can be: WIFI_OFF (turn off WiFi), WIFI_STA (Station mode), WIFI_AP (Access Point mode), WIFI_AP_STA (both Station and Access Point mode)
- WiFi.begin(ssid, password): use this function to make ESP32 a WiFi client that connect to a network have ssid and password. If we use this function we need not to use WiFi.mode(WIFI_STA).
WiFi.softAP(ssidAP, passwordAP): use this function to make ESP32 an Access Point that has authentication information are ssidAP and passwordAP. If we use this function we need not to use WiFi.mode(WIFI_AP)
Let's make ESP32 an Access Point with authentication information below:
- WiFi.mode(mode): where mode can be: WIFI_OFF (turn off WiFi), WIFI_STA (Station mode), WIFI_AP (Access Point mode), WIFI_AP_STA (both Station and Access Point mode)
- WiFi.begin(ssid, password): use this function to make ESP32 a WiFi client that connect to a network have ssid and password. If we use this function we need not to use WiFi.mode(WIFI_STA).
WiFi.softAP(ssidAP, passwordAP): use this function to make ESP32 an Access Point that has authentication information are ssidAP and passwordAP. If we use this function we need not to use WiFi.mode(WIFI_AP)
Let's make ESP32 an Access Point with authentication information below:
- ssid is "ESP32ap"
- password is "12345678"
Note: the default IP add ress of ESP32 in AP mode is "192.168.4.1"
Create an Arduino project and save as esp32ap with the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <WiFi.h> const char *ssid = "ESP32ap"; const char *password = "12345678"; void setup() { Serial.begin(115200); Serial.println(); Serial.print("Configuring access point..."); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); } void loop() { } |
Figure: ESP32 as AP mode with default local IP is 192.168.4.1
Figure: from smartphone you will see AP (ESP32ap), fill password and connected
15 Comments
Nice tutorial.
I followed all the steps and it showed connnected,but
I could not go on the net with IE or Chrome on my cellphone or my laptop.No pages were loaded.
I tried a few diff wifi connections without any problems.
I wonder if you know what the problem is.
Thanks
Regards
Thanks for your reply.
On my laptop computer, I can see ESPap32 connected, but on my IE and Chrome browsers
they say no internet connection. I cannot connect to the Internet.
My router is working well because I can connect to a few wifi connections without any problems.
Thanks.
When ESp is in AP mode, it is similar to a router. Your computer connect to esp, it is similar to connecting to a router but since esp not connect to internet so your computer can not access to internet. I hope i understand properly your question :)
Best regards.
Thanks for everything.
It is working finally.
Best regards
Great tutorial.
One question: ho do I make the AP secure (SSL, https)?
It is quite complicated.
You should look in the WifiClientSecure to see mbed_tls
and learn how to setup a secure server.
Regards,
When compiling the esp32, I receive the error 'class WiFiClass' has no member named 'softAP'
Anyone has any solution?
All the best!
Best
thank you!