Merge branch 'ota' into dev-ota-updater

This commit is contained in:
Shawn A
2018-11-08 12:50:14 -06:00
committed by GitHub
30 changed files with 1747 additions and 669 deletions
+3
View File
@@ -7,3 +7,6 @@ Please test against development branch before submitting issues, issues against
PRs against master may be kept open if provides something useful to other members.
Please open issues before sumbitting PRs against development, as commits might be occuring very frequently.
### Documentation is in progress
https://github.com/tzapu/WiFiManager/issues/500
+5
View File
@@ -1,3 +1,6 @@
## PLEASE TRY DEVELOPMENT BRANCH before submitting bugs on release or master, in case they were already fixed. ##
Issues without basic info will be ignored or closed!
Please fill the info fields, it helps to get you faster support ;)
@@ -14,6 +17,8 @@ https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst
#### Hardware
WiFimanager Branch/Release: Development
Esp8266/Esp32:
Hardware: ESP-12e, esp01, esp25
Core Version: 2.4.0, staging
+2 -3
View File
@@ -13,7 +13,7 @@ before_install:
install:
- ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager
- arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
- arduino --install-library "ArduinoJson"
- arduino --install-library "ArduinoJson:5.13.2"
- arduino --install-boards esp8266:esp8266
- arduino --pref "compiler.warning_level=all" --save-prefs
# install esp32
@@ -38,8 +38,7 @@ script:
- build_examples
- arduino --board espressif:esp32:esp32doit-devkit-v1:FlashFreq=80,DebugLevel=info --save-prefs
# some examples fail (SPIFFS defines differ esp32 vs esp8266) so we exclude them
- excludes=("AutoConnectWithFSParametersAndCustomIP.ino" "AutoConnectWithFSParameters.ino")
- build_examples "${excludes[@]}"
- build_examples
# - arduino -v --verbose-build --verify $PWD/examples/AutoConnect/AutoConnect.ino
# no coverage generated, no need to run
+188 -59
View File
@@ -1,3 +1,5 @@
## Current development going on here :arrow_right: [Development Branch](https://github.com/tzapu/WiFiManager/tree/development)
# WiFiManager
ESP8266 WiFi Connection manager with fallback web configuration portal
@@ -14,12 +16,11 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
[https://github.com/esp8266/Arduino](https://github.com/esp8266/Arduino)
**This works with the ESP32 Arduino platform with staging , with caveats below**
**This works with the ESP32 Arduino platform with staging**
[https://github.com/espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
### Known Issues
* :exclamation: ESP32 must be patched with webserver library, see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513)
* Documentation needs to be updated, see [https://github.com/tzapu/WiFiManager/issues/500](https://github.com/tzapu/WiFiManager/issues/500)
## Contents
@@ -27,8 +28,9 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
- [Wishlist](#wishlist)
- [Quick start](#quick-start)
- Installing
- [Through Library Manager](#install-through-library-manager)
- [From Github](#checkout-from-github)
- [Arduino - Through Library Manager](#install-through-library-manager)
- [Arduino - From Github](#checkout-from-github)
- [PlatformIO]
- [Using](#using)
- [Documentation](#documentation)
- [Access Point Password](#password-protect-the-configuration-access-point)
@@ -45,12 +47,13 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
## How It Works
- when your ESP starts up, it sets it up in Station mode and tries to connect to a previously saved Access Point
- When your ESP starts up, it sets it up in Station mode and tries to connect to a previously saved Access Point
- if this is unsuccessful (or no previous network saved) it moves the ESP into Access Point mode and spins up a DNS and WebServer (default ip 192.168.4.1)
- using any wifi enabled device with a browser (computer, phone, tablet) connect to the newly created Access Point
- because of the Captive Portal and the DNS server you will either get a 'Join to network' type of popup or get any domain you try to access redirected to the configuration portal
- choose one of the access points scanned, enter password, click save
- ESP will try to connect. If successful, it relinquishes control back to your app. If not, reconnect to AP and reconfigure.
- There are options to change this behavior or manually start the configportal and webportal independantly as well as run them in non blocking mode.
## How It Looks
![ESP8266 WiFi Captive Portal Homepage](http://i.imgur.com/YPvW9eql.png) ![ESP8266 WiFi Captive Portal Configuration](http://i.imgur.com/oicWJ4gl.png)
@@ -66,9 +69,35 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
- [x] add to PlatformIO
- [ ] add multiple sets of network credentials
- [x] allow users to customize CSS
- [ ] ESP32 support or instructions
- [ ] rewrite documentation for simplicity, based on scenarios/goals
- [ ] rely on the SDK's built in auto connect more than forcing a connect
### Development
- [x] ESP32 support
- [x] rely on the SDK's built in auto connect more than forcing a connect
- [x] add non blocking mode
- [x] easy customization of strings
- [x] hostname support
- [x] fix various bugs and workarounds for esp SDK issues
- [x] additional info page items
- [x] last status display / faiilure reason
- [x] customizeable menu
- [x] seperate custom params page
- [x] ondemand webportal
- [x] complete refactor of code to segment functions
- [x] wiif scan icons or percentage display
- [x] invert class for dark mode
- [x] more template tokens
- [x] progmem for all strings
- [ ] new callbacks
- [ ] new callouts / filters
- [ ] shared web server instance
- [x] latest esp idf/sdk support
- [x] wm is now non persistent, will not erase or change stored esp config on esp8266
- [x] tons of debugging output / levels
- [ ] disable captiveportal
- [ ] preload wiifscans, faster page loads
- [ ] softap stability fixes when sta is not connected
## Quick Start
@@ -76,7 +105,7 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
You can either install through the Arduino Library Manager or checkout the latest changes or a release from github
#### Install through Library Manager
__Currently version 0.8+ works with release 2.0.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__
__Currently version 0.8+ works with release 2.4.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__
- in Arduino IDE got to Sketch/Include Library/Manage Libraries
![Manage Libraries](http://i.imgur.com/9BkEBkR.png)
@@ -86,20 +115,16 @@ __Currently version 0.8+ works with release 2.0.0 or newer of the [ESP8266 core
- click Install and start [using it](#using)
#### Checkout from github
__Github version works with release 2.0.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__
__Github version works with release 2.4.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__
- Checkout library to your Arduino libraries folder
### Using
- Include in your sketch
```cpp
#include <ESP8266WiFi.h> //ESP8266 Core WiFi Library (you most likely already have this in your sketch)
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
```
- Initialize library, in your setup function add
- Initialize library, in your setup function add, NOTEif you are using non blocking you will make sure you create this in global scope or handle appropriatly , it will not work if in setup and using non blocking mode.
```cpp
WiFiManager wifiManager;
```
@@ -239,7 +264,7 @@ wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddr
##### Custom Station (client) Static IP Configuration
This will make use the specified IP configuration instead of using DHCP in station mode.
```cpp
wifiManager.setSTAStaticIPConfig(IPAddress(192,168,0,99), IPAddress(192,168,0,1), IPAddress(255,255,255,0));
wifiManager.setSTAStaticIPConfig(IPAddress(192,168,0,99), IPAddress(192,168,0,1), IPAddress(255,255,255,0)); // optional DNS 4th argument
```
There are a couple of examples in the examples folder that show you how to set a static IP and even how to configure it through the web configuration portal.
@@ -251,7 +276,7 @@ You can use this to any html bit to the head of the configuration portal. If you
```cpp
wifiManager.setCustomHeadElement("<style>html{filter: invert(100%); -webkit-filter: invert(100%);}</style>");
```
- inject a custom bit of html in the configuration form
- inject a custom bit of html in the configuration/param form
```cpp
WiFiManagerParameter custom_text("<p>This is just a text paragraph</p>");
wifiManager.addParameter(&custom_text);
@@ -262,6 +287,14 @@ Just add the bit you want added as the last parameter to the custom parameter co
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "iot.eclipse", 40, " readonly");
```
#### Theming
You can customize certain elements of the default template with some builtin classes
```CPP
wifiManager.setClass("invert"); // dark theme
wifiManager.setScanDispPerc(true); // display percentages instead of graphs for RSSI
```
There are additional classes in the css you can use in your custom html , see the example template.
#### Filter Networks
You can filter networks based on signal quality and show/hide duplicate networks.
@@ -278,11 +311,24 @@ wifiManager.setRemoveDuplicateAPs(false);
```
#### Debug
Debug is enabled by default on Serial. To disable add before autoConnect
Debug is enabled by default on `Serial` in non-stable releases. To disable add before autoConnect/startConfigPortal
```cpp
wifiManager.setDebugOutput(false);
```
You can pass in a custom stream via constructor
```CPP
WiFiManager wifiManager(Serial1);
```
You can customize the debug level by changing `_debugLevel` in source
options are:
* DEBUG_ERROR
* DEBUG_NOTIFY
* DEBUG_VERBOSE
* DEBUG_DEV
* DEBUG_MAX
## Troubleshooting
If you get compilation errors, more often than not, you may need to install a newer version of the ESP8266 core for Arduino.
@@ -294,7 +340,122 @@ If you connect to the created configuration Access Point but the configuration p
If trying to connect ends up in an endless loop, try to add `setConnectTimeout(60)` before `autoConnect();`. The parameter is timeout to try connecting in seconds.
I get stuck in ap mode when the power goes out or modem resets, try a setConfigPortalTimeout(seconds). This will cause the configportal to close after no activity, and you can reboot or attempt reconnection in your code.
## Releases
### 1.0.1
### Development Overview
#### Added Public Methods
`setConfigPortalBlocking`
`setShowStaticFields`
`setCaptivePortalEnable`
`setRestorePersistent`
`setCaptivePortalClientCheck`
`setWebPortalClientCheck`
`startWebPortal`
`stopWebPortal`
`process`
`disconnect`
`erase`
` debugSoftAPConfig`
` debugPlatformInfo`
`setScanDispPerc`
`setHostname`
`setMenu(menu_page_t[])`
`setWiFiAutoReconnect`
` setSTAStaticIPConfig(..,dns)`
`setShowDnsFields`
`getLastConxResult`
`getWLStatusString`
`getModeString`
`getWiFiIsSaved`
`setShowInfoErase`
`setEnableConfigPortal`
`setCountry`
`setClass`
`htmleEtities`
#### WiFiManagerParameter
`WiFiManagerParameter(id,label)`
`WiFiManagerParameter.setValue(value,length)`
`getParameters`
`getParametersCount`
#### Constructors
`WiFiManager(Stream& consolePort)`
#### define flags
❗️ **Defines cannot be set in user sketches**
`#define WM_MDNS // use MDNS`
`#define WM_FIXERASECONFIG // use erase flash fix, esp8266 2.4.0`
`#define WM_ERASE_NVS // esp32 erase(true) will erase NVS`
`#include <rom/rtc.h> // esp32 info page will show last reset reasons if this file is included`
#### Changes Overview
- ESP32 support ( fairly stable )
- complete refactor of strings `strings_en.h`
- adds new tokens for wifiscan, and some classes (left , invert icons, MSG color)
- adds status callout panel default, primary, special colors
- adds tons of info on info page, and erase capability
- adds signal icons, replaces percentage ( has hover titles )
- adds labels to all inputs (replaces placeholders)
- all html ( and eventually all strings except debug) moved to `strings_en.h`
- added additional debugging, compressed debug lines, debuglevels
- persistent disabled, and restored via de/con-stuctor (uses `setRestorePersistent`)
- should retain all user modes including AP, should not overwrite or persist user modes or configs,even STA (`storeSTAmode`) (BUGGY)
- ⚠️ return values may have changed depending on portal abort, or timeout ( `portalTimeoutResult`,`portalAbortResult`)
- params memory is auto allocated by increment of `WIFI_MANAGER_MAX_PARAMS(5)` when exceeded, user no longer needs to specify this at all.
- addparameter now returns bool, and it returns false if param ID is not alphanum [0-9,A-Z,a-z,_]
- param field ids allow {I} token to use param_n instead of string in case someones wants to change this due to i18n or character issues
- provides `#DEFINE FIXERASECONFIG` to help deal with https://github.com/esp8266/Arduino/pull/3635
- failure reason reporting on portal
- set esp8266 sta hostname, esp32 sta+ap hostname ( DHCP client id)
- pass in debug stream in constructor WiFiManager(Stream& consolePort)
- you can force ip fields off with showxfields(false) if you set _disableIpFields=true
- param menu/page (setup) added to separate params from wifi page, handled automatically by setMenu
- set custom root menu
- disable configportal on autoconnect
- wm parameters init is now protected, allowing child classes, example included
- wifiscans are precached and async for faster page loads, refresh forces rescan
- adds esp32 gettemperature ( currently commented out, useful for relative measurement only )
#### 0.12
- removed 204 header response
- fixed incompatibility with other libs using isnan and other std:: functions without namespace
@@ -313,53 +474,20 @@ If trying to connect ends up in an endless loop, try to add `setConnectTimeout(6
- added an alternative to waitForConnectResult() for debugging
- changed `setTimeout(seconds)` to `setConfigPortalTimeout(seconds)`
##### 0.9
- fixed support for encoded characters in ssid/pass
##### 0.8
- made it compile on older versions of ESP8266 core as well, tested down to 2.0.0
- added simple example for Custom IP
##### 0.7
- added static IP in station mode
- added example of persisting custom IP to FS config.json
- more option on portal homepage
- added on PlatformIO
##### 0.6
- custom parameters
- prettier
- on demand config portal
- commit #100 :D
##### 0.5
- Added to Arduino Boards Manager - Thanks Max
- moved most stuff to PROGMEM
- added signal quality and a nice little padlock to show which networks are encrypted
##### v0.4 - all of it user contributed changes - Thank you
- added ability to password protect the configuration Access Point
- callback for enter configuration mode
- memory allocation improvements
##### v0.3
- removed the need for EEPROM and works with the 2.0.0 and above stable release of the ESP8266 for Arduino IDE package
- removed restart on save of credentials
- updated examples
##### v0.2
needs the latest staging version (or at least a recent release of the staging version) to work
##### v0.1
works with the staging release ver. 1.6.5-1044-g170995a, built on Aug 10, 2015 of the ESP8266 Arduino library.
### Contributions and thanks
The support and help I got from the community has been nothing short of phenomenal. I can't thank you guys enough. This is my first real attept in developing open source stuff and I must say, now I understand why people are so dedicated to it, it is because of all the wonderful people involved.
__THANK YOU__
[Shawn A](https://github.com/tablatronix)
The esp8266 and esp32 arduino and idf maintainers!
[Shawn A aka tablatronix](https://github.com/tablatronix)
[liebman](https://github.com/liebman)
[Evgeny Dontsov](https://github.com/dontsovcmc)
[Chris Marrin](https://github.com/cmarrin)
[bbx10](https://github.com/bbx10)
@@ -396,3 +524,4 @@ And countless others
* https://github.com/chriscook8/esp-arduino-apboot
* https://github.com/esp8266/Arduino/tree/master/libraries/DNSServer/examples/CaptivePortalAdvanced
* Built by AlexT https://github.com/tzapu
+512 -205
View File
File diff suppressed because it is too large Load Diff
+105 -33
View File
@@ -13,6 +13,10 @@
#ifndef WiFiManager_h
#define WiFiManager_h
#ifdef ESP8266
#include <core_version.h>
#endif
#include <vector>
// #define WM_MDNS // also set MDNS with sethostname
@@ -20,8 +24,16 @@
// #define WM_ERASE_NVS // esp32 erase(true) will erase NVS
// #define WM_RTC // esp32 info page will include reset reasons
#ifdef ARDUINO_ESP8266_RELEASE_2_3_0
#warning "ARDUINO_ESP8266_RELEASE_2_3_0, some WM features disabled"
#define WM_NOASYNC // esp8266 no async scan wifi
#endif
// #include "soc/efuse_reg.h" // include to add efuse chip rev to info, getChipRevision() is almost always the same though, so not sure why it matters.
// #define esp32autoreconnect // implement esp32 autoreconnect event listener kludge, @DEPRECATED
// autoreconnect is WORKING https://github.com/espressif/arduino-esp32/issues/653#issuecomment-405604766
#define WM_WEBSERVERSHIM // use webserver shim lib
#ifdef ESP8266
@@ -49,12 +61,11 @@
#define WM_WIFIOPEN WIFI_AUTH_OPEN
#ifndef WEBSERVER_H
#warning "WEBSERVER not implemented in espressif/esp32, see readme notes"
#ifdef WM_WEBSERVERSHIM
#include <WebServer.h>
#else
#include <ESP8266WebServer.h>
// Forthcoming official
// Forthcoming official ?
// https://github.com/esp8266/ESPWebServer
#endif
#endif
@@ -94,31 +105,35 @@ class WiFiManagerParameter {
Create custom parameters that can be added to the WiFiManager setup web page
@id is used for HTTP queries and must not contain spaces nor other special characters
*/
WiFiManagerParameter();
WiFiManagerParameter(const char *custom);
WiFiManagerParameter(const char *id, const char *placeholder);
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length);
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement);
WiFiManagerParameter(const char *id, const char *label);
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length);
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom);
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement);
~WiFiManagerParameter();
const char *getID();
const char *getValue();
const char *getPlaceholder();
const char *getLabel();
const char *getPlaceholder(); // @deprecated, use getLabel
int getValueLength();
int getLabelPlacement();
const char *getCustomHTML();
void setValue(const char *defaultValue, int length);
protected:
void init(const char *id, const char *label, const char *defaultValue, int length, const char *custom);
void init(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement);
private:
const char *_id;
const char *_placeholder;
const char *_label;
char *_value;
int _length;
int _labelPlacement;
const char *_customHTML;
void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement);
friend class WiFiManager;
};
@@ -138,6 +153,9 @@ class WiFiManager
//manually start the config portal, autoconnect does this automatically on connect failure
boolean startConfigPortal(); // auto generates apname
boolean startConfigPortal(char const *apName, char const *apPassword = NULL);
//manually stop the config portal if started manually, stop immediatly if non blocking, flag abort if blocking
bool stopConfigPortal();
//manually start the web portal, autoconnect does this automatically on connect failure
void startWebPortal();
@@ -159,9 +177,33 @@ class WiFiManager
bool erase();
bool erase(bool opt);
//adds a custom parameter, returns false on failure
bool addParameter(WiFiManagerParameter *p);
//returns the list of Parameters
WiFiManagerParameter** getParameters();
// returns the Parameters Count
int getParametersCount();
// SET CALLBACKS
//called after AP mode and config portal has started
void setAPCallback( std::function<void(WiFiManager*)> func );
//called after webserver has started
void setWebServerCallback( std::function<void()> func );
//called when settings reset have been triggered
void setConfigResetCallback( std::function<void()> func );
//called when wifi settings have been changed and connection was successful ( or setBreakAfterConfig(true) )
void setSaveConfigCallback( std::function<void()> func );
//called when settings have been changed and connection was successful
void setSaveParamsCallback( std::function<void()> func );
//called when settings before have been changed and connection was successful
void setPreSaveConfigCallback( std::function<void()> func );
//sets timeout before AP,webserver loop ends and exits even if there has been no setup.
//useful for devices that failed to connect at some point and got stuck in a webserver loop
//in seconds setConfigPortalTimeout is a new name for setTimeout
//in seconds setConfigPortalTimeout is a new name for setTimeout, ! not used if setConfigPortalBlocking
void setConfigPortalTimeout(unsigned long seconds);
void setTimeout(unsigned long seconds); // @deprecated, alias
@@ -171,7 +213,7 @@ class WiFiManager
void setSaveConnectTimeout(unsigned long seconds);
// toggle debug output
void setDebugOutput(boolean debug);
//defaults to not showing anything under 8% signal quality if called
//set min quality percentage to include in scan, defaults to 8% if not specified
void setMinimumSignalQuality(int quality = 8);
//sets a custom ip /gateway /subnet configuration
void setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
@@ -179,15 +221,11 @@ class WiFiManager
void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
//sets config for a static IP with DNS
void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns);
//called when AP mode and config portal is started
void setAPCallback( void (*func)(WiFiManager*) );
//called when settings have been changed and connection was successful
void setSaveConfigCallback( void (*func)(void) );
//adds a custom parameter, returns false on failure
bool addParameter(WiFiManagerParameter *p);
//if this is set, it will exit after config, even if connection is unsuccessful.
void setBreakAfterConfig(boolean shouldBreak);
//if this is set, portal will be blocking and wait until save or exit, is false user must manually `process()` to handle config portal
// if this is set, portal will be blocking and wait until save or exit,
// is false user must manually `process()` to handle config portal,
// setConfigPortalTimeout is ignored in this mode, user is responsible for closing configportal
void setConfigPortalBlocking(boolean shouldBlock);
//if this is set, customise style
void setCustomHeadElement(const char* element);
@@ -201,8 +239,8 @@ class WiFiManager
void setShowDnsFields(boolean alwaysShow);
//if false, disable captive portal redirection
void setCaptivePortalEnable(boolean enabled);
//if false, timeout captive portal even if a STA client connected (false), suggest disabling if captiveportal is open
void setCaptivePortalClientCheck(boolean enabled);
//if false, timeout captive portal even if a STA client connected to softAP (false), suggest disabling if captiveportal is open
void setAPClientCheck(boolean enabled);
//if true, reset timeout when webclient connects (true), suggest disabling if captiveportal is open
void setWebPortalClientCheck(boolean enabled);
// if true, enable autoreconnecting
@@ -234,8 +272,12 @@ class WiFiManager
// debug output platform info and versioning
void debugPlatformInfo();
String htmlEntities(String str);
// set the country code for wifi settings
void setCountry(String cc);
// set body class (invert)
void setClass(String str);
private:
std::unique_ptr<DNSServer> dnsServer;
#if defined(ESP32) && defined(WM_WEBSERVERSHIM)
@@ -243,8 +285,10 @@ class WiFiManager
#else
using WM_WebServer = ESP8266WebServer;
#endif
std::unique_ptr<WM_WebServer> server;
std::unique_ptr<WM_WebServer> server;
private:
std::vector<uint8_t> _menuIds;
std::vector<const char *> _menuIdsDefault = {"wifi","info","exit"};
@@ -275,8 +319,14 @@ class WiFiManager
String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid
uint8_t _lastconxresult = WL_IDLE_STATUS;
int _numNetworks = 0;
unsigned long _lastscan = 0; // ms
unsigned long _lastscan = 0; // ms for timing wifi scans
unsigned long _startscan = 0; // ms for timing wifi scans
int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast.
bool _cleanConnect = true; // disconnect before connect in connectwifi, increases stability on connects
bool _disableSTA = false; // disable sta when starting ap, always
bool _disableSTAConn = true; // disable sta when starting ap, if sta is not connected ( stability )
bool _channelSync = false; // use wifi channel when starting ap
#ifdef ESP32
static uint8_t _lastconxresulttmp; // tmp var for esp32 callback
@@ -292,12 +342,11 @@ class WiFiManager
int _staShowDns = 0; // ternary always show dns, only if not set in code, never(cannot change dns via web!)
boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan
boolean _shouldBreakAfterConfig = false; // stop configportal on save failure
boolean _tryWPS = false; // try WPS on save failure, unsupported
boolean _configPortalIsBlocking = true; // configportal enters blocking loop
boolean _enableCaptivePortal = true; // enable captive portal redirection
boolean _userpersistent = true; // users preffered persistence to restore
boolean _wifiAutoReconnect = true; // there is no platform getter for this, we must assume its true and make it so
boolean _cpClientCheck = false; // keep cp alive if cp have station
boolean _apClientCheck = false; // keep cp alive if ap have station
boolean _webClientCheck = true; // keep cp alive if web have client
boolean _scanDispOptions = false; // show percentage in scans not icons
boolean _paramsInWifi = true; // show custom parameters on wifi page
@@ -306,13 +355,28 @@ class WiFiManager
const char * _hostname = "";
const char* _customHeadElement = ""; // store custom head element html from user
String _bodyClass = ""; // class to add to body
// internal options
boolean _preloadwifiscan = true; // preload wifiscan if true
boolean _disableIpFields = false; // edge case, if true, showxFields(false) forces ip fields off instead of default show when set
String _wificountry = ""; // country code, @todo define in strings lang
// wrapper functions for handling setting and unsetting persistent for now.
bool esp32persistent = false;
bool _hasBegun = false;
void _begin();
void _end();
void setupConfigPortal();
bool shutdownConfigPortal();
#ifdef NO_EXTRA_4K_HEAP
boolean _tryWPS = false; // try WPS on save failure, unsupported
void startWPS();
#endif
bool startAP();
uint8_t connectWifi(String ssid, String pass);
@@ -343,7 +407,6 @@ class WiFiManager
boolean captivePortal();
boolean configPortalHasTimeout();
boolean stopConfigPortal();
uint8_t processConfigPortal();
void stopCaptivePortal();
// OTA Update handler
@@ -364,11 +427,14 @@ class WiFiManager
void WiFi_autoReconnect();
String WiFi_SSID();
bool WiFi_scanNetworks();
bool WiFi_scanNetworks(bool force);
bool WiFi_scanNetworks(bool force,bool async);
bool WiFi_scanNetworks(unsigned int cachetime,bool async);
bool WiFi_scanNetworks(unsigned int cachetime);
void WiFi_scanComplete(int networksFound);
bool WiFiSetCountry();
#ifdef ESP32
static void WiFiEvent(WiFiEvent_t event, system_event_info_t info);
void WiFiEvent(WiFiEvent_t event, system_event_info_t info);
#endif
// output helpers
@@ -413,11 +479,12 @@ class WiFiManager
} wm_debuglevel_t;
boolean _debug = true;
uint8_t _debugLevel = DEBUG_VERBOSE;
uint8_t _debugLevel = DEBUG_DEV;
Stream& _debugPort; // debug output stream ref
template <typename Generic>
void DEBUG_WM(Generic text);
template <typename Generic>
void DEBUG_WM(wm_debuglevel_t level,Generic text);
template <typename Generic, typename Genericb>
@@ -426,8 +493,13 @@ class WiFiManager
void DEBUG_WM(wm_debuglevel_t level, Generic text,Genericb textb);
// callbacks
void (*_apcallback)(WiFiManager*) = NULL;
void (*_savecallback)(void) = NULL;
// @todo use cb list (vector) maybe event ids, allow no return value
std::function<void(WiFiManager*)> _apcallback;
std::function<void()> _webservercallback;
std::function<void()> _savewificallback;
std::function<void()> _presavecallback;
std::function<void()> _saveparamscallback;
std::function<void()> _resetcallback;
template <class T>
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
+133
View File
@@ -0,0 +1,133 @@
/**
* WiFiManager advanced demo, contains advanced configurartion options
* Implements TRIGGEN_PIN button press, press for ondemand configportal, hold for 3 seconds for reset settings.
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#define TRIGGER_PIN 0
WiFiManager wm; // global wm instance
WiFiManagerParameter custom_field; // global param ( for non blocking w params )
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
delay(3000);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT);
// wm.resetSettings(); // wipe settings
// add a custom input field
int customFieldLength = 40;
// new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder=\"Custom Field Placeholder\"");
// test custom html input type(checkbox)
// new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder=\"Custom Field Placeholder\" type=\"checkbox\""); // custom html type
// test custom html(radio)
const char* custom_radio_str = "<br/><label for='customfieldid'>Custom Field Label</label><input type='radio' name='customfieldid' value='1' checked> One<br><input type='radio' name='customfieldid' value='2'> Two<br><input type='radio' name='customfieldid' value='3'> Three";
new (&custom_field) WiFiManagerParameter(custom_radio_str); // custom html input
wm.addParameter(&custom_field);
wm.setSaveParamsCallback(saveParamCallback);
// custom menu via array or vector
//
// menu tokens, "wifi","wifinoscan","info","param","close","sep","erase","restart","exit" (sep is seperator) (if param is in menu, params will not show up in wifi page!)
// const char* menu[] = {"wifi","info","param","sep","restart","exit"};
// wm.setMenu(menu,6);
std::vector<const char *> menu = {"wifi","info","param","sep","restart","exit"};
wm.setMenu(menu);
// set dark theme
wm.setClass("invert");
//set static ip
// wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // set static ip,gw,sn
// wm.setShowStaticFields(true); // force show static ip fields
// wm.setShowDnsFields(true); // force show dns field always
// wm.setConnectTimeout(20); // how long to try to connect for before continuing
wm.setConfigPortalTimeout(30); // auto close configportal after n seconds
// wm.setCaptivePortalEnable(false); // disable captive portal redirection
// wm.setAPClientCheck(true); // avoid timeout if client connected to softap
// wifi scan settings
// wm.setRemoveDuplicateAPs(false); // do not remove duplicate ap names (true)
// wm.setMinimumSignalQuality(20); // set min RSSI (percentage) to show in scans, null = 8%
// wm.setShowInfoErase(false); // do not show erase button on info page
// wm.setScanDispPerc(true); // show RSSI as percentage not graph icons
// wm.setBreakAfterConfig(true); // always exit configportal even if wifi save fails
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
if(!res) {
Serial.println("Failed to connect or hit timeout");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
void checkButton(){
// check for button press
if ( digitalRead(TRIGGER_PIN) == LOW ) {
// poor mans debounce/press-hold, code not ideal for production
delay(50);
if( digitalRead(TRIGGER_PIN) == LOW ){
Serial.println("Button Pressed");
// still holding button for 3000 ms, reset settings, code not ideaa for production
delay(3000); // reset delay hold
if( digitalRead(TRIGGER_PIN) == LOW ){
Serial.println("Button Held");
Serial.println("Erasing Config, restarting");
wm.resetSettings();
ESP.restart();
}
// start portal w delay
Serial.println("Starting config portal");
wm.setConfigPortalTimeout(120);
if (!wm.startConfigPortal("OnDemandAP","password")) {
Serial.println("failed to connect or hit timeout");
delay(3000);
// ESP.restart();
} else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
}
}
String getParam(String name){
//read parameter from server, for customhmtl input
String value;
if(wm.server->hasArg(name)) {
value = wm.server->arg(name);
}
return value;
}
void saveParamCallback(){
Serial.println("[CALLBACK] saveParamCallback fired");
Serial.println("PARAM customfieldid = " + getParam("customfieldid"));
}
void loop() {
checkButton();
// put your main code here, to run repeatedly:
}
-32
View File
@@ -1,32 +0,0 @@
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//reset saved settings
//wifiManager.resetSettings();
//set custom ip for portal
//wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
//fetches ssid and pass from eeprom and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
wifiManager.autoConnect("AutoConnectAP");
//or use this for auto generated name ESP + ChipID
//wifiManager.autoConnect();
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
void loop() {
// put your main code here, to run repeatedly:
}
@@ -8,8 +8,13 @@
//define your default values here, if there are different values in config.json, they are overwritten.
char mqtt_server[40];
char mqtt_port[6] = "8080";
char blynk_token[34] = "YOUR_BLYNK_TOKEN";
char mqtt_port[6] = "8080";
char api_token[32] = "YOUR_API_TOKEN";
//default custom static IP
char static_ip[16] = "10.0.1.56";
char static_gw[16] = "10.0.1.1";
char static_sn[16] = "255.255.255.0";
//flag for saving data
bool shouldSaveConfig = false;
@@ -20,14 +25,9 @@ void saveConfigCallback () {
shouldSaveConfig = true;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
void setupSpiffs(){
//clean FS, for testing
//SPIFFS.format();
// SPIFFS.format();
//read configuration from FS json
Serial.println("mounting FS...");
@@ -53,7 +53,17 @@ void setup() {
strcpy(mqtt_server, json["mqtt_server"]);
strcpy(mqtt_port, json["mqtt_port"]);
strcpy(blynk_token, json["blynk_token"]);
strcpy(api_token, json["api_token"]);
// if(json["ip"]) {
// Serial.println("setting custom ip from config");
// strcpy(static_ip, json["ip"]);
// strcpy(static_gw, json["gateway"]);
// strcpy(static_sn, json["subnet"]);
// Serial.println(static_ip);
// } else {
// Serial.println("no custom ip in config");
// }
} else {
Serial.println("failed to load json config");
@@ -64,62 +74,68 @@ void setup() {
Serial.println("failed to mount FS");
}
//end read
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
setupSpiffs();
// WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wm;
//set config save notify callback
wm.setSaveConfigCallback(saveConfigCallback);
// setup custom parameters
//
// The extra parameters to be configured (can be either global or just in the setup)
// After connecting, parameter.getValue() will get you the configured value
// id/name placeholder/prompt default length
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
WiFiManagerParameter custom_blynk_token("blynk", "blynk token", "", 0);
WiFiManagerParameter custom_api_token("api", "api token", "", 32);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//set config save notify callback
wifiManager.setSaveConfigCallback(saveConfigCallback);
//set static ip
wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
//add all your parameters here
wifiManager.addParameter(&custom_mqtt_server);
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_blynk_token);
wm.addParameter(&custom_mqtt_server);
wm.addParameter(&custom_mqtt_port);
wm.addParameter(&custom_api_token);
//reset settings - for testing
//wifiManager.resetSettings();
// set static ip
// IPAddress _ip,_gw,_sn;
// _ip.fromString(static_ip);
// _gw.fromString(static_gw);
// _sn.fromString(static_sn);
// wm.setSTAStaticIPConfig(_ip, _gw, _sn);
//set minimu quality of signal so it ignores AP's under that quality
//defaults to 8%
//wifiManager.setMinimumSignalQuality();
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
//wifiManager.setConfigPortalTimeout(120);
//reset settings - wipe credentials for testing
//wm.resetSettings();
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//automatically connect using saved credentials if they exist
//If connection fails it starts an access point with the specified name
//here "AutoConnectAP" if empty will auto generate basedcon chipid, if password is blank it will be anonymous
//and goes into a blocking loop awaiting configuration
if (!wifiManager.autoConnect("AutoConnectAP", "password")) {
if (!wm.autoConnect("AutoConnectAP", "password")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
// if we still have not connected restart and try all over again
ESP.restart();
delay(5000);
}
// always start configportal for a little while
// wm.setConfigPortalTimeout(60);
// wm.startConfigPortal("AutoConnectAP","password");
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
//read updated parameters
strcpy(mqtt_server, custom_mqtt_server.getValue());
strcpy(mqtt_port, custom_mqtt_port.getValue());
strcpy(blynk_token, custom_blynk_token.getValue());
strcpy(api_token, custom_api_token.getValue());
//save the custom parameters to FS
if (shouldSaveConfig) {
@@ -127,23 +143,29 @@ void setup() {
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["mqtt_server"] = mqtt_server;
json["mqtt_port"] = mqtt_port;
json["blynk_token"] = blynk_token;
json["mqtt_port"] = mqtt_port;
json["api_token"] = api_token;
// json["ip"] = WiFi.localIP().toString();
// json["gateway"] = WiFi.gatewayIP().toString();
// json["subnet"] = WiFi.subnetMask().toString();
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
Serial.println("failed to open config file for writing");
}
json.printTo(Serial);
json.prettyPrintTo(Serial);
json.printTo(configFile);
configFile.close();
//end save
shouldSaveConfig = false;
}
Serial.println("local ip");
Serial.println(WiFi.localIP());
Serial.println(WiFi.gatewayIP());
Serial.println(WiFi.subnetMask());
}
void loop() {
@@ -7,10 +7,10 @@
#endif
//define your default values here, if there are different values in config.json, they are overwritten.
//length should be max size + 1
char mqtt_server[40];
char mqtt_port[6] = "8080";
char blynk_token[33] = "YOUR_BLYNK_TOKEN";
char mqtt_port[6] = "8080";
char api_token[32] = "YOUR_API_TOKEN";
//default custom static IP
char static_ip[16] = "10.0.1.56";
char static_gw[16] = "10.0.1.1";
@@ -25,13 +25,9 @@ void saveConfigCallback () {
shouldSaveConfig = true;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
void setupSpiffs(){
//clean FS, for testing
//SPIFFS.format();
// SPIFFS.format();
//read configuration from FS json
Serial.println("mounting FS...");
@@ -57,24 +53,18 @@ void setup() {
strcpy(mqtt_server, json["mqtt_server"]);
strcpy(mqtt_port, json["mqtt_port"]);
strcpy(blynk_token, json["blynk_token"]);
strcpy(api_token, json["api_token"]);
if(json["ip"]) {
Serial.println("setting custom ip from config");
//static_ip = json["ip"];
strcpy(static_ip, json["ip"]);
strcpy(static_gw, json["gateway"]);
strcpy(static_sn, json["subnet"]);
//strcat(static_ip, json["ip"]);
//static_gw = json["gateway"];
//static_sn = json["subnet"];
Serial.println(static_ip);
/* Serial.println("converting ip");
IPAddress ip = ipFromCharArray(static_ip);
Serial.println(ip);*/
} else {
Serial.println("no custom ip in config");
}
} else {
Serial.println("failed to load json config");
}
@@ -84,58 +74,53 @@ void setup() {
Serial.println("failed to mount FS");
}
//end read
Serial.println(static_ip);
Serial.println(blynk_token);
Serial.println(mqtt_server);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
setupSpiffs();
// WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wm;
//set config save notify callback
wm.setSaveConfigCallback(saveConfigCallback);
// setup custom parameters
//
// The extra parameters to be configured (can be either global or just in the setup)
// After connecting, parameter.getValue() will get you the configured value
// id/name placeholder/prompt default length
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 5);
WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 34);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
WiFiManagerParameter custom_api_token("api", "api token", "", 32);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//add all your parameters here
wm.addParameter(&custom_mqtt_server);
wm.addParameter(&custom_mqtt_port);
wm.addParameter(&custom_api_token);
//set config save notify callback
wifiManager.setSaveConfigCallback(saveConfigCallback);
//set static ip
// set static ip
IPAddress _ip,_gw,_sn;
_ip.fromString(static_ip);
_gw.fromString(static_gw);
_sn.fromString(static_sn);
wm.setSTAStaticIPConfig(_ip, _gw, _sn);
wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);
//add all your parameters here
wifiManager.addParameter(&custom_mqtt_server);
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_blynk_token);
//reset settings - wipe credentials for testing
//wm.resetSettings();
//reset settings - for testing
//wifiManager.resetSettings();
//set minimu quality of signal so it ignores AP's under that quality
//defaults to 8%
wifiManager.setMinimumSignalQuality();
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
//wifiManager.setConfigPortalTimeout(120);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//automatically connect using saved credentials if they exist
//If connection fails it starts an access point with the specified name
//here "AutoConnectAP" if empty will auto generate basedcon chipid, if password is blank it will be anonymous
//and goes into a blocking loop awaiting configuration
if (!wifiManager.autoConnect("AutoConnectAP", "password")) {
if (!wm.autoConnect("AutoConnectAP", "password")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
// if we still have not connected restart and try all over again
ESP.restart();
delay(5000);
}
@@ -146,7 +131,7 @@ void setup() {
//read updated parameters
strcpy(mqtt_server, custom_mqtt_server.getValue());
strcpy(mqtt_port, custom_mqtt_port.getValue());
strcpy(blynk_token, custom_blynk_token.getValue());
strcpy(api_token, custom_api_token.getValue());
//save the custom parameters to FS
if (shouldSaveConfig) {
@@ -154,12 +139,12 @@ void setup() {
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
json["mqtt_server"] = mqtt_server;
json["mqtt_port"] = mqtt_port;
json["blynk_token"] = blynk_token;
json["mqtt_port"] = mqtt_port;
json["api_token"] = api_token;
json["ip"] = WiFi.localIP().toString();
json["gateway"] = WiFi.gatewayIP().toString();
json["subnet"] = WiFi.subnetMask().toString();
json["ip"] = WiFi.localIP().toString();
json["gateway"] = WiFi.gatewayIP().toString();
json["subnet"] = WiFi.subnetMask().toString();
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
@@ -170,6 +155,7 @@ void setup() {
json.printTo(configFile);
configFile.close();
//end save
shouldSaveConfig = false;
}
Serial.println("local ip");
@@ -1,14 +1,16 @@
// LED will blink when in config mode
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
//for LED status
#include <Ticker.h>
Ticker ticker;
int LED = BUILTIN_LED;
void tick()
{
//toggle state
int state = digitalRead(BUILTIN_LED); // get the current state of GPIO1 pin
digitalWrite(BUILTIN_LED, !state); // set pin to the opposite state
digitalWrite(LED, !digitalRead(LED)); // set pin to the opposite state
}
//gets called when WiFiManager enters configuration mode
@@ -26,24 +28,24 @@ void setup() {
Serial.begin(115200);
//set led pin as output
pinMode(BUILTIN_LED, OUTPUT);
pinMode(LED, OUTPUT);
// start ticker with 0.5 because we start in AP mode and try to connect
ticker.attach(0.6, tick);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
WiFiManager wm;
//reset settings - for testing
//wifiManager.resetSettings();
// wm.resetSettings();
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wifiManager.setAPCallback(configModeCallback);
wm.setAPCallback(configModeCallback);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
if (!wifiManager.autoConnect()) {
if (!wm.autoConnect()) {
Serial.println("failed to connect and hit timeout");
//reset and try again, or maybe put it to deep sleep
ESP.restart();
@@ -54,7 +56,7 @@ void setup() {
Serial.println("connected...yeey :)");
ticker.detach();
//keep LED on
digitalWrite(BUILTIN_LED, LOW);
digitalWrite(LED, LOW);
}
void loop() {
@@ -1,18 +0,0 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:nodemcuv2]
platform=espressif8266
board=nodemcuv2
framework=arduino
[platformio]
src_dir=AutoConnectWithTimeout
lib_dir=/Users/shawn/projects/microcontrollers/dev/libraries
+37
View File
@@ -0,0 +1,37 @@
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wm;
//reset settings - wipe credentials for testing
//wm.resetSettings();
// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
if(!res) {
Serial.println("Failed to connect");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
@@ -0,0 +1,208 @@
/**
* This is a kind of unit test for DEV for now
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <time.h>
#define TRIGGER_PIN 0
const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };
WiFiManager wm;
bool TEST_CP = false; // always start the configportal
bool TEST_NET = true; // do a network test, get ntp time
char ssid[] = "*************"; // your network SSID (name)
char pass[] = "********"; // your network password
void saveWifiCallback(){
Serial.println("[CALLBACK] saveCallback fired");
}
//gets called when WiFiManager enters configuration mode
void configModeCallback (WiFiManager *myWiFiManager) {
Serial.println("[CALLBACK] configModeCallback fired");
// myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
// Serial.println(WiFi.softAPIP());
//if you used auto generated SSID, print it
// Serial.println(myWiFiManager->getConfigPortalSSID());
}
void saveParamCallback(){
Serial.println("[CALLBACK] saveParamCallback fired");
// wm.stopConfigPortal();
}
void bindServerCallback(){
wm.server->on("/custom",handleRoute);
// wm.server->on("/info",handleRoute); // can override wm!
}
void handleRoute(){
Serial.println("[HTTP] handle route");
wm.server->send(200, "text/plain", "hello from user code");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.setDebugOutput(true);
// delay(3000);
Serial.println("\n Starting");
// WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability
wm.debugPlatformInfo();
//Local intialization. Once its business is done, there is no need to keep it around
//reset settings - for testing
// wm.resetSettings();
// wm.erase();
wm.setClass("invert");
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
// wm.setConfigPortalTimeout(600);
// wm.setConnectTimeout(5);
// wm.setShowStaticFields(true);
WiFiManagerParameter custom_html("<p>This Is Custom HTML</p>"); // only custom html
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6);
WiFiManagerParameter custom_token("api_token", "api token", "", 16);
WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); // id is invalid, cannot contain spaces
WiFiManagerParameter custom_ipaddress("input_ip", "input IP", "", 15,"pattern='\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}'"); // custom input attrs (ip mask)
// callbacks
wm.setAPCallback(configModeCallback);
wm.setWebServerCallback(bindServerCallback);
wm.setSaveConfigCallback(saveWifiCallback);
wm.setSaveParamsCallback(saveParamCallback);
//add all your parameters here
wm.addParameter(&custom_html);
wm.addParameter(&custom_mqtt_server);
wm.addParameter(&custom_mqtt_port);
wm.addParameter(&custom_token);
wm.addParameter(&custom_tokenb);
wm.addParameter(&custom_ipaddress);
custom_html.setValue("test",4);
custom_token.setValue("test",4);
// Set cutom menu via menu[] or vector
// const char* menu[] = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
// wm.setMenu(menu,9); // custom menu array must provide length
std::vector<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
wm.setMenu(menu); // custom menu, pass vector
// set static sta ip
// wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
// wm.setShowStaticFields(false);
// wm.setShowDnsFields(false);
// set static ip
// wm.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
// wm.setAPStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
// WiFi.mode(WIFI_STA);
// const wifi_country_t COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO};
// const wifi_country_t COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO};
// const wifi_country_t COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO};
// esp_wifi_set_country(&COUNTRY_US);
// wm.setCountry("US");
wm.setConfigPortalTimeout(120);
// wm.startConfigPortal("AutoConnectAP", "password");
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
if(!wm.autoConnect("AutoConnectAP")) {
Serial.println("failed to connect and hit timeout");
}
else if(TEST_CP) {
// start configportal always
wm.setConfigPortalTimeout(60);
wm.startConfigPortal();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
pinMode(TRIGGER_PIN, INPUT);
}
void loop() {
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW ) {
Serial.println("BUTTON PRESSED");
wm.setConfigPortalTimeout(120);
// disable captive portal redirection
// wm.setCaptivePortalEnable(false);
if (!wm.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
} else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
getTime();
}
}
if(WiFi.status() == WL_CONNECTED) getTime();
// put your main code here, to run repeatedly:
delay(5000);
}
void getTime() {
int tz = -5;
int dst = 0;
time_t now = time(nullptr);
unsigned timeout = 5000;
unsigned start = millis();
configTime(tz * 3600, dst * 3600, "pool.ntp.org", "time.nist.gov");
Serial.print("Waiting for NTP time sync: ");
while (now < 8 * 3600 * 2 ) {
delay(100);
Serial.print(".");
now = time(nullptr);
if((millis() - start) > timeout){
Serial.println("[ERROR] Failed to get NTP time.");
return;
}
}
Serial.println("");
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
Serial.print("Current time: ");
Serial.print(asctime(&timeinfo));
}
void debugchipid(){
// WiFi.mode(WIFI_STA);
// WiFi.printDiag(Serial);
// Serial.println(modes[WiFi.getMode()]);
// ESP.eraseConfig();
// wm.resetSettings();
// wm.erase(true);
WiFi.mode(WIFI_AP);
// WiFi.softAP();
WiFi.enableAP(true);
delay(500);
// esp_wifi_start();
delay(1000);
WiFi.printDiag(Serial);
delay(60000);
ESP.restart();
// AP esp_267751
// 507726A4AE30
// ESP32 Chip ID = 507726A4AE30
}
@@ -0,0 +1,26 @@
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
WiFiManager wm;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//reset settings - wipe credentials for testing
//wm.resetSettings();
wm.setConfigPortalBlocking(false);
//automatically connect using saved credentials if they exist
//If connection fails it starts an access point with the specified name
if(wm.autoConnect("AutoConnectAP")){
Serial.println("connected...yeey :)");
}
else {
Serial.println("Configportal running");
}
}
void loop() {
wm.process();
// put your main code here, to run repeatedly:
}
@@ -0,0 +1,35 @@
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
WiFiManager wm;
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//reset settings - wipe credentials for testing
//wm.resetSettings();
wm.addParameter(&custom_mqtt_server);
wm.setConfigPortalBlocking(false);
wm.setSaveParamsCallback(saveParamsCallback);
//automatically connect using saved credentials if they exist
//If connection fails it starts an access point with the specified name
if(wm.autoConnect("AutoConnectAP")){
Serial.println("connected...yeey :)");
}
else {
Serial.println("Configportal running");
}
}
void loop() {
wm.process();
// put your main code here, to run repeatedly:
}
void saveParamsCallback () {
Serial.println("Get Params:");
Serial.print(custom_mqtt_server.getID());
Serial.print(" : ");
Serial.println(custom_mqtt_server.getValue());
}
@@ -0,0 +1,63 @@
/**
* OnDemandNonBlocking.ino
* example of running the webportal or configportal manually and non blocking
* trigger pin will start a webportal for 120 seconds then turn it off.
* startCP = true will start both the configportal AP and webportal
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0
WiFiManager wm;
unsigned int timeout = 120; // seconds to run for
unsigned int startTime = millis();
bool portalRunning = false;
bool startCP = false; // start AP and webserver if true, else start only webserver
void setup() {
// put your setup code here, to run once
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
void loop() {
doWiFiManager();
// put your main code here, to run repeatedly:
}
void doWiFiManager(){
// is auto timeout portal running
if(portalRunning){
wm.process();
if((millis()-startTime) > (timeout*1000)){
Serial.println("portaltimeout");
portalRunning = false;
if(startCP){
wm.stopConfigPortal();
}
else{
wm.stopWebPortal();
}
}
}
// is configuration portal requested?
if(digitalRead(TRIGGER_PIN) == LOW && (!portalRunning)) {
if(startCP){
Serial.println("Button Pressed, Starting Config Portal");
wm.setConfigPortalBlocking(false);
wm.startConfigPortal();
}
else{
Serial.println("Button Pressed, Starting Web Portal");
wm.startWebPortal();
}
portalRunning = true;
startTime = millis();
}
}
@@ -0,0 +1,46 @@
/**
* OnDemandConfigPortal.ino
* example of running the configPortal AP manually, independantly from the captiveportal
* trigger pin will start a configPortal AP for 120 seconds then turn it off.
*
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0
int timeout = 120; // seconds to run for
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
void loop() {
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW) {
WiFiManager wm;
//reset settings - for testing
//wifiManager.resetSettings();
// set configportal timeout
wm.setConfigPortalTimeout(timeout);
if (!wm.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(5000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
// put your main code here, to run repeatedly:
}
@@ -0,0 +1,50 @@
/**
* OnDemandWebPortal.ino
* example of running the webportal (always NON blocking)
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0
WiFiManager wm;
bool portalRunning = false;
void setup() {
// put your setup code here, to run once
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
void loop() {
checkButton();
// put your main code here, to run repeatedly:
}
void checkButton(){
// is auto timeout portal running
if(portalRunning){
wm.process();
}
// is configuration portal requested?
if(digitalRead(TRIGGER_PIN) == LOW) {
delay(50);
if(digitalRead(TRIGGER_PIN) == LOW) {
if(!portalRunning){
Serial.println("Button Pressed, Starting Portal");
wm.startWebPortal();
portalRunning = true;
}
else{
Serial.println("Button Pressed, Stopping Portal");
wm.startWebPortal();
portalRunning = false;
}
}
}
}
@@ -1,125 +0,0 @@
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
// select which pin will trigger the configuration portal when set to LOW
// ESP-01 users please note: the only pins available (0 and 2), are shared
// with the bootloader, so always set them HIGH at power-up
#define TRIGGER_PIN 0
const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };
WiFiManager wifiManager;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.setDebugOutput(true);
delay(3000);
Serial.println("\n Starting");
// Serial.println(modes[WiFi.getMode()]);
// WiFi.printDiag(Serial);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//Local intialization. Once its business is done, there is no need to keep it around
//reset settings - for testing
//wifiManager.resetSettings();
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
wifiManager.setConfigPortalTimeout(20);
wifiManager.setConnectTimeout(10);
// wifiManager.setShowStaticFields(true);
// uint8_t menu[] = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE};
// wifiManager.setMenu(menu);
// std::vector<WiFiManager::menu_page_t> menu = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE,wifiManager.MENU_SEP,wifiManager.MENU_ERASE,wifiManager.MENU_EXIT};
// wifiManager.setMenu(menu);
// std::vector<WiFiManager::menu_page_t> menu = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE,wifiManager.MENU_SEP,wifiManager.MENU_ERASE,wifiManager.MENU_EXIT};
// wifiManager.setMenu(menu);
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6);
WiFiManagerParameter custom_token("api_token", "api token", "", 0);
WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0);
//add all your parameters here
wifiManager.addParameter(&custom_mqtt_server);
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_token);
wifiManager.addParameter(&custom_tokenb);
// MENU_WIFI = 0,
// MENU_WIFINOSCAN = 1,
// MENU_INFO = 2,
// MENU_PARAM = 3,
// MENU_CLOSE = 4,
// MENU_RESTART = 5,
// MENU_EXIT = 6,
// MENU_ERASE = 7,
// MENU_SEP = 8
// const char* menu[] = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
// wifiManager.setMenu(menu,9);
std::vector<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
wifiManager.setMenu(menu);
//set static ip
wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
// wifiManager.setShowStaticFields(false);
// wifiManager.setShowDnsFields(false);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
if(!wifiManager.autoConnect("AutoConnectAP")) {
Serial.println("failed to connect and hit timeout");
}
pinMode(TRIGGER_PIN, INPUT);
}
void loop() {
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW ) {
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
//reset settings - for testing
//wifiManager.resetSettings();
//sets timeout until configuration portal gets turned off
//useful to make it all retry or go to sleep
//in seconds
wifiManager.setConfigPortalTimeout(120);
//it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
//WITHOUT THIS THE AP DOES NOT SEEM TO WORK PROPERLY WITH SDK 1.5 , update to at least 1.5.1
//WiFi.mode(WIFI_STA);
// disable captive portal redirection
// wifiManager.setCaptivePortalEnable(false);
if (!wifiManager.startConfigPortal("OnDemandAP")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
} else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
// put your main code here, to run repeatedly:
}
@@ -1,47 +0,0 @@
/**
* OnDemandWebPortal.ino
* example of running the webportal manually, independantly from the captiveportal
* trigger pin will start a webportal for 120 seconds then turn it off.
*
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
// select which pin will trigger the configuration portal when set to LOW
// ESP-01 users please note: the only pins available (0 and 2), are shared
// with the bootloader, so always set them HIGH at power-up
#define TRIGGER_PIN 0
int timeout = 120; // seconds
WiFiManager wifiManager;
bool webportalrunning = false;
int start = millis();
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
}
void loop() {
if(webportalrunning){
wifiManager.process();
if(millis()-start > timeout*1000){
Serial.println("webportaltimeout");
webportalrunning = false;
wifiManager.stopWebPortal(); // auto off
}
}
// is configuration portal requested?
if ( digitalRead(TRIGGER_PIN) == LOW && !webportalrunning) {
wifiManager.startWebPortal();
webportalrunning = true;
start = millis();
}
// put your main code here, to run repeatedly:
}
@@ -0,0 +1,140 @@
/**
* WiFiManagerParameter child class example
*/
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <Arduino.h>
#include <EEPROM.h>
#define SETUP_PIN 0
class IPAddressParameter : public WiFiManagerParameter {
public:
IPAddressParameter(const char *id, const char *placeholder, IPAddress address)
: WiFiManagerParameter("") {
init(id, placeholder, address.toString().c_str(), 16, "", WFM_LABEL_BEFORE);
}
bool getValue(IPAddress &ip) {
return ip.fromString(WiFiManagerParameter::getValue());
}
};
class IntParameter : public WiFiManagerParameter {
public:
IntParameter(const char *id, const char *placeholder, long value, const uint8_t length = 10)
: WiFiManagerParameter("") {
init(id, placeholder, String(value).c_str(), length, "", WFM_LABEL_BEFORE);
}
long getValue() {
return String(WiFiManagerParameter::getValue()).toInt();
}
};
class FloatParameter : public WiFiManagerParameter {
public:
FloatParameter(const char *id, const char *placeholder, float value, const uint8_t length = 10)
: WiFiManagerParameter("") {
init(id, placeholder, String(value).c_str(), length, "", WFM_LABEL_BEFORE);
}
float getValue() {
return String(WiFiManagerParameter::getValue()).toFloat();
}
};
struct Settings {
float f;
int i;
char s[20];
uint32_t ip;
} sett;
void setup() {
pinMode(SETUP_PIN, INPUT_PULLUP);
Serial.begin(9600);
//Delay to push SETUP button
Serial.println("Press setup button");
for (int sec = 3; sec > 0; sec--) {
Serial.print(sec);
Serial.print("..");
delay(1000);
}
EEPROM.begin( 512 );
EEPROM.get(0, sett);
Serial.println("Settings loaded");
if (digitalRead(SETUP_PIN) == LOW) {
// Button pressed
Serial.println("SETUP");
WiFiManager wm;
sett.s[19] = '\0'; //add null terminator at the end cause overflow
WiFiManagerParameter param_str( "str", "param_string", sett.s, 20);
FloatParameter param_float( "float", "param_float", sett.f);
IntParameter param_int( "int", "param_int", sett.i);
IPAddress ip(sett.ip);
IPAddressParameter param_ip("ip", "param_ip", ip);
wm.addParameter( &param_str );
wm.addParameter( &param_float );
wm.addParameter( &param_int );
wm.addParameter( &param_ip );
//SSID & password parameters already included
wm.startConfigPortal();
strncpy(sett.s, param_str.getValue(), 20);
sett.s[19] = '\0';
sett.f = param_float.getValue();
sett.i = param_int.getValue();
Serial.print("String param: ");
Serial.println(sett.s);
Serial.print("Float param: ");
Serial.println(sett.f);
Serial.print("Int param: ");
Serial.println(sett.i, DEC);
if (param_ip.getValue(ip)) {
sett.ip = ip;
Serial.print("IP param: ");
Serial.println(ip);
} else {
Serial.println("Incorrect IP");
}
EEPROM.put(0, sett);
if (EEPROM.commit()) {
Serial.println("Settings saved");
} else {
Serial.println("EEPROM error");
}
}
else {
Serial.println("WORK");
//connect to saved SSID
WiFi.begin();
//do smth
Serial.print("String param: ");
Serial.println(sett.s);
Serial.print("Float param: ");
Serial.println(sett.f);
Serial.print("Int param: ");
Serial.println(sett.i, DEC);
Serial.print("IP param: ");
IPAddress ip(sett.ip);
Serial.println(ip);
}
}
void loop() {
}
+28 -12
View File
@@ -7,6 +7,25 @@
<!-- /HTTP_HEAD -->
<!-- HTTP_STYLE -->
<style>
body.invert,
body.invert a,
body.invert h1 {
background-color:#060606;
color:white;
}
body.invert .msg{
background-color: #282828;
border-top: 1px solid #555;
border-right: 1px solid #555;
border-bottom: 1px solid #555;
color:#fff;
}
body.invert .q[role=img] {
-webkit-filter: invert(1);
filter: invert(1);
}
.c,
body {
text-align: center;
@@ -29,7 +48,7 @@ input {
button {
border: 0;
border-radius: .3rem;
background-color: #1fa3ec;
background-color: #9933CC;
color: #fff;
line-height: 2.4rem;
font-size: 1.2rem;
@@ -41,7 +60,7 @@ a {
text-decoration: none;
}
a:hover {
color: #1fa3ec;
color: #9933CC;
text-decoration: underline;
}
.h {
@@ -77,10 +96,7 @@ a:hover {
.ql .q {
float: left;
}
.qinv .q {
-webkit-filter: invert(1);
filter: invert(1);
}
.q:after,
.q:before {
content: '';width:16px;height:16px;display:inline-block;background-repeat:no-repeat;background-position: 16px 0;
@@ -109,10 +125,10 @@ a:hover {
margin-bottom: 5px;
}
.msg.P {
border-left-color: #1fa3ec;
border-left-color: #9933CC;
}
.msg.P h4 {
color: #1fa3ec;
color: #9933CC;
}
/*.msg.S {
border-left-color: #5cb85c;
@@ -121,10 +137,10 @@ a:hover {
color: #5cb85c;
}*/
.msg.D {
border-left-color: #d9534f;
border-left-color: #dc3630;
}
.msg.D h4 {
color: #d9534f;
color: #dc3630;
}
dt {
@@ -138,7 +154,7 @@ td {
vertical-align: top;
}
button.D{
background-color:#d9534f;
background-color:#dc3630;
}
</style>
@@ -150,7 +166,7 @@ button.D{
<!-- /HTTP_SCRIPT -->
<!-- HTTP_HEAD_END -->
</head>
<body>
<body class="invert">
<div class='wrap'>
<!-- <div class='wrap ql qinv'> -->
<!-- /HTTP_HEAD_END -->
+16 -4
View File
@@ -1,8 +1,20 @@
{
"name": "WifiManager",
"keywords": "wifi, wi-fi",
"description": "ESP8266 WiFi Connection manager with fallback web configuration portal",
"repository":
"keywords": "wifi,wi-fi,esp,esp8266,esp32,espressif8266,espressif32,nodemcu,wemos,arduino",
"description": "WiFi Configuration manager with web configuration portal for ESP boards",
"authors":
[
{
"name": "tzapu",
"url": "https://github.com/tzapu"
},
{
"name": "tablatronix",
"url": "https://github.com/tablatronix",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/tzapu/WiFiManager.git"
@@ -13,5 +25,5 @@
"espressif8266",
"espressif32"
],
"version": "0.12"
"version": "1.0.0"
}
+5 -5
View File
@@ -1,9 +1,9 @@
name=WiFiManager
version=0.12
author=tzapu
maintainer=tzapu
sentence=WiFi Connection manager with fallback web configuration portal for ESP boards
paragraph=Library for configuring ESP8266 modules WiFi credentials at runtime.
version=1.0.0
author=tzapu,tablatronix
maintainer=tablatronix
sentence=WiFi Configuration manager with web configuration portal for ESP boards
paragraph=Library for configuring ESP8266/ESP32 modules WiFi credentials and custom parameters at runtime.
category=Communication
url=https://github.com/tzapu/WiFiManager.git
architectures=esp8266,esp32
+25 -16
View File
@@ -11,15 +11,11 @@
*/
#ifndef WIFI_MANAGER_OVERRIDE_STRINGS
// !!! THIS DOES NOT WORK, you cannot define in a sketch, if anyone one knows how to order includes to be able to do this help!
// To override the strings below in your project, make the following changes above the line that includes "WiFIManager.h"
// Add the following line:
// #define WIFI_MANAGER_OVERRIDE_STRINGS
// Copy and paste ALL of the const char lines below and modify to suit.
const char HTTP_HEAD[] PROGMEM = "<!DOCTYPE html><html lang='en'><head><meta name='format-detection' content='telephone=no'><meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'/><title>{v}</title>";
const char HTTP_HEAD_START[] PROGMEM = "<!DOCTYPE html><html lang='en'><head><meta name='format-detection' content='telephone=no'><meta charset='UTF-8' name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'/><title>{v}</title>";
const char HTTP_SCRIPT[] PROGMEM = "<script>function c(l){document.getElementById('s').value=l.innerText||l.textContent;document.getElementById('p').focus();}</script>";
const char HTTP_HEAD_END[] PROGMEM = "</head><body><div class='wrap'>";
const char HTTP_HEAD_END[] PROGMEM = "</head><body class='{c}'><div class='wrap'>";
const char HTTP_ROOT_MAIN[] PROGMEM = "<h1>{v}</h1><h3>WiFiManager</h3>";
const char * const HTTP_PORTAL_MENU[] PROGMEM = {
@@ -49,7 +45,7 @@ const char HTTP_FORM_STATIC_HEAD[] PROGMEM = "<hr><br/>";
const char HTTP_FORM_END[] PROGMEM = "<br/><br/><button type='submit'>Save</button></form>";
const char HTTP_FORM_LABEL[] PROGMEM = "<label for='{i}'>{t}</label>";
const char HTTP_FORM_PARAM_HEAD[] PROGMEM = "<hr><br/>";
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength='{l}' placeholder='' value='{v}' {c}>";
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength='{l}' value='{v}' {c}>";
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><form action='/wifi?refresh=1' method='POST'><button name='refresh' value='1'>Refresh</button></form>";
const char HTTP_SAVED[] PROGMEM = "<div class='msg'>Saving Credentials<br/>Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
@@ -71,19 +67,23 @@ const char HTTP_STYLE[] PROGMEM = "<style>"
// links
"a{color:#000;font-weight:700;text-decoration:none}a:hover{color:#1fa3ec;text-decoration:underline}"
// quality icons
".q{height:16px;margin:0;padding:0 5px;text-align:right;min-width:38px;float:right}.q.q-0:after{background-position-x:0}.q.q-1:after{background-position-x:-16px}.q.q-2:after{background-position-x:-32px}.q.q-3:after{background-position-x:-48px}.q.q-4:after{background-position-x:-64px}.q.l:before{background-position-x:-80px;padding-right:5px}.ql .q{float:left}.qinv .q{-webkit-filter:invert(1);filter:invert(1)}.q:after,.q:before{content:'';width:16px;height:16px;display:inline-block;background-repeat:no-repeat;background-position: 16px 0;"
".q{height:16px;margin:0;padding:0 5px;text-align:right;min-width:38px;float:right}.q.q-0:after{background-position-x:0}.q.q-1:after{background-position-x:-16px}.q.q-2:after{background-position-x:-32px}.q.q-3:after{background-position-x:-48px}.q.q-4:after{background-position-x:-64px}.q.l:before{background-position-x:-80px;padding-right:5px}.ql .q{float:left}.q:after,.q:before{content:'';width:16px;height:16px;display:inline-block;background-repeat:no-repeat;background-position: 16px 0;"
"background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAAQCAMAAADeZIrLAAAAJFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADHJj5lAAAAC3RSTlMAIjN3iJmqu8zd7vF8pzcAAABsSURBVHja7Y1BCsAwCASNSVo3/v+/BUEiXnIoXkoX5jAQMxTHzK9cVSnvDxwD8bFx8PhZ9q8FmghXBhqA1faxk92PsxvRc2CCCFdhQCbRkLoAQ3q/wWUBqG35ZxtVzW4Ed6LngPyBU2CobdIDQ5oPWI5nCUwAAAAASUVORK5CYII=');}"
// icons @2x media query (32px rescaled)
"@media (-webkit-min-device-pixel-ratio: 2),(min-resolution: 192dpi){.q:before,.q:after {"
"background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALwAAAAgCAMAAACfM+KhAAAALVBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAOrOgAAAADnRSTlMAESIzRGZ3iJmqu8zd7gKjCLQAAACmSURBVHgB7dDBCoMwEEXRmKlVY3L//3NLhyzqIqSUggy8uxnhCR5Mo8xLt+14aZ7wwgsvvPA/ofv9+44334UXXngvb6XsFhO/VoC2RsSv9J7x8BnYLW+AjT56ud/uePMdb7IP8Bsc/e7h8Cfk912ghsNXWPpDC4hvN+D1560A1QPORyh84VKLjjdvfPFm++i9EWq0348XXnjhhT+4dIbCW+WjZim9AKk4UZMnnCEuAAAAAElFTkSuQmCC');"
"background-size: 95px 16px;}}"
// msg callouts
".msg{padding:20px;margin:20px 0;border:1px solid #eee;border-left-width:5px;border-radius:3px;border-left-color:#777}.msg h4{margin-top:0;margin-bottom:5px}.msg.P{border-left-color:#1fa3ec}.msg.P h4{color:#1fa3ec}.msg.D{border-left-color:#d9534f}.msg.D h4{color:#d9534f}"
".msg{padding:20px;margin:20px 0;border:1px solid #eee;border-left-width:5px;border-radius:3px;border-left-color:#777}.msg h4{margin-top:0;margin-bottom:5px}.msg.P{border-left-color:#1fa3ec}.msg.P h4{color:#1fa3ec}.msg.D{border-left-color:#dc3630}.msg.D h4{color:#dc3630}"
// lists
"dt{font-weight:bold}dd{margin:0;padding:0 0 0.5em 0;min-height:12px}"
"td{vertical-align: top;}"
".h{display:none}"
"button.D{background-color:#d9534f}"
"button.D{background-color:#dc3630}"
// invert
"body.invert,body.invert a,body.invert h1 {background-color:#060606;color:#fff;}"
"body.invert .msg{color:#fff;background-color:#282828;border-top:1px solid #555;border-right:1px solid #555;border-bottom:1px solid #555;}"
"body.invert .q[role=img]{-webkit-filter:invert(1);filter:invert(1);}"
"</style>";
const char HTTP_HELP[] PROGMEM =
@@ -141,7 +141,7 @@ const char HTTP_JS[] PROGMEM =
#ifdef ESP32
const char HTTP_INFO_esphead[] PROGMEM = "<h3>esp32</h3><hr><dl>";
const char HTTP_INFO_chiprev[] PROGMEM = "<dt>Chip Rev</dt><dd>{1}</dd>";
const char HTTP_INFO_lastreset[] PROGMEM = "<dt>Last reset reason</dt><dd>CPU0: {1}<br/>CPU1: {2}</dd>";
const char HTTP_INFO_lastreset[] PROGMEM = "<dt>Last reset reason</dt><dd>CPU0: {1}<br/>CPU1: {2}</dd>";
const char HTTP_INFO_aphost[] PROGMEM = "<dt>Acccess Point Hostname</dt><dd>{1}</dd>";
#else
const char HTTP_INFO_esphead[] PROGMEM = "<h3>esp8266</h3><hr><dl>";
@@ -173,6 +173,7 @@ const char HTTP_INFO_host[] PROGMEM = "<dt>Hostname</dt><dd>{1}</dd>";
const char HTTP_INFO_stamac[] PROGMEM = "<dt>Station MAC</dt><dd>{1}</dd>";
const char HTTP_INFO_conx[] PROGMEM = "<dt>Connected</dt><dd>{1}</dd>";
const char HTTP_INFO_autoconx[] PROGMEM = "<dt>Autoconnect</dt><dd>{1}</dd>";
const char HTTP_INFO_temp[] PROGMEM = "<dt>Temperature</dt><dd>{1} C&deg; / {2} F&deg;</dd>";
// Strings
const char S_y[] PROGMEM = "Yes";
@@ -254,11 +255,11 @@ const char S_dns[] PROGMEM = "dns";
// softap ssid default prefix
#ifdef ESP8266
const char S_ssidpre[] PROGMEM = "ESP";
const char S_ssidpre[] PROGMEM = "ESP";
#elif defined(ESP32)
const char S_ssidpre[] PROGMEM = "ESP32";
const char S_ssidpre[] PROGMEM = "ESP32";
#else
const char S_ssidpre[] PROGMEM = "WM";
const char S_ssidpre[] PROGMEM = "WM";
#endif
//Tokens
@@ -285,6 +286,8 @@ const char T_h[] PROGMEM = "{h}"; // @token h
const char HTTP_HEAD_CL[] PROGMEM = "Content-Length";
const char HTTP_HEAD_CT[] PROGMEM = "text/html";
const char HTTP_HEAD_CT2[] PROGMEM = "text/plain";
const char HTTP_HEAD_CORS[] PROGMEM = "Access-Control-Allow-Origin";
const char HTTP_HEAD_CORS_ALLOW_ALL[] PROGMEM = "*";
const char * const WIFI_STA_STATUS[] PROGMEM
{
@@ -324,4 +327,10 @@ const char * const AUTH_MODE_NAMES[] PROGMEM
};
#endif
const char* const WIFI_MODES[] PROGMEM = { "NULL", "STA", "AP", "STA+AP" };
const char* const WIFI_MODES[] PROGMEM = { "NULL", "STA", "AP", "STA+AP" };
#ifdef ESP32
const wifi_country_t WM_COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO};
const wifi_country_t WM_COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO};
const wifi_country_t WM_COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO};
#endif