To configure the ESP8266 as an access point, to allow other devices like smartphones or laptops to connect to it, you can use the
softAP function:
#include
<
ESP8266WiFi
.
h
>
// Include the Wi-Fi library
const
char
*
ssid
=
"ESP8266 Access Point"
;
// The name of the Wi-Fi network that will be created
const
char
*
password
=
"thereisnospoon"
;
// The password required to connect to it, leave blank for an open network
void
setup
() {
Serial
.
begin
(115200);
delay
(10);
Serial
.
println
(
'\n'
);
WiFi
.
softAP
(ssid
,
password);
// Start the access point
Serial
.
(
"Access Point \""
);
Serial
.
(ssid);
Serial
.
println
(
"\" started"
);
Serial
.
(
"IP address:\t"
);
Serial
.
println
(
WiFi
.
softAPIP
());
// Send the IP address of the ESP8266 to the computer
}
void
loop
() { }
To see if it works, open the Wi-Fi settings on your computer, look for a network called "ESP8266 Access Point", enter the password
"thereisnospoon", and connect to it. Then open a terminal, and ping to 192.168.4.1 (this is the default IP address of our ESP AP). You'll
see that the ESP responds to your pings.
However, if you try to go to an online website, you'll get a timeout or a DNS error. This is because the ESP itself is not connected to the
internet. The sub-net that consists of the ESP and the computer is not connected to any other networks, so there's no way for a packet
on this network to make it to the Internet.
If you connected a second station to the ESP access point on the other hand, you would be able to ping from one station to the other
without problems, because they're on the same network.