- Notifications
You must be signed in to change notification settings - Fork0
(ESP8266 + LwIP W5100 / W5100S) Connection and Credentials Manager, with enhanced GUI and fallback Web ConfigPortal. This Library is used for configuring (ESP8266 + LwIP W5100 / W5100S) Credentials Manager at runtime. You can also specify static DNS servers, personalized HostName, static or DHCP IP
License
khoih-prog/ESP8266_W5100_Manager
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Why do we need this ESP8266_W5100_Manager library
- Changelog
- Prerequisites
- Installation
- HOWTO Fix
Multiple Definitions
Linker Error - How It Works
- HOWTO Basic configurations
- 1. Using default for every configurable parameter
- 2. Using many configurable parameters
- 3. Using STA-mode DHCP, but don't like to change to static IP or display in Config Portal
- 4. Using STA-mode DHCP, but permit to change to static IP and display in Config Portal
- 5. Using STA-mode StaticIP, and be able to change to DHCP IP and display in Config Portal
- 6. Using STA-mode StaticIP and configurable DNS, and be able to change to DHCP IP and display in Config Portal
- 7. Using STA-mode StaticIP and auto DNS, and be able to change to DHCP IP and display in Config Portal
- 8. Not using NTP to avoid issue with some WebBrowsers, especially in CellPhone or Tablets.
- 9. Using NTP feature with CloudFlare. System can hang until you have Internet access for CloudFlare.
- 10. Using NTP feature without CloudFlare to avoid system hang if no Internet access for CloudFlare.
- 11. Setting STA-mode static IP
- 12. Using CORS (Cross-Origin Resource Sharing) feature
- 13. How to auto getting _timezoneName
- 14. How to get TZ variable to configure Timezone
- 15. How to use the TZ variable to configure Timezone
- HOWTO Open Config Portal
- HOWTO Add Dynamic Parameters
- 1. Determine the variables to be configured via Config Portal (CP)
- 2. Initialize the variables to prepare for Config Portal (CP)
- 2.1 Use the following simple constructor for simple variables such as
thingspeakApiKey
,pinSda
andpinScl
- 2.2 For example, to create a new
ESP8266_EMParameter
objectp_thingspeakApiKey
forthingspeakApiKey
- 2.3 Use the more complex following constructor for variables such as
sensorDht22
- 2.4 For example, to create a new
ESP8266_EMParameter
objectp_sensorDht22
forsensorDht22
- 2.1 Use the following simple constructor for simple variables such as
- 3. Add the variables to Config Portal (CP)
- 4. Save the variables configured in Config Portal (CP)
- 5. Write to FS (SPIFFS, LittleFS, etc.) using JSON format
- 6. Read from FS using JSON format
- So, how it works?
- Documentation
- How to connect W5100 to ESP8266
- Examples
- ConfigOnSwitch
- ConfigOnSwitchFS
- ConfigOnDoubleReset_TZ (now support ArduinoJson 6.0.0+ as well as 5.13.5-)
- ConfigOnDoubleReset (now support ArduinoJson 6.0.0+ as well as 5.13.5-)
- ConfigPortalParamsOnSwitch (now support ArduinoJson 6.0.0+ as well as 5.13.5-)
- ESP8266_FSWebServer
- ESP8266_FSWebServer_DRD
- Example ConfigOnSwitch
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- Contributions and Thanks
- Contributing
- License and credits
- Copyright
Why do we need thisESP8266_W5100_Manager library
This is anESP8266 + LwIP W5100 / W5100S
Credentials and Connection Manager with fallback Web ConfigPortal. This Library is used for configuring ESP8266 Ethernet Static / DHCP and Credentials at runtime. You can specify static DNS servers, personalized HostName and CORS feature.
This library is based on, modified and improved from:
ThisESP8266_W5100_Manager library currently supports these following boards:
- ESP8266 boards using
LwIP W5100 / W5100S Ethernet
Tested OK withWiznet-Ethernet-Hat_RP2040
W5100S
Arduino IDE 1.8.19+
for Arduino.ESP8266 Core 3.0.2+
for ESP8266-based boards.ESP_DoubleResetDetector v1.3.2+
if using DRD feature. To install, check.
The best and easiest way is to useArduino Library Manager
. Search forESP8266_W5100_Manager
, then select / install the latest version. You can also use this link for more detailed instructions.
- Navigate toESP8266_W5100_Manager page.
- Download the latest release
ESP8266_W5100_Manager-main.zip
. - Extract the zip file to
ESP8266_W5100_Manager-main
directory - Copy the whole
ESP8266_W5100_Manager-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- InstallVS Code
- InstallPlatformIO
- InstallESP8266_W5100_Manager library by usingLibrary Manager. Search forESP8266_W5100_Manager inPlatform.io Author's Libraries
- Use includedplatformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples atProject Configuration File
The current library implementation, usingxyz-Impl.h
instead of standardxyz.cpp
, possibly creates certainMultiple Definitions
Linker error in certain use cases.
You can use
#include<ESP8266_W5100_Manager.hpp>//https://github.com/khoih-prog/ESP8266_W5100_Manager
in many files. But be sure to use the following#include <ESP8266_W5100_Manager.h>
in just 1.h
,.cpp
or.ino
file, which mustnot be included in any other file, to avoidMultiple Definitions
Linker Error
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error#include<ESP8266_W5100_Manager.h>//https://github.com/khoih-prog/ESP8266_W5100_Manager
Have a look at the discussion inDifferent behaviour using the src_cpp or src_h lib #80
- TheConfigOnSwitch example shows how it works and should be used as the basis for a sketch that uses this library.
- The concept ofConfigOnSwitch is that a new
ESP8266
will start a ConfigPortal when powered up and save the configuration data in non volatile memory. Thereafter, the ConfigPortal will only be started again if a button is pushed on theESP8266
module. - Using any network-enabled device with a browser (computer, phone, tablet) connect to the newly created Access Point (AP) (Dynamic or Static IP specified in sketch)
then connectWebBrowser
to configurable ConfigPortal IP address, e.g.192.168.186
- Include in your sketch
#include<FS.h>#include<ESP8266WiFi.h>//https://github.com/esp8266/Arduino//needed for library#include<DNSServer.h>#defineUSE_LITTLEFStrue#if USE_LITTLEFS #include<LittleFS.h> FS* filesystem = &LittleFS; #defineFileFS LittleFS #defineFS_Name"LittleFS"#else FS* filesystem = &SPIFFS; #defineFileFS SPIFFS #defineFS_Name"SPIFFS"#endif//////////////////////////////////////////////////////////#defineESP_getChipId() (ESP.getChipId())#defineLED_ON LOW#defineLED_OFF HIGH//////////////////////////////////////////////////////////// You only need to format the filesystem once//#define FORMAT_FILESYSTEM true#defineFORMAT_FILESYSTEMfalse////////////////////////////////////////////////////#include<ESP8266_W5100_Manager.h>//https://github.com/khoih-prog/ESP8266_W5100_Manager#defineHTTP_PORT80
- Include in your sketch
#include<FS.h>#include<ESP8266WiFi.h>//https://github.com/esp8266/Arduino//needed for library#include<DNSServer.h>#defineUSE_LITTLEFStrue#if USE_LITTLEFS #include<LittleFS.h> FS* filesystem = &LittleFS; #defineFileFS LittleFS #defineFS_Name"LittleFS"#else FS* filesystem = &SPIFFS; #defineFileFS SPIFFS #defineFS_Name"SPIFFS"#endif//////////////////////////////////////////////////////////#defineESP_getChipId() (ESP.getChipId())#defineLED_ON LOW#defineLED_OFF HIGH//////////////////////////////////////////////////////////////// You only need to format the filesystem once//#define FORMAT_FILESYSTEM true#defineFORMAT_FILESYSTEMfalse//////////////////////////////////////////////////////////////// Assuming max 49 chars#defineTZNAME_MAX_LEN50#defineTIMEZONE_MAX_LEN50typedefstruct{char TZ_Name[TZNAME_MAX_LEN];// "America/Toronto"char TZ[TIMEZONE_MAX_LEN];// "EST5EDT,M3.2.0,M11.1.0"uint16_t checksum;} EthConfig;EthConfig Ethconfig;//////////////////////////////////////////////////////////////#defineCONFIG_FILENAMEF("/eth_cred.dat")//////////////////////////////////////////////////////////////// Indicates whether ESP has credentials saved from previous session, or double reset detectedbool initialConfig = false;// Use false if you don't like to display Available Pages in Information Page of Config Portal// Comment out or use true to display Available Pages in Information Page of Config Portal// Must be placed before #include <ESP8266_W5100_Manager.h>#defineUSE_AVAILABLE_PAGEStrue// From v1.0.10 to permit disable/enable StaticIP configuration in Config Portal from sketch. Valid only if DHCP is used.// You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa// You have to explicitly specify false to disable the feature.//#define USE_STATIC_IP_CONFIG_IN_CP false// Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal.// See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23)#defineUSE_ESP_ETH_MANAGER_NTPtrue// Just use enough to save memory. On ESP8266, can cause blank ConfigPortal screen// if using too much memory#defineUSING_AFRICAfalse#defineUSING_AMERICAtrue#defineUSING_ANTARCTICAfalse#defineUSING_ASIAfalse#defineUSING_ATLANTICfalse#defineUSING_AUSTRALIAfalse#defineUSING_EUROPEfalse#defineUSING_INDIANfalse#defineUSING_PACIFICfalse#defineUSING_ETC_GMTfalse// Use true to enable CloudFlare NTP service. System can hang if you don't have Internet access while accessing CloudFlare// See Issue #21: CloudFlare link in the default portal (https://github.com/khoih-prog/ESP_WiFiManager/issues/21)#defineUSE_CLOUDFLARE_NTPfalse// New in v1.0.11#defineUSING_CORS_FEATUREtrue//////////////////////////////////////////////////////////////// Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network#if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP)// Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #defineUSE_DHCP_IPtrue#else// You can select DHCP or Static IP here//#define USE_DHCP_IP true #defineUSE_DHCP_IPfalse#endif#if ( USE_DHCP_IP )// Use DHCP #if (_ESP8266_ETH_MGR_LOGLEVEL_ > 3) #warning Using DHCP IP #endif IPAddress stationIP = IPAddress(0,0,0,0); IPAddress gatewayIP = IPAddress(192,168,2,1); IPAddress netMask = IPAddress(255,255,255,0);#else// Use static IP #if (_ESP8266_ETH_MGR_LOGLEVEL_ > 3) #warning Using static IP #endif IPAddress stationIP = IPAddress(192,168,2,186); IPAddress gatewayIP = IPAddress(192,168,2,1); IPAddress netMask = IPAddress(255,255,255,0);#endif//////////////////////////////////////////////////////////////#defineUSE_CONFIGURABLE_DNStrueIPAddress dns1IP = gatewayIP;IPAddress dns2IP = IPAddress(8,8,8,8);#include<ESP8266_W5100_Manager.h>//https://github.com/khoih-prog/ESP8266_W5100_Manager#defineHTTP_PORT80///////////////////////////////////////////////////////////////****************************************** // Defined in ESP8266_W5100_Manager.hpp typedef struct { IPAddress _sta_static_ip; IPAddress _sta_static_gw; IPAddress _sta_static_sn; #if USE_CONFIGURABLE_DNS IPAddress _sta_static_dns1; IPAddress _sta_static_dns2; #endif } ETH_STA_IPConfig;******************************************/ETH_STA_IPConfig EthSTA_IPconfig;
// You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa// You have to explicitly specify false to disable the feature.#defineUSE_STATIC_IP_CONFIG_IN_CPfalse
// You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa// You have to explicitly specify false to disable the feature.//#define USE_STATIC_IP_CONFIG_IN_CP false// Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network#if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP)// Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #defineUSE_DHCP_IPtrue#else// You can select DHCP or Static IP here #defineUSE_DHCP_IPtrue#endif
// You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa// You have to explicitly specify false to disable the feature.//#define USE_STATIC_IP_CONFIG_IN_CP false// Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network#if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP)// Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #defineUSE_DHCP_IPtrue#else// You can select DHCP or Static IP here #defineUSE_DHCP_IPfalse#endif
6. Using STA-mode StaticIP and configurable DNS, and be able to change to DHCP IP and display in Config Portal
// You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa// You have to explicitly specify false to disable the feature.//#define USE_STATIC_IP_CONFIG_IN_CP false// Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network#if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP)// Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #defineUSE_DHCP_IPtrue#else// You can select DHCP or Static IP here #defineUSE_DHCP_IPfalse#endif#defineUSE_CONFIGURABLE_DNStrueIPAddress dns1IP = gatewayIP;IPAddress dns2IP = IPAddress(8,8,8,8);
7. Using STA-mode StaticIP and auto DNS, and be able to change to DHCP IP and display in Config Portal
// You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa// You have to explicitly specify false to disable the feature.//#define USE_STATIC_IP_CONFIG_IN_CP false// Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network#if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP)// Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #defineUSE_DHCP_IPtrue#else// You can select DHCP or Static IP here #defineUSE_DHCP_IPfalse#endif#defineUSE_CONFIGURABLE_DNSfalse
// Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal.// See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23)#defineUSE_ESP_ETH_MANAGER_NTPfalse
9. Using NTP feature with CloudFlare. System can hang until you have Internet access for CloudFlare.
// Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal.// See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23)#defineUSE_ESP_ETH_MANAGER_NTPtrue// Use true to enable CloudFlare NTP service. System can hang if you don't have Internet access while accessing CloudFlare// See Issue #21: CloudFlare link in the default portal (https://github.com/khoih-prog/ESP_WiFiManager/issues/21)#defineUSE_CLOUDFLARE_NTPtrue
// Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal.// See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23)#defineUSE_ESP_ETH_MANAGER_NTPtrue// Use true to enable CloudFlare NTP service. System can hang if you don't have Internet access while accessing CloudFlare// See Issue #21: CloudFlare link in the default portal (https://github.com/khoih-prog/ESP_WiFiManager/issues/21)#defineUSE_CLOUDFLARE_NTPfalse
//ESP8266_W5100_manager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask, dns1IP, dns2IP);ESP8266_W5100_manager.setSTAStaticIPConfig(WM_STA_IPconfig);
- To use CORS feature withdefault CORS Header "". Some WebBrowsers won't accept this allowing-all "" CORS Header.
// Default false for using only whenever necessary to avoid security issue#defineUSING_CORS_FEATUREtrue
- To use CORS feature with specific CORS Header "Your Access-Control-Allow-Origin".To be modified according to your specific Allowed-Origin.
// Default false for using only whenever necessary to avoid security issue#defineUSING_CORS_FEATUREtrue...#if USING_CORS_FEATURE ESP_wifiManager.setCORSHeader("Your Access-Control-Allow-Origin");#endif
- Not use CORS feature (default)
// Default false for using only whenever necessary to avoid security issue#defineUSING_CORS_FEATUREfalse
- Turn on auto
NTP
configuration by
// Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal.// See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23)#defineUSE_ESP_ETH_MANAGER_NTPtrue
- The
_timezoneName
, in the format similar toAmerica/New_York, America/Toronto, Europe/London, etc., can be retrieved by using
String tempTZ = ESP8266_W5100_manager.getTimezoneName();
- ESP8266
TZ
can be configured, using the similar toEST5EDT,M3.2.0,M11.1.0
(for America/New_York) , as follows:
// EST5EDT,M3.2.0,M11.1.0 (for America/New_York)// EST5EDT is the name of the time zone// EST is the abbreviation used when DST is off// 6 hours is the time difference from GMT// EDT is the abbreviation used when DST is on// ,M3 is the third month// .2 is the second occurrence of the day in the month// .0 is Sunday// ,M11 is the eleventh month// .1 is the first occurrence of the day in the month// .0 is SundayconfigTime(Ethconfig.TZ,"pool.ntp.org");
- To convert from
_timezoneName
toTZ
, use the functiongetTZ()
as follows:
constchar * TZ_Result = ESP8266_W5100_manager.getTZ(_timezoneName);
The conversion depends on the stored TZs, which is using some memory, and can cause issue for ESP8266 in certain cases. Therefore, enable just the region you're interested.
For example, your application is used in America continent, you need just
#defineUSING_AMERICAtrue
Hereafter is the regions' list
// Just use enough to save memory. On ESP8266, can cause blank ConfigPortal screen// if using too much memory#defineUSING_AFRICAfalse#defineUSING_AMERICAtrue#defineUSING_ANTARCTICAfalse#defineUSING_ASIAfalse#defineUSING_ATLANTICfalse#defineUSING_AUSTRALIAfalse#defineUSING_EUROPEfalse#defineUSING_INDIANfalse#defineUSING_PACIFICfalse#defineUSING_ETC_GMTfalse
configTime(Ethconfig.TZ,"pool.ntp.org");
then to print local time
voidprintLocalTime(){statictime_t now; now =time(nullptr);if ( now >1451602800 ) { Serial.print("Local Date/Time:"); Serial.print(ctime(&now)); }}
- When you want to open a config portal, with default
DHCP
hostnameESP8266-XXXXXX
, just add
#include<ESP8266_W5100_Manager.h>//https://github.com/khoih-prog/ESP8266_W5100_Manager#defineHTTP_PORT80WebServerwebServer(HTTP_PORT);ESP8266_W5100_ManagerESP8266_W5100_manager();
If you'd like to have a personalized hostname(RFC952-conformed,- 24 chars max,- only a..z A..Z 0..9 '-' and no '-' as last char)
add
ESP8266_W5100_ManagerESP8266_W5100_manager("Personalized-HostName");
then later call
ESP8266_W5100_manager.startConfigPortal()
While in Config Portal, connect to it using its AP IP, e.g.192.168.2.186
, configure Credentials, then save. The settings will be saved in non volatile memory. It will then reboot and autoconnect.
These illustrating steps is based on the exampleConfigOnSwitchFS
The application will:
- use DHT sensor (either DHT11 or DHT22) and
- need to connect to ThingSpeak with unique user's API Key.
The DHT sensor is connected to the ESP boards using SDA/SCL pins which also need to be configurable.
So this is the list of variables to be dynamically configured using CP
1. `thingspeakApiKey`, type `char array`, max length 17 chars, and just arbitrarily selected default value to be "" or "ThingSpeak-APIKey"2. `sensorDht22`, type `bool`, default to be `true` (DHT22)3. `pinSda`, type `int`, default to be `PIN_D2`4. `pinScl`, type `int`, default to be `PIN_D1`
The Label can be any arbitrary string that help you identify the variable, but must be unique in your application
The initial code will be
#defineAPI_KEY_LEN17// Default configuration valueschar thingspeakApiKey[API_KEY_LEN] ="";bool sensorDht22 =true;int pinSda = PIN_D2;// Pin D2 mapped to pin GPIO4 of ESP8266int pinScl = PIN_D1;// Pin D1 mapped to pin GPIO5 of ESP8266// Any unique string helping you identify the vars#defineThingSpeakAPI_Label"thingspeakApiKey"#defineSensorDht22_Label"SensorDHT22"#definePinSDA_Label"PinSda"#definePinSCL_Label"PinScl"
The exampleConfigOnSwitchFS will open the CP whenever a SW press is detected inloop()
. So the code to adddynamic variables
will be there, just after the CPESP8266_W5100_Manager
class initialization to createESP8266_W5100_Manager
object.
voidloop(){// is configuration portal requested?if ((digitalRead(TRIGGER_PIN) == LOW) || (digitalRead(TRIGGER_PIN2) == LOW)) { Serial.println("\nConfiguration portal requested.");digitalWrite(LED_BUILTIN, LED_ON);// turn the LED on by making the voltage LOW to tell us we are in configuration mode.//Local initialization. Once its business is done, there is no need to keep it around ESP8266_W5100_ManagerESP8266_W5100_manager("ConfigOnSwitchFS");//Check if there is stored WiFi router/password credentials.//If not found, device will remain in configuration mode until switched off via webserver. Serial.print("Opening configuration portal."); ...// The addition of dynamic vars will be somewhere here }
TheESP8266_EMParameter
class constructor will be used to initialize each newly-added parameter object.
2.1 Use the following simple constructor for simple variables such asthingspeakApiKey
,pinSda
andpinScl
:
ESP8266_EMParameter(constchar *id,constchar *placeholder,constchar *defaultValue,int length);
The command to use will be
ESP8266_EMParameterp_thingspeakApiKey(ThingSpeakAPI_Label,"Thingspeak API Key", thingspeakApiKey, API_KEY_LEN);
where
- p_thingspeakApiKey : ESP8266_EMParameter class object reference that stores the new Custom Parameter- id => ThingSpeakAPI_Label : var ref to Json associative name and HTML element ID for the new Custom Paramerter you just defined in step 1- placeholder => "Thingspeak API Key" : HTML input placeholder and/or label element text the user sees in the configuration interface for this Custom Parameter- defaultValue => thingspeakApiKey : variable for storing the value of your Custom Parameter in the file system or default value when no data is entered- length => API_KEY_LEN : max allowed length you want for this Custom Parameter to have
ForpinSda
andpinScl
, the command will be similar
// I2C SCL and SDA parameters are integers so we need to convert them to char array but// no other special considerationschar convertedValue[3];sprintf(convertedValue,"%d", pinSda);ESP8266_EMParameterp_pinSda(PinSDA_Label,"I2C SDA pin", convertedValue,3);sprintf(convertedValue,"%d", pinScl);ESP8266_EMParameterp_pinScl(PinSCL_Label,"I2C SCL pin", convertedValue,3);
where
- p_pinSda / p_pinScl : ESP8266_EMParameter class object reference that stores the new Custom Parameter- id => PinSDA_Label/PinSCL_Label : var ref to Json associative name and HTML element ID for the new Custom Paramerter you just defined in step 1- placeholder => "I2C SDA pin"/"I2C SCL pin" : HTML input placeholder and/or label element text the user sees in the configuration interface for this Custom Parameter- defaultValue => convertedValue : variable for storing the value of your Custom Parameter in the file system or default value when no data is entered- length => 3 : max allowed length you want for this Custom Parameter to have
ESP8266_EMParameter(constchar *id,constchar *placeholder,constchar *defaultValue,int length,constchar *custom,int labelPlacement);
The command to use will be
ESP8266_EMParameterp_sensorDht22(SensorDht22_Label,"DHT-22 Sensor","T",2, customhtml, WFM_LABEL_AFTER);
where
- p_sensorDht22 : ESP8266_EMParameter class object reference that stores the new Custom Parameter- id => SensorDht22_Label : var ref to Json associative name and HTML element ID for the new Custom Paramerter you just defined in step 1- placeholder => "DHT-22 Sensor" : HTML input placeholder and/or label element text the user sees in the configuration interface for this Custom Parameter- defaultValue => "T" : variable for storing the value of your Custom Parameter in the file system or default value when no data is entered ("T" means `true`)- length => 2 : max allowed length you want for this Custom Parameter to have- custom => customhtml : custom HTML code to add element type, e.g. `checkbox`, and `checked` when `sensorDht22 == true`- labelPlacement => WFM_LABEL_AFTER : to place label after
and customhtml Code is:
char customhtml[24] ="type=\"checkbox\"";if (sensorDht22){strcat(customhtml," checked");}
Adding thoseESP8266_EMParameter
objects created in Step 2 using the functionaddParameter()
of objectESP8266_W5100_Manager
//adds a custom parameterbooladdParameter(ESP8266_EMParameter *p);
Add parameter objects, previously created in Step 2, such as :p_thingspeakApiKey
,p_sensorDht22
,p_pinSda
andp_pinScl
//add all parameters hereESP8266_W5100_manager.addParameter(&p_thingspeakApiKey);ESP8266_W5100_manager.addParameter(&p_sensorDht22);ESP8266_W5100_manager.addParameter(&p_pinSda);ESP8266_W5100_manager.addParameter(&p_pinScl);
When the CP exits, we have to store the parameters' values that users input via CP to use later.
For ESP8266, that can beEEPROM
orSPIFFS
.
We can write directly to awell-defined structure of our choice, but the current example is usingJSON
to be portable butmuch more complicated and not advised for new users.
After users selectSave
, the CPESP8266_W5100_Manager
object will save the user input data into relatedESP8266_EMParameter
objects.
We can now retrieve the data, usinggetValue()
function, for eachESP8266_EMParameter
object. Then we can utilize the data for our purpose, such asthingspeakApiKey
to log in,sensorDht22
type to know how to handle the sensor,pinSda
andpinSda
to know which pins to use to communicate with the DHT sensor.
The code is as follows:
// Getting posted form values and overriding local variables parameters// Config file is written regardless the connection statestrcpy(thingspeakApiKey, p_thingspeakApiKey.getValue());sensorDht22 = (strncmp(p_sensorDht22.getValue(),"T",1) ==0);pinSda = atoi(p_pinSda.getValue());pinScl = atoi(p_pinScl.getValue());
We can also save to FS file to use later in next boot.
// Writing JSON config file to flash for next bootwriteConfigFile();
First, you have to familiarize yourself withArduinoJson
library, its functions, thedisruptive
differences betweenArduinoJson version 5.x.x-
andv6.0.0+
. The best documentation can be found atThe best JSON library for embedded C++.
This documentation will discuss onlyArduinoJson v6.x.x+
(ARDUINOJSON_VERSION_MAJOR >= 6
)
Then have a look at the code snippet ofwriteConfigFile()
function and the following step-by-step explanations.
boolwriteConfigFile(){ Serial.println("Saving config file");#if (ARDUINOJSON_VERSION_MAJOR >= 6) DynamicJsonDocumentjson(1024);#else DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject();#endif// JSONify local configuration parameters json[ThingSpeakAPI_Label] = thingspeakApiKey; json[SensorDht22_Label] = sensorDht22; json[PinSDA_Label] = pinSda; json[PinSCL_Label] = pinScl;// Open file for writing File f = FileFS.open(CONFIG_FILE,"w");if (!f) { Serial.println("Failed to open config file for writing");returnfalse; }#if (ARDUINOJSON_VERSION_MAJOR >= 6)serializeJsonPretty(json, Serial);// Write data to file and close itserializeJson(json, f);#else json.prettyPrintTo(Serial);// Write data to file and close it json.printTo(f);#endif f.close(); Serial.println("\nConfig file was successfully saved");returntrue;}
We'll create an object with size 1024 bytes, enough to hold our data:
DynamicJsonDocumentjson(1024);
ThenJSONify
all local parameters we've just received from CP and wish to store into FS by using the function prototype:
json[Unique_Label] = Value_For_Unique_Label;
as follows:
// JSONify local configuration parametersjson[ThingSpeakAPI_Label] = thingspeakApiKey;json[SensorDht22_Label] = sensorDht22;json[PinSDA_Label] = pinSda;json[PinSCL_Label] = pinScl;
This is theCONFIG_FILE
file name we already declared at the beginning of the sketch (for ESP8266):
#include<SPIFFS.h>FS* filesystem = &SPIFFS;#defineFileFS SPIFFSconstchar* CONFIG_FILE ="/ConfigSW.json";
Now just open the file for writing, and abort if open-for-writing error:
// Open file for writingFile f = FileFS.open(CONFIG_FILE,"w");if (!f){ Serial.println("Failed to open config file for writing");returnfalse;}
As simple as this single command to write the wholejson
object we declared then filled with data in steps 5.1 and 5.2
// Write data to file and close itserializeJson(json, f);
Soooo simple !!! Now everybody can do it.
f.close();
ButHOWTO use the saved data in the next startup ???? That's in next step 6.
Now, you have familiarized yourself with ArduinoJson library, its functions. We'll discuss HOWTO read data from theCONFIG_FILE
in Jsonified format, then HOWTO parse the to use.
The documentation will discuss onlyArduinoJson v6.x.x+
(ARDUINOJSON_VERSION_MAJOR >= 6
)
First, have a look at the code snippet ofreadConfigFile()
function.
boolreadConfigFile(){// this opens the config file in read-mode File f = FileFS.open(CONFIG_FILE,"r");if (!f) { Serial.println("Configuration file not found");returnfalse; }else {// we could open the filesize_t size = f.size();// Allocate a buffer to store contents of the file. std::unique_ptr<char[]>buf(newchar[size +1]);// Read and store file contents in buf f.readBytes(buf.get(), size);// Closing file f.close();// Using dynamic JSON buffer which is not the recommended memory model, but anyway// See https://github.com/bblanchon/ArduinoJson/wiki/Memory%20model#if (ARDUINOJSON_VERSION_MAJOR >= 6) DynamicJsonDocumentjson(1024);auto deserializeError =deserializeJson(json, buf.get());if ( deserializeError ) { Serial.println("JSON parseObject() failed");returnfalse; }serializeJson(json, Serial);#else DynamicJsonBuffer jsonBuffer;// Parse JSON string JsonObject& json = jsonBuffer.parseObject(buf.get());// Test if parsing succeeds.if (!json.success()) { Serial.println("JSON parseObject() failed");returnfalse; } json.printTo(Serial);#endif// Parse all config file parameters, override// local config variables with parsed valuesif (json.containsKey(ThingSpeakAPI_Label)) {strcpy(thingspeakApiKey, json[ThingSpeakAPI_Label]); }if (json.containsKey(SensorDht22_Label)) { sensorDht22 = json[SensorDht22_Label]; }if (json.containsKey(PinSDA_Label)) { pinSda = json[PinSDA_Label]; }if (json.containsKey(PinSCL_Label)) { pinScl = json[PinSCL_Label]; } } Serial.println("\nConfig file was successfully parsed");returntrue;}
and the following step-by-step explanations.
As simple as this
// this opens the config file in read-modeFile f = FileFS.open(CONFIG_FILE,"r");
We'll inform and abort if theCONFIG_FILE
can't be opened (file not found, can't be opened, etc.)
if (!f){ Serial.println("Configuration file not found");returnfalse;}
Now we have to determine the file size to create a buffer large enough to store the to-be-read data
// we could open the filesize_t size = f.size();// Allocate a buffer to store contents of the file.std::unique_ptr<char[]>buf(newchar[size +1]);
Remember always add 1 to the buffer length to store the terminating0
.
Then just read the file into the buffer, and close the file to be safe
// Read and store file contents in buff.readBytes(buf.get(), size);// Closing filef.close();
We again use the sameDynamicJsonDocument json
object to store the data we've just read fromCONFIG_FILE
.
Why the same complicatedDynamicJsonDocument json
object ?? Because in steps 5, we did storeJsonified data
using the sameDynamicJsonDocument json
object. It's much easier we now use it again to facilitate the parsing ofJsonified data
back to the data we can use easily.
We first create the object with enough size
DynamicJsonDocumentjson(1024);
then populate it with data from buffer we read fromCONFIG_FILE
in step 6.2, pre-parse and check for error. All is done just by one commanddeserializeJson()
auto deserializeError = deserializeJson(json, buf.get());
Abort if there is any data error in the process of writing, storing, reading back. If OK, just nicely print out to the Debug Terminal
if ( deserializeError ){ Serial.println("JSON parseObject() failed");returnfalse;}serializeJson(json, Serial);
6.4 Parse the Jsonified data from the DynamicJsonDocument json object to store into corresponding parameters
This is as simple as in the step 5.2, but in reverse direction.
To be sure there is good corresponding data, not garbage, for each variable, we have to performsanity checks byverifying theDynamicJsonDocument json object
still contains the correct keys we passed to it when we wrote intoCONFIG_FILE
.
For example:
if (json.containsKey(ThingSpeakAPI_Label))
Then proceed to get every parameter we know we stored there from last CPSave
.
// Parse all config file parameters, override// local config variables with parsed valuesif (json.containsKey(ThingSpeakAPI_Label)){strcpy(thingspeakApiKey, json[ThingSpeakAPI_Label]);}if (json.containsKey(SensorDht22_Label)){ sensorDht22 = json[SensorDht22_Label];}if (json.containsKey(PinSDA_Label)){ pinSda = json[PinSDA_Label];}if (json.containsKey(PinSCL_Label)){ pinScl = json[PinSCL_Label];}
Just use those parameters for whatever purpose you designed them for in step 1:
The application will use DHTsensor (either DHT11or DHT22) and need to connect to ThingSpeak with unique user's API Key. The DHT sensor is connected to the ESP boards using SDA/SCL pins which also need to be configurable.
InConfigPortal Mode
, it starts an access point @ the current Static or DHCP IP.
Connect to it by going to, e.g.http://192.168.2.186
, you'll see thisMain
page:
SelectInformation
to enter the Info page where the board info will be shown (long page)
SelectConfiguration
to enter this page where you can modify its Credentials
Enter your credentials, then clickSave. The Credentials will be saved and the board continues, or reboots if necessary, to connect to the selected Static IP or DHCP.
If you're already satisfied with the current settings and don't want to change anything, just selectExit Portal from theMain
page to continue or reboot the board and connect using the previously-stored Credentials.
You can password protect the ConfigPortal AP. CheckESP8266_FSWebServer example
This gets called when custom parameters have been setAND a connection has been established. Use it to set a flag, so when all the configuration finishes, you can save the extra parameters somewhere.
ESP8266_W5100_manager.setSaveConfigCallback(saveConfigCallback);
saveConfigCallback declaration and example
//flag for saving databool shouldSaveConfig =false;//callback notifying us of the need to save configvoidsaveConfigCallback () { Serial.println("Should save config"); shouldSaveConfig =true;}
If you need to set a timeout so theESP8266
doesn't hang waiting to be configured for ever.
ESP8266_W5100_manager.setConfigPortalTimeout(120);
which will wait 2 minutes (120 seconds). When the time passes, thestartConfigPortal()
function will return and continue the sketch,unless you're accessing theConfig Portal
. In this case, thestartConfigPortal()
function will stay until you save config data or exittheConfig Portal
.
Example usage
voidloop(){// is configuration portal requested?if ((digitalRead(TRIGGER_PIN) == LOW) || (digitalRead(TRIGGER_PIN2) == LOW)) { Serial.println(F("\nConfiguration portal requested."));digitalWrite(LED_BUILTIN, LED_ON);// turn the LED on by making the voltage LOW to tell us we are in configuration mode.//Local initialization. Once its business is done, there is no need to keep it around// Use this to default DHCP hostname to ESP8266-XXXXXX//ESP8266_W5100_Manager ESP8266_W5100_manager;// Use this to personalize DHCP hostname (RFC952 conformed) ESP8266_W5100_ManagerESP8266_W5100_manager("ConfigOnSwitch");#if !USE_DHCP_IP#if USE_CONFIGURABLE_DNS// Set static IP, Gateway, Subnetmask, DNS1 and DNS2 ESP8266_W5100_manager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask, dns1IP, dns2IP);#else// Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. ESP8266_W5100_manager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask);#endif#endif#if USING_CORS_FEATURE ESP8266_W5100_manager.setCORSHeader("Your Access-Control-Allow-Origin");#endif//Check if there is stored credentials.//If not found, device will remain in configuration mode until switched off via webserver. Serial.println(F("Opening configuration portal."));if (loadConfigData()) {//If no access point name has been previously entered disable timeout. ESP8266_W5100_manager.setConfigPortalTimeout(120); Serial.println(F("Got stored Credentials. Timeout 120s for Config Portal")); }else {// Enter CP only if no stored SSID on flash and file ESP8266_W5100_manager.setConfigPortalTimeout(0); Serial.println(F("Open Config Portal without Timeout: No stored Credentials.")); initialConfig =true; }//Starts an access point//and goes into a blocking loop awaiting configurationif (!ESP8266_W5100_manager.startConfigPortal()) Serial.println(F("Not connected to ETH network but continuing anyway."));else { Serial.println(F("ETH network connected...yeey :)")); Serial.print(F("Local IP:")); Serial.println(eth.localIP()); }#if USE_ESP_ETH_MANAGER_NTP String tempTZ = ESP8266_W5100_manager.getTimezoneName();if (strlen(tempTZ.c_str()) <sizeof(Ethconfig.TZ_Name) -1)strcpy(Ethconfig.TZ_Name, tempTZ.c_str());elsestrncpy(Ethconfig.TZ_Name, tempTZ.c_str(),sizeof(Ethconfig.TZ_Name) -1);constchar * TZ_Result = ESP8266_W5100_manager.getTZ(Ethconfig.TZ_Name);if (strlen(TZ_Result) <sizeof(Ethconfig.TZ) -1)strcpy(Ethconfig.TZ, TZ_Result);elsestrncpy(Ethconfig.TZ, TZ_Result,sizeof(Ethconfig.TZ_Name) -1);if (strlen(Ethconfig.TZ_Name) >0 ) {LOGERROR3(F("Saving current TZ_Name ="), Ethconfig.TZ_Name,F(", TZ ="), Ethconfig.TZ);configTime(Ethconfig.TZ,"pool.ntp.org"); }else {LOGERROR(F("Current Timezone Name is not set. Enter Config Portal to set.")); }#endif ESP8266_W5100_manager.getSTAStaticIPConfig(EthSTA_IPconfig);saveConfigData();#if !USE_DHCP_IP// Reset to use new Static IP, if different from current eth.localIP()if (eth.localIP() != EthSTA_IPconfig._sta_static_ip) { Serial.print(F("Current IP =")); Serial.print(eth.localIP()); Serial.print(F(". Reset to take new IP =")); Serial.println(EthSTA_IPconfig._sta_static_ip); ESP.reset();delay(2000); }#endifdigitalWrite(LED_BUILTIN, LED_OFF);// Turn led off as we are not in configuration mode. }// put your main code here, to run repeatedlycheck_status();}
SeeConfigOnSwitch example for a more complex version.
Many applications need configuration parameters likeMQTT host and port
,Blynk oremoncms tokens, etc. While it is possible to useESP8266_W5100_Manager
to collect additional parameters, it is better to read these parameters from a web service onceESP8266_W5100_Manager
has been used to connect to the Internet.
To capture other parameters withESP8266_W5100_Manager
is a little bit more complicated than all the other features. This requires adding custom HTML to your form.
If you want to do it withESP8266_W5100_Manager
see the exampleConfigOnSwitchFS
You can set a custom IP for STA (station mode, client mode, normal project state)
This will use the specified IP configuration instead of using DHCP in station mode.
ESP8266_W5100_manager.setSTAStaticIPConfig(IPAddress(192,168,2,186), IPAddress(192,168,2,1), IPAddress(255,255,255,0));
There are various ways in which you can inject custom HTML, CSS or Javascript into the ConfigPortal.
The options are:
- inject custom head element
You can use this to any html bit to the head of the ConfigPortal. If you add a<style>
element, keep in mind it overwrites the includedcss
, not replaces.
ESP8266_W5100_manager.setCustomHeadElement("<style>html{filter: invert(100%); -webkit-filter: invert(100%);}</style>");
- inject a custom bit of html in the configuration form
ESP8266_EMParametercustom_text("<p>This is just a text paragraph</p>");ESP8266_W5100_manager.addParameter(&custom_text);
- inject a custom bit of html in a configuration form element
Just add the bit you want added as the last parameter to the custom parameter constructor.
ESP8266_EMParametercustom_mqtt_server("server","mqtt server","iot.eclipse",40," readonly");
You can change theCS/SS
pin to another one. Default isGPIO16
ConnectingCS/SS
toTX0/GPIO15
interferes with uploading firmware to ESP8266. If absolutely necessary to useTX0/GPIO15
, remove the wire toTX0/GPIO15
before uploading firmware. Then reconnect after done uploading.
// Using GPIO4, GPIO16, or GPIO5#defineCSPIN16
W5100 | <---> | ESP8266 |
---|---|---|
MOSI | <---> | GPIO13 |
MISO | <---> | GPIO12 |
SCK | <---> | GPIO14 |
SS | <---> | GPIO16 |
GND | <---> | GND |
3.3V | <---> | 3.3V |
- ConfigOnSwitch
- ConfigOnSwitchFS
- ConfigOnDoubleReset_TZ (now support ArduinoJson 6.0.0+ as well as 5.13.5-)
- ConfigOnDoubleReset (now support ArduinoJson 6.0.0+ as well as 5.13.5-)
- ConfigPortalParamsOnSwitch (now support ArduinoJson 6.0.0+ as well as 5.13.5-)
- ESP8266_FSWebServer
- ESP8266_FSWebServer_DRD
ExampleConfigOnSwitch
ESP8266_W5100_Manager/examples/ConfigOnSwitch/ConfigOnSwitch.ino
Lines 27 to 786 ince30b44
#if !( defined(ESP8266) ) | |
#error This code is intended to run on the (ESP8266 + LwIP W5100) platform! Please check your Tools->Board setting. | |
#endif | |
////////////////////////////////////////////////////////////// | |
// Use from 0 to 4. Higher number, more debugging messages and memory usage. | |
#define_ESP8266_ETH_MGR_LOGLEVEL_4 | |
// To not display stored SSIDs and PWDs on Config Portal, select false. Default is true | |
// Even the stored Credentials are not display, just leave them all blank to reconnect and reuse the stored Credentials | |
//#define DISPLAY_STORED_CREDENTIALS_IN_CP false | |
////////////////////////////////////////////////////////////// | |
// Using GPIO4, GPIO16, or GPIO5 | |
#defineCSPIN16 | |
////////////////////////////////////////////////////////// | |
#include<FS.h> | |
#include<ESP8266WiFi.h>//https://github.com/esp8266/Arduino | |
//needed for library | |
#include<DNSServer.h> | |
#defineUSE_LITTLEFStrue | |
#if USE_LITTLEFS | |
#include<LittleFS.h> | |
FS* filesystem = &LittleFS; | |
#defineFileFS LittleFS | |
#defineFS_Name"LittleFS" | |
#else | |
FS* filesystem = &SPIFFS; | |
#defineFileFS SPIFFS | |
#defineFS_Name"SPIFFS" | |
#endif | |
////////////////////////////////////////////////////////// | |
#defineESP_getChipId() (ESP.getChipId()) | |
#defineLED_ON LOW | |
#defineLED_OFF HIGH | |
////////////////////////////////////////////////////////// | |
// Onboard LED I/O pin on NodeMCU board | |
#defineLED_BUILTIN2// Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED | |
//PIN_D0 can't be used for PWM/I2C | |
#definePIN_D016// Pin D0 mapped to pin GPIO16/USER/WAKE of ESP8266. This pin is also used for Onboard-Blue LED. PIN_D0 = 0 => LED ON | |
#definePIN_D15// Pin D1 mapped to pin GPIO5 of ESP8266 | |
#definePIN_D24// Pin D2 mapped to pin GPIO4 of ESP8266 | |
#definePIN_D30// Pin D3 mapped to pin GPIO0/FLASH of ESP8266 | |
#definePIN_D42// Pin D4 mapped to pin GPIO2/TXD1 of ESP8266 | |
#definePIN_D514// Pin D5 mapped to pin GPIO14/HSCLK of ESP8266 | |
#definePIN_D612// Pin D6 mapped to pin GPIO12/HMISO of ESP8266 | |
#definePIN_D713// Pin D7 mapped to pin GPIO13/RXD2/HMOSI of ESP8266 | |
#definePIN_D815// Pin D8 mapped to pin GPIO15/TXD2/HCS of ESP8266 | |
//Don't use pins GPIO6 to GPIO11 as already connected to flash, etc. Use them can crash the program | |
//GPIO9(D11/SD2) and GPIO11 can be used only if flash in DIO mode ( not the default QIO mode) | |
#definePIN_D119// Pin D11/SD2 mapped to pin GPIO9/SDD2 of ESP8266 | |
#definePIN_D1210// Pin D12/SD3 mapped to pin GPIO10/SDD3 of ESP8266 | |
#definePIN_SD29// Pin SD2 mapped to pin GPIO9/SDD2 of ESP8266 | |
#definePIN_SD310// Pin SD3 mapped to pin GPIO10/SDD3 of ESP8266 | |
#definePIN_D93// Pin D9 /RX mapped to pin GPIO3/RXD0 of ESP8266 | |
#definePIN_D101// Pin D10/TX mapped to pin GPIO1/TXD0 of ESP8266 | |
#definePIN_RX3// Pin RX mapped to pin GPIO3/RXD0 of ESP8266 | |
#definePIN_TX1// Pin RX mapped to pin GPIO1/TXD0 of ESP8266 | |
#defineLED_PIN16// Pin D0 mapped to pin GPIO16 of ESP8266. This pin is also used for Onboard-Blue LED. PIN_D0 = 0 => LED ON | |
/* Trigger for inititating config mode is Pin D1 and also flash button on NodeMCU | |
Flash button is convenient to use but if it is pressed it will stuff up the serial port device driver | |
until the computer is rebooted on windows machines. | |
*/ | |
constint TRIGGER_PIN = PIN_D1;// D1 on NodeMCU and WeMos. | |
/* | |
Alternative trigger pin. Needs to be connected to a button to use this pin. It must be a momentary connection | |
not connected permanently to ground. Either trigger pin will work. | |
*/ | |
constint TRIGGER_PIN2 = PIN_D2;// D2 on NodeMCU and WeMos. | |
////////////////////////////////////////////////////////////// | |
// You only need to format the filesystem once | |
//#define FORMAT_FILESYSTEM true | |
#defineFORMAT_FILESYSTEMfalse | |
////////////////////////////////////////////////////////////// | |
// Assuming max 49 chars | |
#defineTZNAME_MAX_LEN50 | |
#defineTIMEZONE_MAX_LEN50 | |
typedefstruct | |
{ | |
char TZ_Name[TZNAME_MAX_LEN];// "America/Toronto" | |
char TZ[TIMEZONE_MAX_LEN];// "EST5EDT,M3.2.0,M11.1.0" | |
uint16_t checksum; | |
} EthConfig; | |
EthConfig Ethconfig; | |
////////////////////////////////////////////////////////////// | |
#defineCONFIG_FILENAMEF("/eth_cred.dat") | |
////////////////////////////////////////////////////////////// | |
// Indicates whether ESP has credentials saved from previous session, or double reset detected | |
bool initialConfig = false; | |
// Use false if you don't like to display Available Pages in Information Page of Config Portal | |
// Comment out or use true to display Available Pages in Information Page of Config Portal | |
// Must be placed before #include <ESP8266_W5100_Manager.h> | |
#defineUSE_AVAILABLE_PAGEStrue | |
// From v1.0.10 to permit disable/enable StaticIP configuration in Config Portal from sketch. Valid only if DHCP is used. | |
// You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa | |
// You have to explicitly specify false to disable the feature. | |
//#define USE_STATIC_IP_CONFIG_IN_CP false | |
// Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal. | |
// See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23) | |
#defineUSE_ESP_ETH_MANAGER_NTPtrue | |
// Just use enough to save memory. On ESP8266, can cause blank ConfigPortal screen | |
// if using too much memory | |
#defineUSING_AFRICAfalse | |
#defineUSING_AMERICAtrue | |
#defineUSING_ANTARCTICAfalse | |
#defineUSING_ASIAfalse | |
#defineUSING_ATLANTICfalse | |
#defineUSING_AUSTRALIAfalse | |
#defineUSING_EUROPEfalse | |
#defineUSING_INDIANfalse | |
#defineUSING_PACIFICfalse | |
#defineUSING_ETC_GMTfalse | |
// Use true to enable CloudFlare NTP service. System can hang if you don't have Internet access while accessing CloudFlare | |
// See Issue #21: CloudFlare link in the default portal (https://github.com/khoih-prog/ESP_WiFiManager/issues/21) | |
#defineUSE_CLOUDFLARE_NTPfalse | |
// New in v1.0.11 | |
#defineUSING_CORS_FEATUREtrue | |
////////////////////////////////////////////////////////////// | |
// Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network | |
#if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP) | |
// Force DHCP to be true | |
#if defined(USE_DHCP_IP) | |
#undef USE_DHCP_IP | |
#endif | |
#defineUSE_DHCP_IPtrue | |
#else | |
// You can select DHCP or Static IP here | |
//#define USE_DHCP_IP true | |
#defineUSE_DHCP_IPfalse | |
#endif | |
#if ( USE_DHCP_IP ) | |
// Use DHCP | |
#if (_ESP8266_ETH_MGR_LOGLEVEL_ > 3) | |
#warning Using DHCP IP | |
#endif | |
IPAddress stationIP = IPAddress(0,0,0,0); | |
IPAddress gatewayIP = IPAddress(192,168,2,1); | |
IPAddress netMask = IPAddress(255,255,255,0); | |
#else | |
// Use static IP | |
#if (_ESP8266_ETH_MGR_LOGLEVEL_ > 3) | |
#warning Using static IP | |
#endif | |
IPAddress stationIP = IPAddress(192,168,2,186); | |
IPAddress gatewayIP = IPAddress(192,168,2,1); | |
IPAddress netMask = IPAddress(255,255,255,0); | |
#endif | |
////////////////////////////////////////////////////////////// | |
#defineUSE_CONFIGURABLE_DNStrue | |
IPAddress dns1IP = gatewayIP; | |
IPAddress dns2IP = IPAddress(8,8,8,8); | |
#include<ESP8266_W5100_Manager.h>//https://github.com/khoih-prog/ESP8266_W5100_Manager | |
#defineHTTP_PORT80 | |
////////////////////////////////////////////////////////////// | |
/****************************************** | |
// Defined in ESP8266_W5100_Manager.hpp | |
typedef struct | |
{ | |
IPAddress _sta_static_ip; | |
IPAddress _sta_static_gw; | |
IPAddress _sta_static_sn; | |
#if USE_CONFIGURABLE_DNS | |
IPAddress _sta_static_dns1; | |
IPAddress _sta_static_dns2; | |
#endif | |
} ETH_STA_IPConfig; | |
******************************************/ | |
ETH_STA_IPConfig EthSTA_IPconfig; | |
////////////////////////////////////////////////////////////// | |
voidinitSTAIPConfigStruct(ETH_STA_IPConfig &in_EthSTA_IPconfig) | |
{ | |
in_EthSTA_IPconfig._sta_static_ip = stationIP; | |
in_EthSTA_IPconfig._sta_static_gw = gatewayIP; | |
in_EthSTA_IPconfig._sta_static_sn = netMask; | |
#if USE_CONFIGURABLE_DNS | |
in_EthSTA_IPconfig._sta_static_dns1 = dns1IP; | |
in_EthSTA_IPconfig._sta_static_dns2 = dns2IP; | |
#endif | |
} | |
////////////////////////////////////////////////////////////// | |
voiddisplayIPConfigStruct(ETH_STA_IPConfig in_EthSTA_IPconfig) | |
{ | |
LOGERROR3(F("stationIP ="), in_EthSTA_IPconfig._sta_static_ip,", gatewayIP =", in_EthSTA_IPconfig._sta_static_gw); | |
LOGERROR1(F("netMask ="), in_EthSTA_IPconfig._sta_static_sn); | |
#if USE_CONFIGURABLE_DNS | |
LOGERROR3(F("dns1IP ="), in_EthSTA_IPconfig._sta_static_dns1,", dns2IP =", in_EthSTA_IPconfig._sta_static_dns2); | |
#endif | |
} | |
////////////////////////////////////////////////////////////// | |
voidtoggleLED() | |
{ | |
//toggle state | |
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); | |
} | |
////////////////////////////////////////////////////////////// | |
#if USE_ESP_ETH_MANAGER_NTP | |
voidprintLocalTime() | |
{ | |
statictime_t now; | |
now =time(nullptr); | |
if ( now >1451602800 ) | |
{ | |
Serial.print("Local Date/Time:"); | |
Serial.print(ctime(&now)); | |
} | |
} | |
#endif | |
////////////////////////////////////////////////////////////// | |
voidheartBeatPrint() | |
{ | |
#if USE_ESP_ETH_MANAGER_NTP | |
printLocalTime(); | |
#else | |
staticint num =1; | |
if (eth.connected()) | |
Serial.print(F("H"));// H means connected to Ethernet | |
else | |
Serial.print(F("F"));// F means not connected to Ethernet | |
if (num ==80) | |
{ | |
Serial.println(); | |
num =1; | |
} | |
elseif (num++ %10 ==0) | |
{ | |
Serial.print(F("")); | |
} | |
#endif | |
} | |
////////////////////////////////////////////////////////////// | |
voidcheck_status() | |
{ | |
static ulong checkstatus_timeout =0; | |
static ulong LEDstatus_timeout =0; | |
static ulong current_millis; | |
#if USE_ESP_ETH_MANAGER_NTP | |
#defineHEARTBEAT_INTERVAL60000L | |
#else | |
#defineHEARTBEAT_INTERVAL10000L | |
#endif | |
#defineLED_INTERVAL2000L | |
current_millis =millis(); | |
if ((current_millis > LEDstatus_timeout) || (LEDstatus_timeout ==0)) | |
{ | |
// Toggle LED at LED_INTERVAL = 2s | |
toggleLED(); | |
LEDstatus_timeout = current_millis + LED_INTERVAL; | |
} | |
// Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. | |
if ((current_millis > checkstatus_timeout) || (checkstatus_timeout ==0)) | |
{ | |
heartBeatPrint(); | |
checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; | |
} | |
} | |
////////////////////////////////////////////////////////////// | |
intcalcChecksum(uint8_t* address,uint16_t sizeToCalc) | |
{ | |
uint16_t checkSum =0; | |
for (uint16_t index =0; index < sizeToCalc; index++) | |
{ | |
checkSum += * ( ( (byte*) address ) + index); | |
} | |
return checkSum; | |
} | |
////////////////////////////////////////////////////////////// | |
boolloadConfigData() | |
{ | |
File file = FileFS.open(CONFIG_FILENAME,"r"); | |
LOGERROR(F("LoadCfgFile")); | |
memset((void *) &Ethconfig,0,sizeof(Ethconfig)); | |
memset((void *) &EthSTA_IPconfig,0,sizeof(EthSTA_IPconfig)); | |
if (file) | |
{ | |
file.readBytes((char *) &Ethconfig,sizeof(Ethconfig)); | |
file.readBytes((char *) &EthSTA_IPconfig,sizeof(EthSTA_IPconfig)); | |
file.close(); | |
LOGERROR(F("OK")); | |
if ( Ethconfig.checksum !=calcChecksum( (uint8_t*) &Ethconfig,sizeof(Ethconfig) -sizeof(Ethconfig.checksum) ) ) | |
{ | |
LOGERROR(F("Ethconfig checksum wrong")); | |
returnfalse; | |
} | |
displayIPConfigStruct(EthSTA_IPconfig); | |
returntrue; | |
} | |
else | |
{ | |
LOGERROR(F("failed")); | |
returnfalse; | |
} | |
} | |
////////////////////////////////////////////////////////////// | |
voidsaveConfigData() | |
{ | |
File file = FileFS.open(CONFIG_FILENAME,"w"); | |
LOGERROR(F("SaveCfgFile")); | |
if (file) | |
{ | |
Ethconfig.checksum =calcChecksum( (uint8_t*) &Ethconfig,sizeof(Ethconfig) -sizeof(Ethconfig.checksum) ); | |
file.write((uint8_t*) &Ethconfig,sizeof(Ethconfig)); | |
displayIPConfigStruct(EthSTA_IPconfig); | |
file.write((uint8_t*) &EthSTA_IPconfig,sizeof(EthSTA_IPconfig)); | |
file.close(); | |
LOGERROR(F("OK")); | |
} | |
else | |
{ | |
LOGERROR(F("failed")); | |
} | |
} | |
////////////////////////////////////////////////////////////// | |
voidinitEthernet() | |
{ | |
SPI.begin(); | |
SPI.setClockDivider(SPI_CLOCK_DIV4); | |
SPI.setBitOrder(MSBFIRST); | |
SPI.setDataMode(SPI_MODE0); | |
LOGWARN(F("Default SPI pinout:")); | |
LOGWARN1(F("MOSI:"), MOSI); | |
LOGWARN1(F("MISO:"), MISO); | |
LOGWARN1(F("SCK:"), SCK); | |
LOGWARN1(F("CS:"), CSPIN); | |
LOGWARN(F("=========================")); | |
#if !USING_DHCP | |
//eth.config(localIP, gateway, netMask, gateway); | |
eth.config(EthSTA_IPconfig._sta_static_ip, EthSTA_IPconfig._sta_static_gw, EthSTA_IPconfig._sta_static_sn, | |
EthSTA_IPconfig._sta_static_dns1); | |
#endif | |
eth.setDefault(); | |
if (!eth.begin()) | |
{ | |
Serial.println("No Ethernet hardware ... Stop here"); | |
while (true) | |
{ | |
delay(1000); | |
} | |
} | |
else | |
{ | |
Serial.print("Connecting to network :"); | |
while (!eth.connected()) | |
{ | |
Serial.print("."); | |
delay(1000); | |
} | |
} | |
Serial.println(); | |
#if USING_DHCP | |
Serial.print("Ethernet DHCP IP address:"); | |
#else | |
Serial.print("Ethernet Static IP address:"); | |
#endif | |
Serial.println(eth.localIP()); | |
} | |
////////////////////////////////////////////////////////////// | |
voidsetup() | |
{ | |
//set led pin as output | |
pinMode(LED_BUILTIN, OUTPUT); | |
pinMode(TRIGGER_PIN, INPUT_PULLUP); | |
pinMode(TRIGGER_PIN2, INPUT_PULLUP); | |
Serial.begin(115200); | |
while (!Serial &&millis() <5000); | |
delay(200); | |
Serial.print(F("\nStarting ConfigOnSwitch using")); | |
Serial.print(FS_Name); | |
Serial.print(F(" on")); | |
Serial.print(ARDUINO_BOARD); | |
Serial.print(F(" with")); | |
Serial.println(SHIELD_TYPE); | |
Serial.println(ESP8266_W5100_MANAGER_VERSION); | |
Serial.setDebugOutput(false); | |
#if FORMAT_FILESYSTEM | |
Serial.println(F("Forced Formatting.")); | |
FileFS.format(); | |
#endif | |
// Format FileFS if not yet | |
if (!FileFS.begin()) | |
{ | |
FileFS.format(); | |
Serial.println(F("SPIFFS/LittleFS failed! Already tried formatting.")); | |
if (!FileFS.begin()) | |
{ | |
// prevents debug info from the library to hide err message. | |
delay(100); | |
#if USE_LITTLEFS | |
Serial.println(F("LittleFS failed!. Please use SPIFFS or EEPROM. Stay forever")); | |
#else | |
Serial.println(F("SPIFFS failed!. Please use LittleFS or EEPROM. Stay forever")); | |
#endif | |
while (true) | |
{ | |
delay(1); | |
} | |
} | |
} | |
unsignedlong startedAt =millis(); | |
initSTAIPConfigStruct(EthSTA_IPconfig); | |
digitalWrite(LED_BUILTIN, LED_ON);// turn the LED on by making the voltage LOW to tell us we are in configuration mode. | |
//Local initialization. Once its business is done, there is no need to keep it around | |
// Use this to default DHCP hostname to ESP8266-XXXXXX | |
//ESP8266_W5100_Manager ESP8266_W5100_manager; | |
// Use this to personalize DHCP hostname (RFC952 conformed) | |
ESP8266_W5100_ManagerESP8266_W5100_manager("ConfigOnSwitch"); | |
ESP8266_W5100_manager.setDebugOutput(true); | |
#if !USE_DHCP_IP | |
// Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask) | |
ESP8266_W5100_manager.setSTAStaticIPConfig(EthSTA_IPconfig); | |
#endif | |
#if USING_CORS_FEATURE | |
ESP8266_W5100_manager.setCORSHeader("Your Access-Control-Allow-Origin"); | |
#endif | |
bool configDataLoaded =false; | |
if (loadConfigData()) | |
{ | |
configDataLoaded =true; | |
//If no access point name has been previously entered disable timeout. | |
ESP8266_W5100_manager.setConfigPortalTimeout(120); | |
Serial.println(F("Got stored Credentials. Timeout 120s for Config Portal")); | |
#if USE_ESP_ETH_MANAGER_NTP | |
if (strlen(Ethconfig.TZ_Name) >0 ) | |
{ | |
LOGERROR3(F("Current TZ_Name ="), Ethconfig.TZ_Name,F(", TZ ="), Ethconfig.TZ); | |
configTime(Ethconfig.TZ,"pool.ntp.org"); | |
} | |
else | |
{ | |
Serial.println(F("Current Timezone is not set. Enter Config Portal to set.")); | |
} | |
#endif | |
} | |
else | |
{ | |
// Enter CP only if no stored SSID on flash and file | |
Serial.println(F("Open Config Portal without Timeout: No stored Credentials.")); | |
initialConfig =true; | |
} | |
////////////////////////////////// | |
// Connect ETH now if using STA | |
initEthernet(); | |
////////////////////////////////// | |
if (initialConfig) | |
{ | |
Serial.print(F("Starting configuration portal @")); | |
Serial.println(eth.localIP()); | |
digitalWrite(LED_BUILTIN, LED_ON);// Turn led on as we are in configuration mode. | |
//sets timeout in seconds until configuration portal gets turned off. | |
//If not specified device will remain in configuration mode until | |
//switched off via webserver or device is restarted. | |
//ESP8266_W5100_manager.setConfigPortalTimeout(600); | |
// Starts an access point | |
if (!ESP8266_W5100_manager.startConfigPortal()) | |
Serial.println(F("Not connected to ETH network but continuing anyway.")); | |
else | |
{ | |
Serial.println(F("ETH network connected...yeey :)")); | |
} | |
#if USE_ESP_ETH_MANAGER_NTP | |
String tempTZ = ESP8266_W5100_manager.getTimezoneName(); | |
if (strlen(tempTZ.c_str()) <sizeof(Ethconfig.TZ_Name) -1) | |
strcpy(Ethconfig.TZ_Name, tempTZ.c_str()); | |
else | |
strncpy(Ethconfig.TZ_Name, tempTZ.c_str(),sizeof(Ethconfig.TZ_Name) -1); | |
constchar * TZ_Result = ESP8266_W5100_manager.getTZ(Ethconfig.TZ_Name); | |
if (strlen(TZ_Result) <sizeof(Ethconfig.TZ) -1) | |
strcpy(Ethconfig.TZ, TZ_Result); | |
else | |
strncpy(Ethconfig.TZ, TZ_Result,sizeof(Ethconfig.TZ_Name) -1); | |
if (strlen(Ethconfig.TZ_Name) >0 ) | |
{ | |
LOGERROR3(F("Saving current TZ_Name ="), Ethconfig.TZ_Name,F(", TZ ="), Ethconfig.TZ); | |
configTime(Ethconfig.TZ,"pool.ntp.org"); | |
} | |
else | |
{ | |
LOGERROR(F("Current Timezone Name is not set. Enter Config Portal to set.")); | |
} | |
#endif | |
ESP8266_W5100_manager.getSTAStaticIPConfig(EthSTA_IPconfig); | |
saveConfigData(); | |
} | |
digitalWrite(LED_BUILTIN, LED_OFF);// Turn led off as we are not in configuration mode. | |
startedAt =millis(); | |
Serial.print(F("After waiting")); | |
Serial.print((float) (millis() - startedAt) /1000); | |
Serial.print(F(" secs more in setup(), connection result is")); | |
if (eth.connected()) | |
{ | |
Serial.print(F("connected. Local IP:")); | |
Serial.println(eth.localIP()); | |
} | |
} | |
////////////////////////////////////////////////////////////// | |
voidloop() | |
{ | |
// is configuration portal requested? | |
if ((digitalRead(TRIGGER_PIN) == LOW) || (digitalRead(TRIGGER_PIN2) == LOW)) | |
{ | |
Serial.println(F("\nConfiguration portal requested.")); | |
digitalWrite(LED_BUILTIN, LED_ON);// turn the LED on by making the voltage LOW to tell us we are in configuration mode. | |
//Local initialization. Once its business is done, there is no need to keep it around | |
// Use this to default DHCP hostname to ESP8266-XXXXXX | |
//ESP8266_W5100_Manager ESP8266_W5100_manager; | |
// Use this to personalize DHCP hostname (RFC952 conformed) | |
ESP8266_W5100_ManagerESP8266_W5100_manager("ConfigOnSwitch"); | |
#if !USE_DHCP_IP | |
#if USE_CONFIGURABLE_DNS | |
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2 | |
ESP8266_W5100_manager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask, dns1IP, dns2IP); | |
#else | |
// Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. | |
ESP8266_W5100_manager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask); | |
#endif | |
#endif | |
#if USING_CORS_FEATURE | |
ESP8266_W5100_manager.setCORSHeader("Your Access-Control-Allow-Origin"); | |
#endif | |
//Check if there is stored credentials. | |
//If not found, device will remain in configuration mode until switched off via webserver. | |
Serial.println(F("Opening configuration portal.")); | |
if (loadConfigData()) | |
{ | |
//If no access point name has been previously entered disable timeout. | |
ESP8266_W5100_manager.setConfigPortalTimeout(120); | |
Serial.println(F("Got stored Credentials. Timeout 120s for Config Portal")); | |
} | |
else | |
{ | |
// Enter CP only if no stored SSID on flash and file | |
ESP8266_W5100_manager.setConfigPortalTimeout(0); | |
Serial.println(F("Open Config Portal without Timeout: No stored Credentials.")); | |
initialConfig =true; | |
} | |
//Starts an access point | |
//and goes into a blocking loop awaiting configuration | |
if (!ESP8266_W5100_manager.startConfigPortal()) | |
Serial.println(F("Not connected to ETH network but continuing anyway.")); | |
else | |
{ | |
Serial.println(F("ETH network connected...yeey :)")); | |
Serial.print(F("Local IP:")); | |
Serial.println(eth.localIP()); | |
} | |
#if USE_ESP_ETH_MANAGER_NTP | |
String tempTZ = ESP8266_W5100_manager.getTimezoneName(); | |
if (strlen(tempTZ.c_str()) <sizeof(Ethconfig.TZ_Name) -1) | |
strcpy(Ethconfig.TZ_Name, tempTZ.c_str()); | |
else | |
strncpy(Ethconfig.TZ_Name, tempTZ.c_str(),sizeof(Ethconfig.TZ_Name) -1); | |
constchar * TZ_Result = ESP8266_W5100_manager.getTZ(Ethconfig.TZ_Name); | |
if (strlen(TZ_Result) <sizeof(Ethconfig.TZ) -1) | |
strcpy(Ethconfig.TZ, TZ_Result); | |
else | |
strncpy(Ethconfig.TZ, TZ_Result,sizeof(Ethconfig.TZ_Name) -1); | |
if (strlen(Ethconfig.TZ_Name) >0 ) | |
{ | |
LOGERROR3(F("Saving current TZ_Name ="), Ethconfig.TZ_Name,F(", TZ ="), Ethconfig.TZ); | |
configTime(Ethconfig.TZ,"pool.ntp.org"); | |
} | |
else | |
{ | |
LOGERROR(F("Current Timezone Name is not set. Enter Config Portal to set.")); | |
} | |
#endif | |
ESP8266_W5100_manager.getSTAStaticIPConfig(EthSTA_IPconfig); | |
saveConfigData(); | |
#if !USE_DHCP_IP | |
// Reset to use new Static IP, if different from current eth.localIP() | |
if (eth.localIP() != EthSTA_IPconfig._sta_static_ip) | |
{ | |
Serial.print(F("Current IP =")); | |
Serial.print(eth.localIP()); | |
Serial.print(F(". Reset to take new IP =")); | |
Serial.println(EthSTA_IPconfig._sta_static_ip); | |
ESP.reset(); | |
delay(2000); | |
} | |
#endif | |
digitalWrite(LED_BUILTIN, LED_OFF);// Turn led off as we are not in configuration mode. | |
} | |
// put your main code here, to run repeatedly | |
check_status(); | |
} |
This is terminal debug output when runningConfigOnDoubleReset onESP8266_W5100.Config Portal
was requested by DRD to input and save Credentials, such as Static IP address.
Starting ConfigOnDoubleReset_TZ using LittleFS on ESP8266_NODEMCU_ESP12E with ESP8266_W5100 EthernetESP8266_W5100_Manager v1.0.0ESP_DoubleResetDetector v1.3.2[EM] RFC925 Hostname = ConfigOnDoubleReset_TZ[EM] setSTAStaticIPConfig[EM] Set CORS Header to : Your Access-Control-Allow-Origin[EM] LoadCfgFile [EM] OK[EM] stationIP = 192.168.2.186 , gatewayIP = 192.168.2.1[EM] netMask = 255.255.255.0[EM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8Got stored Credentials. Timeout 120s for Config Portal[EM] Current TZ_Name = America/New_York , TZ = EST5EDT,M3.2.0,M11.1.0[EM] Default SPI pinout:[EM] MOSI: 13[EM] MISO: 12[EM] SCK: 14[EM] CS: 16[EM] =========================Connecting to network : Ethernet Static IP address: 192.168.2.186LittleFS Flag read = 0xD0D01234doubleResetDetectedSaving config file...Saving config file OKOpen Config Portal without Timeout: Double Reset DetectedStarting configuration portal @ 192.168.2.186_domainName = *_resolvedIP = 192.168.2.186_port = 53[EM] _configPortalStart millis() = 354[EM] Config Portal IP address = 192.168.2.186[EM] HTTP server started[EM] startConfigPortal : Enter loop[EM] handleRoot[EM] captivePortal: hostHeader = 192.168.2.186[EM] Handle ETH[EM] Static IP = 192.168.2.186[EM] Sent config page[EM] ETH save[EM] TZ name = America/New_York[EM] New Static IP = 192.168.2.188[EM] New Static Gateway = 192.168.2.1[EM] New Static Netmask = 255.255.255.0[EM] New Static DNS1 = 192.168.2.1[EM] New Static DNS2 = 8.8.8.8[EM] Sent eth save page[EM] stopConfigPortalETH network connected...yeey :)[EM] Saving current TZ_Name = America/New_York , TZ = EST5EDT,M3.2.0,M11.1.0[EM] getSTAStaticIPConfig[EM] SaveCfgFile [EM] stationIP = 192.168.2.188 , gatewayIP = 192.168.2.1[EM] netMask = 255.255.255.0[EM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8[EM] OKCurrent IP = 192.168.2.186. Reset to take new IP = 192.168.2.188ets Jan 8 2013,rst cause:2, boot mode:(3,6)
Starting ConfigOnDoubleReset_TZ using LittleFS on ESP8266_NODEMCU_ESP12E with ESP8266_W5100 EthernetESP8266_W5100_Manager v1.0.0ESP_DoubleResetDetector v1.3.2[EM] RFC925 Hostname = ConfigOnDoubleReset_TZ[EM] setSTAStaticIPConfig[EM] Set CORS Header to : Your Access-Control-Allow-Origin[EM] LoadCfgFile [EM] OK[EM] stationIP = 192.168.2.188 , gatewayIP = 192.168.2.1[EM] netMask = 255.255.255.0[EM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8Got stored Credentials. Timeout 120s for Config Portal[EM] Current TZ_Name = America/New_York , TZ = EST5EDT,M3.2.0,M11.1.0[EM] Default SPI pinout:[EM] MOSI: 13[EM] MISO: 12[EM] SCK: 14[EM] CS: 16[EM] =========================Connecting to network : Ethernet Static IP address: 192.168.2.188LittleFS Flag read = 0xD0D04321No doubleResetDetectedSaving config file...Saving config file OKAfter waiting 0.00 secs more in setup(), connection result is connected. Local IP: 192.168.2.188[EM] freeing allocated params!Stop doubleResetDetectingSaving config file...Saving config file OKLocal Date/Time: Sun Dec 11 20:09:39 2022Local Date/Time: Sun Dec 11 20:10:39 2022
This is terminal debug output when runningConfigOnSwichFS onESP8266_W5100.Config Portal
was requested to input and save Credentials.
Starting ConfigOnSwichFS using LittleFS on ESP8266_NODEMCU_ESP12E with ESP8266_W5100 EthernetESP8266_W5100_Manager v1.0.0{"thingspeakApiKey":"","SensorDHT22":true,"PinSda":4,"PinScl":5}Config file was successfully parsed[EM] RFC925 Hostname = ConfigOnSwitchFS[EM] setSTAStaticIPConfig[EM] Set CORS Header to : Your Access-Control-Allow-Origin[EM] LoadCfgFile [EM] OK[EM] stationIP = 192.168.2.186 , gatewayIP = 192.168.2.1[EM] netMask = 255.255.255.0[EM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8Got stored Credentials. Timeout 120s for Config PortalCurrent Timezone is not set. Enter Config Portal to set.[EM] Default SPI pinout:[EM] MOSI: 13[EM] MISO: 12[EM] SCK: 14[EM] CS: 16[EM] =========================Connecting to network : Ethernet Static IP address: 192.168.2.186After waiting 0.00 secs more in setup(), connection result is connected. Local IP: 192.168.2.186[EM] freeing allocated params!Configuration portal requested.[EM] RFC925 Hostname = ConfigOnSwitchFSOpening configuration portal. [EM] LoadCfgFile [EM] OK[EM] stationIP = 192.168.2.186 , gatewayIP = 192.168.2.1[EM] netMask = 255.255.255.0[EM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8Got stored Credentials. Timeout 120s for Config Portal[EM] Adding parameter thingspeakApiKey[EM] Adding parameter SensorDHT22[EM] Adding parameter PinSda[EM] Adding parameter PinScl[EM] setSTAStaticIPConfig for USE_CONFIGURABLE_DNS[EM] Set CORS Header to : Your Access-Control-Allow-Origin[EM] _configPortalStart millis() = 26788[EM] Config Portal IP address = 192.168.2.186[EM] HTTP server started[EM] startConfigPortal : Enter loop[EM] handleRoot[EM] request host IP = 192.168.2.186[EM] Info[EM] Info page sent[EM] handleRoot[EM] request host IP = 192.168.2.186[EM] Handle ETH[EM] Static IP = 192.168.2.186[EM] Sent config page[EM] ETH save[EM] TZ = America/Toronto[EM] Parameter and value : thingspeakApiKey [EM] Parameter and value : SensorDHT22 T[EM] Parameter and value : PinSda 4[EM] Parameter and value : PinScl 5[EM] New Static IP = 192.168.2.186[EM] New Static Gateway = 192.168.2.1[EM] New Static Netmask = 255.255.255.0[EM] New Static DNS1 = 192.168.2.1[EM] New Static DNS2 = 8.8.8.8[EM] Sent eth save page[EM] stopConfigPortalETH network connected...yeey :)Local IP: 192.168.2.186[EM] Saving current TZ_Name = America/Toronto , TZ = EST5EDT,M3.2.0,M11.1.0[EM] getSTAStaticIPConfig[EM] SaveCfgFile [EM] stationIP = 192.168.2.186 , gatewayIP = 192.168.2.1[EM] netMask = 255.255.255.0[EM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8[EM] OKSaving config file{ "thingspeakApiKey": "", "SensorDHT22": true, "PinSda": 4, "PinScl": 5}Config file was successfully savedCurrent IP = 192.168.2.186. Reset to take new IP = 192.168.2.186ets Jan 8 2013,rst cause:2, boot mode:(3,6)...Starting ConfigOnSwichFS using LittleFS on ESP8266_NODEMCU_ESP12E with ESP8266_W5100 EthernetESP8266_W5100_Manager v1.0.0{"thingspeakApiKey":"","SensorDHT22":true,"PinSda":4,"PinScl":5}Config file was successfully parsed[EM] RFC925 Hostname = ConfigOnSwitchFS[EM] setSTAStaticIPConfig[EM] Set CORS Header to : Your Access-Control-Allow-Origin[EM] LoadCfgFile [EM] OK[EM] stationIP = 192.168.2.186 , gatewayIP = 192.168.2.1[EM] netMask = 255.255.255.0[EM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8Got stored Credentials. Timeout 120s for Config Portal[EM] Current TZ_Name = America/Toronto , TZ = EST5EDT,M3.2.0,M11.1.0[EM] Default SPI pinout:[EM] MOSI: 13[EM] MISO: 12[EM] SCK: 14[EM] CS: 16[EM] =========================Connecting to network : Ethernet Static IP address: 192.168.2.186After waiting 0.00 secs more in setup(), connection result is connected. Local IP: 192.168.2.186[EM] freeing allocated params!Local Date/Time: Sun Dec 11 20:19:39 2022Local Date/Time: Sun Dec 11 20:20:39 2022
This is terminal debug output when runningESP8266_FSWebServer_DRD onESP8266_W5100.
The terminal debug output demonstrate the upload the contents of the data folder to ESP8266 LittleFS using the following command
for file in `\ls -A1`; do curl -F "file=@$PWD/$file" 192.168.2.186/edit; done
Starting ESP_FSWebServer_DRDusing LittleFS on ESP8266_NODEMCU_ESP12E with ESP8266_W5100 EthernetESP8266_W5100_Manager v1.0.0ESP_DoubleResetDetector v1.3.2Opening / directoryFS File: PM2_5_Log.csv, size: 40BFS File: drd.dat, size: 4BFS File: eth_cred.dat, size: 142BFS File: timezone.dat, size: 32B[EM] RFC925 Hostname = ESP-FSWebServerDRD[EM] setSTAStaticIPConfig[EM] Set CORS Header to : Your Access-Control-Allow-Origin[EM] LoadCfgFile [EM] OK[EM] stationIP =192.168.2.186 , gatewayIP =192.168.2.1[EM] netMask =255.255.255.0[EM] dns1IP =192.168.2.1 , dns2IP =8.8.8.8[EM] Default SPI pinout:[EM] MOSI:13[EM] MISO:12[EM] SCK:14[EM] CS:16[EM] =========================Connecting to network : Ethernet Static IP address:192.168.2.186LittleFS Flag read =0xD0D04321No doubleResetDetectedSaving config file...Saving config file OKAfter waiting0.00 secs more insetup(), connection result is connected. Local IP: 192.168.2.186HTTP server started @ 192.168.2.186===============================================================Open http://192.168.2.186/edit.htm to see the file browserUsing username = admin and password = admin===============================================================[EM] freeing allocated params!Stop doubleResetDetectingSaving config file...Saving config file OKhandleFileRead: /handleFileRead: /edit.htmhandleFileRead: /edit.htmhandleFileRead: /handleFileUpload Name: /CanadaFlag_1.pnghandleFileUpload Size: 41214handleFileUpload Name: /CanadaFlag_2.pnghandleFileUpload Size: 8311handleFileUpload Name: /CanadaFlag_3.jpghandleFileUpload Size: 11156handleFileUpload Name: /edit.htm.gzhandleFileUpload Size: 4116handleFileUpload Name: /favicon.icohandleFileUpload Size: 1150handleFileUpload Name: /graphs.js.gzhandleFileUpload Size: 1971handleFileUpload Name: /index.htmhandleFileUpload Size: 3721handleFileRead: /handleFileRead: /graphs.jshandleFileRead: /edit.htmhandleFileRead: /index.htmhandleFileList: /handleFileRead: /CanadaFlag_1.png
Then after restart, the uploaded files are shown in/
directory
Starting ESP_FSWebServer_DRD using LittleFS on ESP8266_NODEMCU_ESP12E with ESP8266_W5100 EthernetESP8266_W5100_Manager v1.0.0ESP_DoubleResetDetector v1.3.2Opening / directoryFS File: CanadaFlag_1.png, size: 40.25KBFS File: CanadaFlag_2.png, size: 8.12KBFS File: CanadaFlag_3.jpg, size: 10.89KBFS File: PM2_5_Log.csv, size: 40BFS File: drd.dat, size: 4BFS File: edit.htm.gz, size: 4.02KBFS File: eth_cred.dat, size: 142BFS File: favicon.ico, size: 1.12KBFS File: graphs.js.gz, size: 1.92KBFS File: index.htm, size: 3.63KBFS File: timezone.dat, size: 32B[EM] RFC925 Hostname = ESP-FSWebServerDRD[EM] setSTAStaticIPConfig[EM] Set CORS Header to : Your Access-Control-Allow-Origin[EM] LoadCfgFile [EM] OK[EM] stationIP = 192.168.2.186 , gatewayIP = 192.168.2.1[EM] netMask = 255.255.255.0[EM] dns1IP = 192.168.2.1 , dns2IP = 8.8.8.8[EM] Default SPI pinout:[EM] MOSI: 13[EM] MISO: 12[EM] SCK: 14[EM] CS: 16[EM] =========================Connecting to network : Ethernet Static IP address: 192.168.2.186LittleFS Flag read = 0xD0D04321No doubleResetDetectedSaving config file...Saving config file OKAfter waiting 0.00 secs more in setup(), connection result is connected. Local IP: 192.168.2.186HTTP server started @ 192.168.2.186===============================================================Open http://192.168.2.186/edit.htm to see the file browserUsing username = admin and password = admin===============================================================[EM] freeing allocated params!
Debug is enabled by default on Serial. To disable, add beforestartConfigPortal()
ESP8266_W5100_manager.setDebugOutput(false);
You can also change the debugging level from 0 to 4
// Use from 0 to 4. Higher number, more debugging messages and memory usage.#define_ESP8266_ETH_MGR_LOGLEVEL_3
If you get compilation errors, more often than not, you may need to install a newer version of theESP8266
core for Arduino.
Sometimes, the library will only work if you update theESP8266
core to the latest version because I am using some newly added function.
If you connect to the created configuration Access Point but the ConfigPortal does not show up, just open a browser and type in the IP of the web portal, by default192.168.2.186
.
Submit issues to:ESP8266_W5100_Manager issues
- Based on and modified fromTzapu,KenTaylor's version, and
Khoi Hoang's ESP_WiFiManager
.
![]() ⭐️ Tzapu | ![]() ⭐️ Ken Taylor |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed underMIT
Copyright 2022- Khoi Hoang
About
(ESP8266 + LwIP W5100 / W5100S) Connection and Credentials Manager, with enhanced GUI and fallback Web ConfigPortal. This Library is used for configuring (ESP8266 + LwIP W5100 / W5100S) Credentials Manager at runtime. You can also specify static DNS servers, personalized HostName, static or DHCP IP
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.