Introduction: Connect Your ESP8266 to Any Available Wi-Fi Network

Picture of 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 has the ability to perform WiFi related activities like Internet of things applications and home automation. Ranging in price and features, there are many types of ESP8266 modules available, but all of them are incredibly useful for IoT world.

Regardless of the IoT application you've developed, when using the ESP8266, you must set the WiFi credentials into the ESP8266's firmware to establish the required connections and be able to send data to the cloud. This is one way to connect, but you can also build your own access point into the board making an universal firmware which will establish a connection in any network available just by pressing a button.

Step 1: Requirements

Step 2: Hardware Setup

Picture of Hardware Setup

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

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

Step 3: Setup the Arduino IDE With Your Device

Picture of Setup the Arduino IDE With Your Device

To start with any ESP8266 device you have to install the boards into the Arduino IDE, please follow the steps below to be able to compile the board.

Please download the Arduino IDE if you do not already have it.

1.- Open the Arduino IDE, select Files -> Preferences and enter http://arduino.esp8266.com/stable/package_esp8266... into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas

NOTE: If you're a Mac user, please note that Arduino and File contain different drop down functions compared to Windows users. Also, you will need to install the following driver to be able to upload your NodeMCU.

2.- Open Boards Manager from Tools -> Board -> Boards Manager and install esp8266 platform. To simply find the correct device, search ESP8266 within the search bar.

3.- Select the ESP8266 module that you are using. In this case, we decided to use the NodeMCU 1.0 (ESP-12 Module). To select the board go to: Tools > Board > Select the board.

Additionally, we need to be able to communicate with the NodeMCU, we also need to select the port com. Go to Tools > Port > Select the appropriate PORT for your device.

Also, to keep everything running fast and smooth - let's make sure the upload speed is optimized to 115200. Go to Tools > Upload Speed > 115200.

4.- Go to the following repository to download the ConfigManager library. To download the library clicking the green button called "Clone or download" and select "Download ZIP".

5.- Now back in the Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library

6.- Select the .ZIP file of ConfigManager and then “Accept” or “Choose” If successful you will receive a message in the Arduino IDE.

7.- Next, go to Sketch/Program -> Include Library -> Library Manager and install the PubSubClient library. To simply find the correct library, search PubSubClient within the search bar.

8.- Now, reboot the Arduino IDE prior to upload.

9.- Once you have the ESP8266 platform and the libraries required installed, you have to install the Arduino ESP8266 filesystem uploader. Please follow all the installation steps of the repository and return back to this guide.

10.- Once your uploader is installed, create a new sketch to work in and save it. Ours is called AP_ESP8266.

11. Next, go to the sketch directory and create new directory named data.

12.- Once the directory is created, download this HTML file and attached it to the directory. This file will be used in the file system.

13. Next, we need to upload the file into the ESP8266 flash file system. To begin, make sure you have selected a board port, and closed Serial Monitor.

14.- Select Tools > ESP8266 Sketch Data Upload menu item to start uploading the files into the ESP8266 flash file system.

When done, the IDE status bar will display SPIFFS Image Uploaded message.

15.- Now in the Arduino IDE, paste the code below. Once pasted, please assign the device and variable label desired by you, plus your individual, unique Ubidots TOKEN.

If you do not have your Ubidots TOKEN, reference the following article.

  • How to get your Ubidots TOKEN.

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

16.- After the code contains your parameters, Verify the code within the Arduino IDE. To do this, in the top left corner of our Arduino IDE. Click "check mark" icon to verify any code.

Next, upload your code into your NodeMCU. Choose the "right-arrow" icon beside the check mark icon to upload code

Now your ESP8266 module is ready to establish the connection with any available network just pressing the button!

17.- Confirm: Open the Serial monitor to verify the connection status; press the button connected to your ESP module and hold for 5 seconds until you see the message "Starting Access Point" display in your serial monitor

18.- Now that the Access Point is created, you can establish the connection from your phone. Open the Wi-Fi access and select the network available called "Ubidots Access Point"

Once the connection is established, it will redirect you to the side below. Set the your Wi-Fi parameters into the fields and press "save"

19.- To verify if the connection is established properly go to the Serial Monitor.

Now, return to your Ubidots accounts to visualize the device created and the data received

Step 4: ​Result

An Access Point that connects your device to any network available without setting the credentials into the firmware; thus making a universal firmware that can be used anywhere

Comments

wtito (author)2017-09-22

I follow all instructions to set up my ESP12E, but when I try to verify it, I got the following message:

Board nodemcuv2 (platform esp8266, package esp8266) is unknown

Error compiling for board NodeMCU 1.0 (ESP-12E Module).

Could you please help me to fix it? Thank you.

MalachiB3 (author)2017-07-05

Though widely accepted, sending plaintext credentials over unsecured WiFi is a terrible security idea.

Absolutelyautomation (author)2017-07-04

Nice, good info, and even easier way to connect to networks!

About This Instructable

2,827views

80favorites

License:

Bio: Community manager @Ubidots, a startup empowering makers and hardware engineers to create applications for the Internet of Things #IoT
More by UbiMaker:DIY Raspberry Pi Temperature System With UbidotsTest You Internet Speed Using a Raspberry Pi + UbidotsConnect Your Thinxtra Xkit Using Sigfox
Add instructable to: