0

members

Easy Basics: Project 066m ESP8266 ESP-12E module - WiFiManager

of Acoptex.com in ESP8266 ESP-12

Basics: Project 066m

Project name: ESP8266 ESP-12E module - WiFiManager

Tags: ESP, ESP8266, WI FI module, ESP-12E, Ai Thinker, AI-Cloud, SOC, GPIO, General Purpose Input Output, System On a Chip, IOT, internet of things, FTDI232, FTDI 232, how to upload sketch, LoLin NODEMCU V3, NODEMCU, V3, Development Board with USB-to-Serial Onboard, NodeMCU DevKit, WiFiManager

Attachments: sketch1, sketch2 and library1, library2

In this project, you need these parts :

1. ESP8266 ESP-12E module with micro USB cable 1pc

2.Arduino IDE ( you can download it from here  )

3.Jumper cables F-M, M-M

4. LED 2 pcs (different colors)

5. Resistor 2 pcs (220 Ohm)

6. Breadboard 1 pc

General

We will learn about WiFi manager and how to use it (autoconnect, custom parameters and manage your SSID and password) with ESP8266 ESP-12E module (LoLin NODEMCU V3). 

Understanding the WiFi manager

WiFiManager allows you to connect your ESP8266 to different Access Points (AP) without having to hard-code and upload new code to your board. Additionally, you can also add custom parameters (variables) and manage multiple SSID connections with the WiFiManager library.

The WiFiManager is a great library do add to your ESP8266 projects, because using this library you no longer have to hard-code your network credentials (SSID and password). Your ESP will automatically join a known network or set up an Access Point that you can use to configure the network credentials. Here’s how this process works:

  • When your ESP8266 boots, it is set up in Station mode, and tries to connect to a previously saved Access Point (a known SSID and password combination);
  • If this process fails, it sets the ESP into Access Point mode;
  • Using any Wi-Fi enabled device with a browser, connect to the newly created Access Point (default name AutoConnectAP);
  • After establishing a connection with the AutoConnectAP, you can go to the default IP address to open a web page that allows you to configure your SSID and password;
  • Once a new SSID and password is set, the ESP reboots and tries to connect;
  • If it establishes a connection, the process is completed successfully. Otherwise, it will be set up as an Access Point.

Understanding the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)

You can read more about it here.

Signals and connections of LED

The operating voltage of the LED is 1.8V and the operating current is 10mA-20mA. The Arduino Uno board can supply 5V or 3.3V power. We will use 5V for this project, so the minimum resistance of the current limiting resistor should be (5 V to 1.8 V)/20 = 160 Om. The 220 Om offered in the kit is suitable and you can also choose other resistors that meet the condition. The larger the resistance is, the dimmer the LED will get.

Signals and connections of the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)

TX - transmit pin. GPIO pin

RX  - receive pin.  GPIO pin

3V3 (or 3V or 3.3V) - power supply pin (3-3.6V). 

GND ( or G) - ground pin.

RST - reset pin. Keep it on high (3.3V) for normal operation. Put it on 0V to reset the chip.

EN - Chip enable. Keep it on high (3.3V) for normal operation.

Vin - External power supply 5VDC.

D0-D8 - GPIO (General Purpose Input Output) pins 

D5-D8 - SPI interface

D1-D2– I²C/TWI Interface

SC (or CMD) - (Chip Select) - the pin that the master can use to enable and disable specific devices. GPIO pin

SO (or SDO) - Master In Slave Out (MISO) - SPI communication. The Slave line for sending data to the master. GPIO pin

SK (or CLK) - SCK (Serial Clock) - SPI communication.The clock pulses which synchronize data transmission generated by the master. GPIO pin

S1 (or SD1) - Master Out/Slave In (MOSI). SPI communication. The Master line for sending data to the peripherals. GPIO pin

S2 (or SD2) - GPIO pin

S3 (or SD3) - GPIO pin

VU (or VUSB) - external power 5VDC.

A0 - ADC output.

RSV - reserved

Wiring

Step by Step instruction

1. Adding ESP8266 platform to Arduino IDE

the Arduino environment has to be set up to make it compatible with the 
ESP-01 module. It is required to have Arduino version 1.6.4 or higher in order to install the ESP8266’s platform packages.

The Arduino environment has to be set up to make it compatible with the ESP8266 ESP-01 module. It is required to have Arduino IDE version 1.6.4 or higher in order to install the ESP8266’s platform packages.

  1. Open Arduino IDE. 
  2. Open the Preferences window from the Arduino IDE. Go to File -> Preferences.
  3. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field and click the “OK” button. If you already have a URL in there, and want to keep it, you can separate multiple URLs by placing a comma between them. (Arduino 1.6.5 added an expanded text box, separate links in here by line.)

  4. Open Boards manager. Go to Tools -> Board -> Boards Manager…

  5. There should be a couple new entries in addition to the standard Arduino boards. Look for esp8266. or scroll down to the ESP8266 entry (usually at the bottom). Select the ESP8266 entry. When you click it an install option will appear. Select the latest version and click install
  6. The board definitions and tools for the ESP8266 include a whole new set of gcc, g++, and other reasonably large, compiled binaries, so it may take a few minutes to download and install (the archived file is ~110MB). Once the installation has completed, an Arduino-blue “INSTALLED” will appear next to the entry.

2. Uploading sketch to ESP8266 ESP-12E module 

 If you’re using an ESP-12E NodeMCU Kit, uploading the sketch is very simple, since it has built-in programmer. 

Before use ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3), you need to download the manufacture's driver (CH340)  for this chip and install it in your PC. Here is the link. See the description of driver installation package below: CH340 / CH341 USB to serial WINDOWS driver installation package that supports 32/64 bit Windows 10 / 8.1 / 8/7 / VISTA / XP, SERVER 2016/2012/2008/2003, 2000 / ME / 98, through Microsoft digital signature authentication, support USB to 3-wire and 9-wire serial port, with the product release To the end user. Applicable scope: CH340G, CH340C, CH340B, CH340E, CH340T, CH340R, CH341A, CH341T, CH341H chips.

If you have CP2102 chip then  you need to download the manufacture's driver for this chip and install it in your PC. Driver for Mac, Windows, Linux or more.. 

  1. Do wiring.
  2. Open Arduino IDE.
  3. Plug your ESP8266 ESP-12E module into your PC USB port.
  4. Choose your NodeMCU board. Go to Tools -> Board -> NodeMCU 1.0 (ESP-12E Module)
  5. Select the correct com port.
  6. Verify and upload the sketch1 to your ESP8266 ESP-12E module. AT commands will not work after that. You need to Flash the firmware to enable them again.
  7. Open Serial monitor at baud rate of 115200 bps.
  8. You can use your PC/laptop/smartphone to connect to the AutoConnectAP Access point. You need to connect to AutoConnectAP local network - just select it and click on Connect button.
  9. Open your browser and you will be automatically redirected to the following IP address: 192.168.4.1. This loads the web page, where you can set your network parameters.
  10. Click on Configure WiFi button.
  11. Choose your desired network by tapping its name and the SSID should be filled instantly (in our case TR-2), type your password and click on Save button. You will see a message Credentials Saved.
  12. Press RST button on your ESP8266 ESP-12E module to reset it. You will see IP address in the Serial Monitor (in our case it’s 192.168.0.117):
  13. Open your browser and type the IP address. You should see the web server shown below, that allows you to control two GPIOs, switch them on/off.
  14. The WiFiManager has a useful feature that allows you to add custom parameters to the Configure WiFi web page. This is extremely useful, because in some applications you might want to add a different API Key, an MQTT broker IP Address, assign a different GPIO, activate a sensor, etc. Let's make a web server to control an ESP8266 ESP-12E GPIO pin that is defined with a custom parameter set through the WiFiManager. You need to add a bunch of code  that allows you to manipulate the /config.json file stored in the ESP in order to add a custom parameter. 
  15. Open Arduino IDE.
  16. Plug your ESP8266 ESP-12E module into your PC USB port.
  17. Choose your NodeMCU board. Go to Tools -> Board -> NodeMCU 1.0 (ESP-12E Module)
  18. Select the correct com port.
  19. Verify and upload the sketch2 to your ESP8266 ESP-12E module. AT commands will not work after that. You need to Flash the firmware to enable them again.
  20. Open Serial monitor at baud rate of 115200 bps.
  21. You can use your PC/laptop/smartphone to connect to the AutoConnectAP Access point. You need to connect to AutoConnectAP local network - just select it and click on Connect button.
  22. Open your browser and you will be automatically redirected to the following IP address: 192.168.4.1. This loads the web page, where you can set your network parameters.
  23. Click on Configure WiFi button.
  24. Choose your desired network by tapping its name and the SSID should be filled instantly (in our case TR-2), type your password, type output (number of GPIO port) and click on Save button. You will see a message Credentials Saved.
  25. Press RST button on your ESP8266 ESP-12E module to reset it. You will see IP address in the Serial Monitor (in our case it’s 192.168.0.117):
  26. Open your browser and type the IP address. You should see the web server shown below, that allows you to control output GPIO (in our case it's GPIO 4), switch them on/off.

Code

Uncomment and run it once, if you want to erase all the stored information: //wifiManager.resetSettings();

In order to add custom parameter we will create a variable to store an MQTT broker server IP address. Create a char variable: char mqtt_server[40]; 

If it is already saved in the /config.json, you can copy it:

strcpy(mqtt_server, json["mqtt_server"]);

Create a WiFiManagerParameter - the parameter to be displayed in the Configure WiFi web page:

WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);

Add the variable as a parameter:

wifiManager.addParameter(&custom_mqtt_server);

Check and update the char variables with the latest value:

strcpy(mqtt_server, custom_mqtt_server.getValue());

If the user submits a new value to one of the parameters, this line updates the /config.json file:

json["mqtt_server"] = mqtt_server;

You could repeat this process to add more custom parameters.

Summary

We have learnt about WiFi manager and how to use it (autoconnect, custom parameters and manage your SSID and password) with ESP8266 ESP-12E module (LoLin NODEMCU V3). 

Library

  • WiFiManager library. Download, unzip  and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here
  • ArduinoJSON library. Download, unzip  and add to libraries in our PC, for example C:\Users\toshiba\Documents\Arduino\libraries. This link you can find in Preferences of Adruino IDE program which installed in your PC. You can read more about it here
  • ESP8266WebServer library included in Arduino IDE.
  • DNSServer library included in Arduino IDE.
  • ESP8266WiFi library included in Arduino IDE.

Sketch

  • You can find it on the begining of this project


Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019
Medium Basics: Project 083e Sipeed Maixduino board - Uploading MaixPy of Acoptex.com in Sipeed Maixduino 04-08-2019
Medium Basics: Project 083f Sipeed Maixduino board - Using MycroPython of Acoptex.com in Sipeed Maixduino 04-08-2019

Published at 13-07-2018
Viewed: 3136 times