







You can download our e-book ‘Learn Arduino from Scratch’ from this link

Last time we hosted a simple web server on an ESP8266. Today we are going a step further, we are going to turn the ESP8266 into an access point (AP). Yes, then you can connect to the ESP8266 via your phone or laptop, or any other device for that matter. As you will see the Arduino core library makes it really easy to initialize the AP mode instead of the station mode. Almost all functions will work in the same manner in both modes.

As an example, to keep things as simple as possible, we will just turn the ESP8266 into a WiFi access point and then you can add what we learned in Part 3 to host a simple web page on the access point!! Lets start with the AP mode first.

#include <ESP8266WiFi.h> const char *ssid = "myESPNetwork"; const char *password = "thisESPisProtected"; //the password should be 8 char or more //setting the addresses IPAddress ip(192,168,8,1); IPAddress gateway(192, 168, 8, 1); IPAddress subnet(255, 255, 255, 0); void setup() { WiFi.mode(WIFI_AP); //switching to AP mode WiFi.softAP(ssid, password); //initializing the AP with ssid and password. This will create a WPA2-PSK secured AP WiFi.config(ip,gateway,subnet); WiFi.begin(); } void loop() { }









As you can see it is very simple to turn the ESP8266 into a router. First, we give the ESP an SSID (the wifi name which will be visible) and a password (with WPA2-PSK security). Next we set some addresses, first the IP address of the ESP, the access point, the gateway can be any device on the network which will provide internet access or access to other networks. Then the subnet, which … ohh never mind, not important!!

Next up we set the ESP in AP mode and giving it an ssid and password in the setup function. Assign the addresses with WiFi.config and start the AP with WiFi.begin.

Now fetch your mobile or laptop, search for your new WiFi access point and connect. You will find that however small the ESP8266 has a very powerful transmitter. In the next tutorial you will see how you can use your ESP8266 for a simple WiFi bridge between an existing network and the newly created one.

Happy Coding!