ESP8266 WiFi Access Point

The ESP8266 is a WiFi module that allows you to connect to WiFi access points, or even create one. In this tutorial we will build a WiFi access point for our IoT projects that allows authorized clients to have access to our IoT network. We will also build a client that has access, and see how to use the two together.

The Access Point

To configure an access point, you set the ESP8266 up with two commands:


AT+CWMODE=3
AT+CWSAP="DAEESP","Password",1,3
    

The two commands above set up the ESP8266 as a client and an access point, and configure the access point by name "DAEESP", and password "Password" on channel 1 using WPA/WPA2 encryption. That last one is to keep the neighbors out of your thermostats. Use a name that distinguishes your access point from the many others likely to be in the area, and a password that is adequate to keep unwelcome visitors out.

That is really all there is to setting up an access point. Just as an FYI, you can't join your own access point from a client on the same ESP. The ESP8266's response is "FAIL". You can join other access points, like your wireless router. This allows you to build a network free from your main network, accessible only by your IoT devices. This is a safety feature that prevents intruders on either your main network or your IoT network from accessing the other.

Using the Access Point

The access point is used like any network access point. All who connect to it are on the same vlan - they can all connect with each other and trade data. Clients can still choose to connect to other networks without changing anything in the IoT network, they just can't connect to two different access points at the same time (such as your ESP access point and your wireless router). To connect to the access point on the client:

AT+CWDHCP=2,1

OK
AT+CWJAP="DAEESP","Password"

WIFI CONNECTED
WIFI GOT IP

OK
    

The first command tells the client to get an IP address from the access point. The second command tells the client to log in to the DAEESP network. That is the network we built on the access point. If you see "WIFI CONNECTED" followed by "WIFI DISCONNECT", you are not getting an IP address, so enter that AT+CWDHCP=2,1 command again to be sure you got it right.

If you received an IP address from the access point, you can see what it is:

    
AT+CIPSTA?

+CIPSTA:ip:"192.168.4.2"
+CIPSTA:gateway:"192.168.4.1"
+CIPSTA:netmask:"255.255.255.0"

OK
    

Once you have the client connected to the access point, you can access any other devices which are also connected, including the access point itself. To do that, use the IP address in the "AT+CIPSTA?" command listed as the gateway - typically "192.168.4.1". Below is a session in which the client connected with the server, sent "MAGIC", which you can't see, and received "xyzzy" from the server running on the access point.


AT+CIPSTART=1,"TCP","192.168.4.1",80

1,CONNECT

OK
AT+CIPSEND=1,5


OK
> 

busy s...

Recv 5 bytes

SEND OK

+IPD,1,5:xyzzy
    
Arduino Board Logo

 

Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support

Arduino-Board

Stay updated

Sign up if you would like to receive our once monthly newsletter.