Introduction library WifiManager
The main disadvantage is to configure the network credentials in a esp8266 without requiring to modify and download the firmware again, I have tested with several methods to dynamically store the SSID and PASSWORD of a network.
In the case of the esp8266 programmed in Arduino IDE for some time I have seen a proposal called WIfiManager presented by Tzapu, which allows an agile and fast connection, the first tests are registered since 2015.
This time we will make a brief introduction to the WifiManager library, I have tested 2 similar versions.
Note: they work perfectly, obviously between the 2 libraries there are variations in code implementations and that generates incompatibilities or errors in some functions between version 1 and 2.
I will mention some of the functionalities of the WifiManager libraries, in case of using them the complete and detailed information of each library is available in github, in this case I have used the Version 2: WifiManager library by Ken Taylor.
-Main Functionality Configuration of NETWORK credentials.
-Timeout of AP mode “180 s”, if it is not configured wifi the module restarts automatically after the defined time in seconds example: 180 .
– Custom html text function, allows you to add titles in HTML form.
-Form form to enter string “parameters”, create input fields of parameters, to capture parameters and store data requires handling functions SPIFFS and Json.
– Boolean checkbox function to select, enable or disable parameters, to capture parameters and store data requires handling SPIFFS and Json functions.
-Function add css styles in html, modify HTML form styles via ccs, in this case invert colors.
1 Pushbutton”normally open” NO
2 Resistors 220 Ohm
1 Resistors 10K
2 Diode led, “red y green.”
An example has been downloaded from Github and has been cut to make a light and simple version, without the slightly complex functionalities that we will see later, this version will realize the basic configuration of NETWORK credentials.
We have used an ESP8266 12E, we have added a button to configure the Wifi and 2 led diodes as indicators.
- GPIO 5 (Pin D1) – Wifi Config button + 10K resistor
- GPIO 14 (Pin D5) – led red + Resistance 220 Ohm
- GPIO 4 (Pin D2) – led green + Resistance 220 Ohm
- The technically pressed stops the void loop execution, resets network parameters and enables AP mode, this functionality depends on the code or loop executed.
- RED LED: indicates wifi configuration status,
-led = “On” wifi configuration mode, in process.
-led = “Off” network configuration Successful.
- LED GREEN: in this test we will not use it, but its function is to indicate the connection status in client mode, eg: esp8266 sending data to a platform, emoncms, blink, thinger.io, thinkspeak, Node-RED etc.
-led = “On” sending and receiving data Ok.
-led = “Off” sending and / or connection with failed server.
Note: if the button is removed, the esp8266 will always be in AP mode “Wifi configuration”
Description of Sequence
- Press “config wifi” button.
- esp8266 resets Network parameters and initiates AP mode “Access Point”.
- Create a new Wifi network from the esp8266.
- Connect to the ESPXXXX network.
- From the browser, enter 192.168.4.1.
- From form make SSID and PASS configuration.
- Reset esp8266, disappears red ESPXXXX.
- esp8266 STA mode will connect and execute void loop code normally.
Introduction library WifiManager explained – explicado
This video has been made to test some of the features mentioned above.
ESP8266 in Access Point mode “ESPTest” for configuration of Network parameters.
ESP8266 in station mode connected to RED “1503523” executing “void loop”.
Arduino IDE Code
Note: In this case the code is a trimmed version, allowing the basic configuration and connection, download link at the end of the post and require the following libraries:
Fixed Network Parameters – Version 1 libraries
In the case of the previous tests we made a configuration and Wifi connection via DCHP assigned by our router, but there is a method of assigning complete parameters from form:
- Fixed IP address
- Subnet Mask
Storage of HTML parameters and functionalities – Wifimanager Version 2 libraries
- Entering additional parameters
- Enable checkbox
Parameter reading via JSON from browser in configuration mode – Version 2.
- scan reading /scan
Recommended Tutorial : WifiManager + Emoncms (OEM) with ESP8266 (Temperature) #1
Although we have only done some testing, WifiManager is a good solution fast and easy it works correctly.
We are analyzing the methods used to add and store more parameters, according to the examples a Json file is created in which the parameters are written, this file “config.json” is saved in SPIFFS internal file system the ESP8266, and is written only when configuring parameters and is read every time the module is restarted.
We will try later on configuration functionalities we intend to integrate and both libraries in an application, we will test each one of the 2 versions, each version has its own characteristics.
In future applications we will begin to implement this library our tests.
Thanks to all the developers and collaborators of these libraries.
- If they have any input, suggestion, or have made commentary …
In next tutorials
we will integrate:
- esp8266 + WifiManager + Modbus TCP / IP
- esp8266 + WifiManager + Modbus RTU
- esp8266 + WifiManager + MQTT
- esp8266 + WifiManager + CoAP