Connect Your ESP8266 To Any Available Wi-Fi network

The ESP8266 is a microcontroller developed by Espressif Systems. Known as a WiFi module, this microcontroller can be used to perform various WiFi-related activities, with applications in home automation and beyond. Ranging in price and features, there are many types of ESP8266 modules available – but all are incredibly useful in the IoT world.

Regardless of the IoT application you’ve developed, there are two ways to connect your ESP8266 to the cloud. First, you can input your WiFi credentials in the ESP8266’s firmware to establish the required connection and start sending data. A second way – which we’ll cover step-by-step below – is by building your own access point into the board, creating a universal firmware that will establish a connection to any available network with just the press of a button.

Requirements

Step 1. Hardware setup

Note: The Ubidots team made some modifications in the ConfigManager Library to implement a routine that launches the AP mode by simply pressing an external reset button.

Depending on the ESP8266 module you choose, you may need to assign the reset pin using this library version. The default button settings are assigned to PIN 5; if using a NodeMCU, you must connect the button into the D1 pin.

Step 2. Set up the Arduino IDE with your device

Before using any ESP8266 device, you’ll have to install the boards into the Arduino IDE. Follow the steps below to compile the board.

15.Now, paste the below code in the Arduino IDE. Once pasted, assign your desired device and variable labels, as well as your unique Ubidots TOKEN. If you don’t know your Ubidots TOKEN, find out how to get one here.

Copy and paste the below code into the Arduino IDE, including your specific device and variable parameters.

Once the code is uploaded, you’ll see the below message in the Arduino IDE:

Your ESP8266 module is now ready to establish a connection with any available network by just pressing the button!

17. To verify the connection status, open the Serial monitor, press the button connected to your ESP module and hold it for 5 seconds until you see the message “Starting Access Point” in your serial monitor:

18. Now that the Access Point is created, you can establish connection from your phone. Under Wi-Fi networks, select Ubidots Access Point:

When the connection is established, it will redirect you to the page below. Input your Wi-Fi parameters and click save.

19. To verify the connection is established, go to the Serial Monitor:

Now, return to your Ubidots accounts to visualize the data received from your new device:

Results

By following this guide, you’ll set up an Access Point that connects your device to any available network without setting the credentials into the firmware – thus creating a universal firmware that can be used anywhere!