mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
Merge branch 'development' into resetConfigCallback
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
## PLEASE TRY DEVELOPMENT BRANCH before submitting bugs on release or master, in case they were already fixed. ##
|
||||
|
||||
## POST SERIAL OUTPUT !
|
||||
|
||||
Issues without basic info will be ignored or closed!
|
||||
|
||||
Please fill the info fields, it helps to get you faster support ;)
|
||||
@@ -17,24 +15,13 @@ https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst
|
||||
### Basic Infos
|
||||
|
||||
#### Hardware
|
||||
**WiFimanager Branch/Release:**
|
||||
- [ ] Master
|
||||
- [ ] Development
|
||||
WiFimanager Branch/Release: Development
|
||||
|
||||
**Esp8266/Esp32:**
|
||||
- [ ] ESP8266
|
||||
- [ ] ESP32
|
||||
Esp8266/Esp32:
|
||||
|
||||
**Hardware: ESP-12e, esp01, esp25**
|
||||
- [ ] ESP01
|
||||
- [ ] ESP12 E/F/S (nodemcu, wemos, feather)
|
||||
- [ ] Other
|
||||
Hardware: ESP-12e, esp01, esp25
|
||||
|
||||
|
||||
**ESP Core Version: 2.4.0, staging**
|
||||
- [ ] 2.3.0
|
||||
- [ ] 2.4.0
|
||||
- [ ] staging (master/dev)
|
||||
Core Version: 2.4.0, staging
|
||||
|
||||
### Description
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
platformio.ini
|
||||
+30
-13
@@ -1,34 +1,51 @@
|
||||
language: c
|
||||
sudo: false
|
||||
|
||||
before_install:
|
||||
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
|
||||
- sleep 3
|
||||
- export DISPLAY=:1.0
|
||||
- wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
|
||||
- tar xf arduino-1.6.5-linux64.tar.xz
|
||||
- sudo mv arduino-1.6.5 /usr/local/share/arduino
|
||||
- wget http://downloads.arduino.cc/arduino-1.8.5-linux64.tar.xz
|
||||
- tar xf arduino-1.8.5-linux64.tar.xz
|
||||
- sudo mv arduino-1.8.5 /usr/local/share/arduino
|
||||
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
|
||||
|
||||
install:
|
||||
- ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager
|
||||
# boards manager not working on 1.6.7 - 1.6.8
|
||||
- arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
|
||||
# install lib arduino json not working in 1.6.5
|
||||
# - arduino --install-library "ArduinoJson"
|
||||
- git clone https://github.com/bblanchon/ArduinoJson /usr/local/share/arduino/libraries/ArduinoJson
|
||||
- arduino --install-library "ArduinoJson:5.13.2"
|
||||
- arduino --install-boards esp8266:esp8266
|
||||
- arduino --board esp8266:esp8266:generic --save-prefs
|
||||
- arduino --pref "compiler.warning_level=all" --save-prefs
|
||||
# install esp32
|
||||
- pushd .
|
||||
- mkdir -p ~/Arduino/hardware/espressif
|
||||
- cd ~/Arduino/hardware/espressif
|
||||
- git clone https://github.com/espressif/arduino-esp32.git esp32
|
||||
- cd esp32
|
||||
- git submodule update --init --recursive
|
||||
- cd tools
|
||||
- python2 get.py
|
||||
- popd
|
||||
# esp32 needs WebServer_tng for now
|
||||
- git clone https://github.com/bbx10/WebServer_tng.git /usr/local/share/arduino/libraries/WebServer_tng
|
||||
|
||||
script:
|
||||
- "echo $PWD"
|
||||
- "echo $HOME"
|
||||
- "ls $PWD"
|
||||
- source $TRAVIS_BUILD_DIR/travis/common.sh
|
||||
- arduino --board esp8266:esp8266:generic:CpuFrequency=80,CrystalFreq=26,FlashFreq=40,FlashMode=qio,FlashSize=4M1M,led=2,LwIPVariant=v2mss536,Debug=Serial,DebugLevel=CORE --save-prefs
|
||||
- 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
|
||||
- build_examples
|
||||
# - "cat $PWD/examples/AutoConnect/AutoConnect.ino"
|
||||
# - arduino -v --verbose-build --verify $PWD/examples/AutoConnect/AutoConnect.ino
|
||||
# - arduino --verify --board arduino:avr:uno $PWD/examples/IncomingCall/IncomingCall.ino
|
||||
# - arduino --verify --board arduino:avr:uno $PWD/examples/AdafruitIO_GPS/AdafruitIO_GPS.ino
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
# no coverage generated, no need to run
|
||||
#
|
||||
#after_success:
|
||||
# - bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: change
|
||||
|
||||
@@ -3,21 +3,34 @@
|
||||
# WiFiManager
|
||||
ESP8266 WiFi Connection manager with fallback web configuration portal
|
||||
|
||||
[](https://travis-ci.org/tzapu/WiFiManager)
|
||||
[](https://travis-ci.org/tzapu/WiFiManager)
|
||||
|
||||

|
||||

|
||||
|
||||
The configuration portal is of the captive variety, so on various devices it will present the configuration dialogue as soon as you connect to the created access point.
|
||||
|
||||
First attempt at a library. Lots more changes and fixes to do. Contributions are welcome.
|
||||
|
||||
#### This works with the ESP8266 Arduino platform with a recent stable release(2.0.0 or newer) https://github.com/esp8266/Arduino
|
||||
**This works with the ESP8266 Arduino platform with a recent stable release(2.0.0 or newer)**
|
||||
|
||||
[https://github.com/esp8266/Arduino](https://github.com/esp8266/Arduino)
|
||||
|
||||
**This works with the ESP32 Arduino platform with staging**
|
||||
|
||||
[https://github.com/espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
|
||||
|
||||
### Known Issues
|
||||
* Documentation needs to be updated, see [https://github.com/tzapu/WiFiManager/issues/500](https://github.com/tzapu/WiFiManager/issues/500)
|
||||
|
||||
## Contents
|
||||
- [How it works](#how-it-works)
|
||||
- [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)
|
||||
@@ -34,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
|
||||
 
|
||||
@@ -55,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
|
||||
|
||||
@@ -65,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
|
||||

|
||||
|
||||
@@ -75,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;
|
||||
```
|
||||
@@ -184,6 +220,12 @@ void loop() {
|
||||
```
|
||||
See example for a more complex version. [OnDemandConfigPortal](https://github.com/tzapu/WiFiManager/tree/master/examples/OnDemandConfigPortal)
|
||||
|
||||
#### Exiting from the Configuration Portal
|
||||
Normally, once entered, the configuration portal will continue to loop until WiFi credentials have been successfully entered or a timeout is reached.
|
||||
If you'd prefer to exit without joining a WiFi network, say becuase you're going to put the ESP into AP mode, then press the "Exit" button
|
||||
on the main webpage.
|
||||
If started via `autoConnect` or `startConfigPortal` then it will return `false (portalAbortResult)`
|
||||
|
||||
#### Custom Parameters
|
||||
You can use WiFiManager to collect more parameters than just SSID and password.
|
||||
This could be helpful for configuring stuff like MQTT host and port, [blynk](http://www.blynk.cc) or [emoncms](http://emoncms.org) tokens, just to name a few.
|
||||
@@ -191,18 +233,18 @@ This could be helpful for configuring stuff like MQTT host and port, [blynk](htt
|
||||
Usage scenario would be:
|
||||
- load values from somewhere (EEPROM/FS) or generate some defaults
|
||||
- add the custom parameters to WiFiManager using
|
||||
```cpp
|
||||
```cpp
|
||||
// id/name, placeholder/prompt, default, length
|
||||
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
|
||||
wifiManager.addParameter(&custom_mqtt_server);
|
||||
|
||||
```
|
||||
```
|
||||
- if connection to AP fails, configuration portal starts and you can set /change the values (or use on demand configuration portal)
|
||||
- once configuration is done and connection is established [save config callback]() is called
|
||||
- once WiFiManager returns control to your application, read and save the new values using the `WiFiManagerParameter` object.
|
||||
```cpp
|
||||
```cpp
|
||||
mqtt_server = custom_mqtt_server.getValue();
|
||||
```
|
||||
```
|
||||
This feature is a lot more involved than all the others, so here are some examples to fully show how it is done.
|
||||
You should also take a look at adding custom HTML to your form.
|
||||
|
||||
@@ -266,6 +308,14 @@ Debug is enabled by default on Serial. To disable add before autoConnect
|
||||
wifiManager.setDebugOutput(false);
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
@@ -278,6 +328,8 @@ 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.
|
||||
|
||||
## Releases
|
||||
#### 1.0.1
|
||||
|
||||
#### 0.12
|
||||
- removed 204 header response
|
||||
- fixed incompatibility with other libs using isnan and other std:: functions without namespace
|
||||
@@ -342,7 +394,11 @@ The support and help I got from the community has been nothing short of phenomen
|
||||
|
||||
__THANK YOU__
|
||||
|
||||
[Shawn A](https://github.com/tablatronix)
|
||||
[Shawn A aka tablatronix](https://github.com/tablatronix)
|
||||
|
||||
[bbx10](https://github.com/bbx10)
|
||||
|
||||
[kentaylor](https://github.com/kentaylor)
|
||||
|
||||
[Maximiliano Duarte](https://github.com/domonetic)
|
||||
|
||||
@@ -368,7 +424,10 @@ __THANK YOU__
|
||||
|
||||
[walthercarsten](https://github.com/walthercarsten)
|
||||
|
||||
Sorry if i have missed anyone.
|
||||
And countless others
|
||||
|
||||
#### Inspiration
|
||||
- http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||
* http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||
* 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
|
||||
|
||||
+2386
-564
File diff suppressed because it is too large
Load Diff
+368
-83
@@ -1,44 +1,103 @@
|
||||
/**************************************************************
|
||||
WiFiManager is a library for the ESP8266/Arduino platform
|
||||
(https://github.com/esp8266/Arduino) to enable easy
|
||||
configuration and reconfiguration of WiFi credentials using a Captive Portal
|
||||
inspired by:
|
||||
http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||
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
|
||||
Licensed under MIT license
|
||||
**************************************************************/
|
||||
/**
|
||||
* WiFiManager.h
|
||||
*
|
||||
* WiFiManager, a library for the ESP8266/Arduino platform
|
||||
* for configuration of WiFi credentials using a Captive Portal
|
||||
*
|
||||
* @author Creator tzapu
|
||||
* @author tablatronix
|
||||
* @version 0.0.0
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
#ifndef WiFiManager_h
|
||||
#define WiFiManager_h
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#ifdef ESP8266
|
||||
#include <core_version.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
// #define WM_MDNS // also set MDNS with sethostname
|
||||
// #define WM_FIXERASECONFIG // use erase flash fix
|
||||
// #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
|
||||
// autoreconnect status WORKING https://github.com/espressif/arduino-esp32/issues/653#issuecomment-405604766
|
||||
|
||||
#define WM_WEBSERVERSHIM // use webserver shim lib
|
||||
|
||||
#ifdef ESP8266
|
||||
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
#ifdef WM_MDNS
|
||||
#include <ESP8266mDNS.h>
|
||||
#endif
|
||||
|
||||
#define WIFI_getChipId() ESP.getChipId()
|
||||
#define WM_WIFIOPEN ENC_TYPE_NONE
|
||||
|
||||
#elif defined(ESP32)
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
|
||||
#define WIFI_getChipId() (uint32_t)ESP.getEfuseMac()
|
||||
#define WM_WIFIOPEN WIFI_AUTH_OPEN
|
||||
|
||||
#ifndef WEBSERVER_H
|
||||
#ifdef WM_WEBSERVERSHIM
|
||||
#include <WebServer.h>
|
||||
#else
|
||||
#include <ESP8266WebServer.h>
|
||||
// Forthcoming official ?
|
||||
// https://github.com/esp8266/ESPWebServer
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WM_ERASE_NVS
|
||||
#include <nvs.h>
|
||||
#include <nvs_flash.h>
|
||||
#endif
|
||||
|
||||
#ifdef WM_MDNS
|
||||
#include <ESPmDNS.h>
|
||||
#endif
|
||||
|
||||
#ifdef WM_RTC
|
||||
#include <rom/rtc.h>
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
#endif
|
||||
|
||||
#include <DNSServer.h>
|
||||
#include <memory>
|
||||
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
|
||||
const char HTTP_HEAD[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\" name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>";
|
||||
const char HTTP_STYLE[] PROGMEM = "<style>.c{text-align: center;} div,input{padding:5px;font-size:1em;} input{width:95%;} body{text-align: center;font-family:verdana;} button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;} .q{float: right;width: 64px;text-align: right;} .l{background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==\") no-repeat left center;background-size: 1em;}</style>";
|
||||
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 style='text-align:left;display:inline-block;min-width:260px;'>";
|
||||
const char HTTP_PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>";
|
||||
const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
||||
const char HTTP_FORM_START[] PROGMEM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 type='password' placeholder='password'><br/>";
|
||||
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='{p}' value='{v}' {c}>";
|
||||
const char HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
||||
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
||||
const char HTTP_SAVED[] PROGMEM = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
|
||||
const char HTTP_END[] PROGMEM = "</div></body></html>";
|
||||
#include "strings_en.h"
|
||||
|
||||
#ifndef WIFI_MANAGER_MAX_PARAMS
|
||||
#define WIFI_MANAGER_MAX_PARAMS 10
|
||||
#define WIFI_MANAGER_MAX_PARAMS 5 // params will autoincrement and realloc by this amount when max is reached
|
||||
#endif
|
||||
|
||||
#define WFM_LABEL_BEFORE 1
|
||||
#define WFM_LABEL_AFTER 2
|
||||
#define WFM_NO_LABEL 0
|
||||
|
||||
class WiFiManagerParameter {
|
||||
public:
|
||||
/**
|
||||
@@ -46,24 +105,32 @@ class WiFiManagerParameter {
|
||||
@id is used for HTTP queries and must not contain spaces nor other special characters
|
||||
*/
|
||||
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 *getID();
|
||||
const char *getValue();
|
||||
const char *getPlaceholder();
|
||||
int getValueLength();
|
||||
int getLabelPlacement();
|
||||
const char *getCustomHTML();
|
||||
void setValue(const char *defaultValue, int length);
|
||||
|
||||
protected:
|
||||
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);
|
||||
|
||||
private:
|
||||
const char *_id;
|
||||
const char *_placeholder;
|
||||
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);
|
||||
|
||||
friend class WiFiManager;
|
||||
};
|
||||
|
||||
@@ -71,134 +138,352 @@ class WiFiManagerParameter {
|
||||
class WiFiManager
|
||||
{
|
||||
public:
|
||||
WiFiManager(Stream& consolePort);
|
||||
WiFiManager();
|
||||
~WiFiManager();
|
||||
void WiFiManagerInit();
|
||||
|
||||
// auto connect to saved wifi, or custom, and start config portal on failures
|
||||
boolean autoConnect();
|
||||
boolean autoConnect(char const *apName, char const *apPassword = NULL);
|
||||
|
||||
//if you want to always start the config portal, without trying to connect first
|
||||
boolean startConfigPortal();
|
||||
//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
|
||||
boolean stopConfigPortal();
|
||||
|
||||
//manually start the web portal, autoconnect does this automatically on connect failure
|
||||
void startWebPortal();
|
||||
//manually stop the web portal if started manually
|
||||
void stopWebPortal();
|
||||
// Run webserver processing, if setConfigPortalBlocking(false)
|
||||
boolean process();
|
||||
|
||||
// get the AP name of the config portal, so it can be used in the callback
|
||||
String getConfigPortalSSID();
|
||||
|
||||
// erase wifi credentials
|
||||
void resetSettings();
|
||||
// reboot esp
|
||||
void reboot();
|
||||
// disconnect wifi, without persistent saving or erasing
|
||||
bool disconnect();
|
||||
// erase esp
|
||||
bool erase();
|
||||
bool erase(bool opt);
|
||||
|
||||
//sets timeout before webserver loop ends and exits even if there has been no setup.
|
||||
//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);
|
||||
void setTimeout(unsigned long seconds); // @deprecated, alias
|
||||
|
||||
//sets timeout for which to attempt connecting, useful if you get a lot of failed connects
|
||||
void setConnectTimeout(unsigned long seconds);
|
||||
|
||||
|
||||
//sets timeout for which to attempt connecting on saves, useful if there are bugs in esp waitforconnectloop
|
||||
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);
|
||||
//sets config for a static IP
|
||||
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) );
|
||||
void setAPCallback( std::function<void(WiFiManager*)> func );
|
||||
//called when settings reset have been triggered
|
||||
void setConfigResetCallback(void(*func)(void));
|
||||
//called when settings have been changed and connection was successful
|
||||
void setSaveConfigCallback( std::function<void()> func );
|
||||
//called when settings before have been changed and connection was successful
|
||||
void setPreSaveConfigCallback( std::function<void()> func );
|
||||
//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();
|
||||
//if this is set, it will exit after config, even if connection is unsuccessful.
|
||||
void setBreakAfterConfig(boolean shouldBreak);
|
||||
//if this is set, try WPS setup when starting (this will delay config portal for up to 2 mins)
|
||||
//TODO
|
||||
// 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);
|
||||
//if this is true, remove duplicated Access Points - defaut true
|
||||
void setRemoveDuplicateAPs(boolean removeDuplicates);
|
||||
//setter for ESP wifi.persistent so we can remember it and restore user preference, as WIFi._persistent is protected
|
||||
void setRestorePersistent(boolean persistent);
|
||||
//if true, always show static net inputs, IP, subnet, gateway, else only show if set via setSTAStaticIPConfig
|
||||
void setShowStaticFields(boolean alwaysShow);
|
||||
//if true, always show static dns, esle only show if set via setSTAStaticIPConfig
|
||||
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 true, reset timeout when webclient connects (true), suggest disabling if captiveportal is open
|
||||
void setWebPortalClientCheck(boolean enabled);
|
||||
// if true, enable autoreconnecting
|
||||
void setWiFiAutoReconnect(boolean enabled);
|
||||
// if true, wifiscan will show percentage instead of quality icons, until we have better templating
|
||||
void setScanDispPerc(boolean enabled);
|
||||
// if true (default) then start the config portal from autoConnect if connection failed
|
||||
void setEnableConfigPortal(boolean enable);
|
||||
// set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266
|
||||
bool setHostname(const char * hostname);
|
||||
// show erase wifi onfig button on info page, true
|
||||
void setShowInfoErase(boolean enabled);
|
||||
// set custom menu
|
||||
|
||||
// set custom menu items and order
|
||||
void setMenu(std::vector<const char*>& menu);
|
||||
void setMenu(const char* menu[], uint8_t size);
|
||||
|
||||
// get last connection result, includes autoconnect and wifisave
|
||||
uint8_t getLastConxResult();
|
||||
// get a status as string
|
||||
String getWLStatusString(uint8_t status);
|
||||
String getModeString(uint8_t mode);
|
||||
// check if the module has a saved ap to connect to
|
||||
bool getWiFiIsSaved();
|
||||
|
||||
// debug output the softap config
|
||||
void debugSoftAPConfig();
|
||||
// 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;
|
||||
std::unique_ptr<ESP8266WebServer> server;
|
||||
|
||||
//const int WM_DONE = 0;
|
||||
//const int WM_WAIT = 10;
|
||||
#if defined(ESP32) && defined(WM_WEBSERVERSHIM)
|
||||
using WM_WebServer = WebServer;
|
||||
#else
|
||||
using WM_WebServer = ESP8266WebServer;
|
||||
#endif
|
||||
std::unique_ptr<WM_WebServer> server;
|
||||
|
||||
//const String HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>";
|
||||
|
||||
void setupConfigPortal();
|
||||
void startWPS();
|
||||
|
||||
const char* _apName = "no-net";
|
||||
const char* _apPassword = NULL;
|
||||
String _ssid = "";
|
||||
String _pass = "";
|
||||
unsigned long _configPortalTimeout = 0;
|
||||
unsigned long _connectTimeout = 0;
|
||||
unsigned long _configPortalStart = 0;
|
||||
std::vector<uint8_t> _menuIds;
|
||||
std::vector<const char *> _menuIdsDefault = {"wifi","info","exit"};
|
||||
|
||||
// ip configs @todo struct ?
|
||||
IPAddress _ap_static_ip;
|
||||
IPAddress _ap_static_gw;
|
||||
IPAddress _ap_static_sn;
|
||||
IPAddress _sta_static_ip;
|
||||
IPAddress _sta_static_gw;
|
||||
IPAddress _sta_static_sn;
|
||||
IPAddress _sta_static_dns;
|
||||
|
||||
int _paramsCount = 0;
|
||||
int _minimumQuality = -1;
|
||||
boolean _removeDuplicateAPs = true;
|
||||
boolean _shouldBreakAfterConfig = false;
|
||||
boolean _tryWPS = false;
|
||||
// defaults
|
||||
const byte DNS_PORT = 53;
|
||||
const byte HTTP_PORT = 80;
|
||||
String _apName = "no-net";
|
||||
String _apPassword = "";
|
||||
String _ssid = "";
|
||||
String _pass = "";
|
||||
|
||||
// options flags
|
||||
unsigned long _configPortalTimeout = 0; // ms close config portal loop if set (depending on _cp/webClientCheck options)
|
||||
unsigned long _connectTimeout = 0; // ms stop trying to connect to ap if set
|
||||
unsigned long _saveTimeout = 0; // ms stop trying to connect to ap on saves, in case bugs in esp waitforconnectresult
|
||||
unsigned long _configPortalStart = 0; // ms config portal start time (updated for timeouts)
|
||||
unsigned long _webPortalAccessed = 0; // ms last web access time
|
||||
WiFiMode_t _usermode = WIFI_OFF;
|
||||
String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid
|
||||
uint8_t _lastconxresult = WL_IDLE_STATUS;
|
||||
int _numNetworks = 0;
|
||||
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
|
||||
|
||||
const char* _customHeadElement = "";
|
||||
#ifdef ESP32
|
||||
static uint8_t _lastconxresulttmp; // tmp var for esp32 callback
|
||||
#endif
|
||||
|
||||
//String getEEPROMString(int start, int len);
|
||||
//void setEEPROMString(int start, int len, String string);
|
||||
#ifndef WL_STATION_WRONG_PASSWORD
|
||||
uint8_t WL_STATION_WRONG_PASSWORD = 7; // @kludge define a WL status for wrong password
|
||||
#endif
|
||||
|
||||
// parameter options
|
||||
int _minimumQuality = -1; // filter wifiscan ap by this rssi
|
||||
int _staShowStaticFields = 0; // ternary always show static ip fields, only if not set in code, never(cannot change ips via web!)
|
||||
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 _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 _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
|
||||
boolean _showInfoErase = true; // info page erase button
|
||||
boolean _enableConfigPortal = true; // use config portal if autoconnect failed
|
||||
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();
|
||||
|
||||
#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);
|
||||
bool setSTAConfig();
|
||||
bool wifiConnectDefault();
|
||||
bool wifiConnectNew(String ssid, String pass);
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
int connectWifi(String ssid, String pass);
|
||||
uint8_t waitForConnectResult();
|
||||
uint8_t waitForConnectResult(uint16_t timeout);
|
||||
void updateConxResult(uint8_t status);
|
||||
|
||||
// webserver handlers
|
||||
void handleRoot();
|
||||
void handleWifi(boolean scan);
|
||||
void handleWifiSave();
|
||||
void handleInfo();
|
||||
void handleReset();
|
||||
void handleNotFound();
|
||||
void handle204();
|
||||
void handleExit();
|
||||
void handleClose();
|
||||
// void handleErase();
|
||||
void handleErase(boolean opt);
|
||||
void handleParam();
|
||||
void handleWiFiStatus();
|
||||
void handleRequest();
|
||||
void handleParamSave();
|
||||
void doParamSave();
|
||||
|
||||
boolean captivePortal();
|
||||
boolean configPortalHasTimeout();
|
||||
uint8_t processConfigPortal();
|
||||
void stopCaptivePortal();
|
||||
|
||||
// DNS server
|
||||
const byte DNS_PORT = 53;
|
||||
// wifi platform abstractions
|
||||
bool WiFi_Mode(WiFiMode_t m);
|
||||
bool WiFi_Mode(WiFiMode_t m,bool persistent);
|
||||
bool WiFi_Disconnect();
|
||||
bool WiFi_enableSTA(bool enable);
|
||||
bool WiFi_enableSTA(bool enable,bool persistent);
|
||||
bool WiFi_eraseConfig();
|
||||
uint8_t WiFi_softap_num_stations();
|
||||
bool WiFi_hasAutoConnect();
|
||||
void WiFi_autoReconnect();
|
||||
String WiFi_SSID();
|
||||
bool WiFi_scanNetworks();
|
||||
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
|
||||
void WiFiEvent(WiFiEvent_t event, system_event_info_t info);
|
||||
#endif
|
||||
|
||||
// output helpers
|
||||
String getParamOut();
|
||||
String getIpForm(String id, String title, String value);
|
||||
String getScanItemOut();
|
||||
String getStaticOut();
|
||||
String getHTTPHead(String title);
|
||||
String getMenuOut();
|
||||
//helpers
|
||||
int getRSSIasQuality(int RSSI);
|
||||
boolean isIp(String str);
|
||||
String toStringIp(IPAddress ip);
|
||||
boolean validApPassword();
|
||||
String encryptionTypeStr(uint8_t authmode);
|
||||
void reportStatus(String &page);
|
||||
String getInfoData(String id);
|
||||
|
||||
// flags
|
||||
boolean connect;
|
||||
boolean _debug = true;
|
||||
boolean abort;
|
||||
boolean reset = false;
|
||||
boolean configPortalActive = false;
|
||||
boolean webPortalActive = false;
|
||||
boolean portalTimeoutResult = false;
|
||||
boolean portalAbortResult = false;
|
||||
boolean storeSTAmode = true; // option store persistent STA mode in connectwifi
|
||||
int timer = 0;
|
||||
|
||||
// WiFiManagerParameter
|
||||
int _paramsCount = 0;
|
||||
int _max_params;
|
||||
WiFiManagerParameter** _params = NULL;
|
||||
|
||||
void (*_apcallback)(WiFiManager*) = NULL;
|
||||
void (*_savecallback)(void) = NULL;
|
||||
void (*_resetcallback)(void) = NULL;
|
||||
|
||||
int _max_params;
|
||||
WiFiManagerParameter** _params;
|
||||
// debugging
|
||||
typedef enum {
|
||||
DEBUG_ERROR = 0,
|
||||
DEBUG_NOTIFY = 1, // default
|
||||
DEBUG_VERBOSE = 2,
|
||||
DEBUG_DEV = 3,
|
||||
DEBUG_MAX = 4
|
||||
} wm_debuglevel_t;
|
||||
|
||||
boolean _debug = true;
|
||||
uint8_t _debugLevel = DEBUG_DEV;
|
||||
Stream& _debugPort; // debug output stream ref
|
||||
|
||||
template <typename Generic>
|
||||
void DEBUG_WM(Generic text);
|
||||
void DEBUG_WM(Generic text);
|
||||
|
||||
template <typename Generic>
|
||||
void DEBUG_WM(wm_debuglevel_t level,Generic text);
|
||||
template <typename Generic, typename Genericb>
|
||||
void DEBUG_WM(Generic text,Genericb textb);
|
||||
template <typename Generic, typename Genericb>
|
||||
void DEBUG_WM(wm_debuglevel_t level, Generic text,Genericb textb);
|
||||
|
||||
// callbacks
|
||||
std::function<void(WiFiManager*)> _apcallback;
|
||||
std::function<void()> _savecallback;
|
||||
std::function<void()> _presavecallback;
|
||||
void (*_resetcallback)(void) = NULL; // @todo change to std func
|
||||
|
||||
template <class T>
|
||||
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
|
||||
return obj->fromString(s);
|
||||
}
|
||||
auto optionalIPFromString(...) -> bool {
|
||||
DEBUG_WM("NO fromString METHOD ON IPAddress, you need ESP8266 core 2.1.0 or newer for Custom IP configuration to work.");
|
||||
// DEBUG_WM("NO fromString METHOD ON IPAddress, you need ESP8266 core 2.1.0 or newer for Custom IP configuration to work.");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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;
|
||||
WiFiManagerParameter custom_field("customfield", "Custom Field", "Default Value", customFieldLength);
|
||||
wm.addParameter(&custom_field);
|
||||
|
||||
// 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(60); // auto close configportal after n seconds
|
||||
// wifiManager.setCaptivePortalEnable(false); // disable captive portal redirection
|
||||
|
||||
// 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, not recommended for production code
|
||||
delay(50);
|
||||
if( digitalRead(TRIGGER_PIN) == LOW ){
|
||||
|
||||
// holding button 3000 ms, reset settings
|
||||
delay(3000); // reset delay hold
|
||||
if( digitalRead(TRIGGER_PIN) == LOW ){
|
||||
Serial.println("Erasing Config");
|
||||
wm.resetSettings();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
// start portal w delay
|
||||
Serial.println("Starting config portal");
|
||||
wm.setConfigPortalTimeout(120);
|
||||
|
||||
if (!wm.startConfigPortal("OnDemandAP")) {
|
||||
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 :)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
checkButton();
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#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:
|
||||
|
||||
}
|
||||
+73
-55
@@ -1,18 +1,20 @@
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
#include <FS.h> // this needs to be first, or it all crashes and burns...
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
|
||||
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
||||
#ifdef ESP32
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
//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;
|
||||
@@ -23,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...");
|
||||
@@ -56,74 +53,89 @@ 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");
|
||||
}
|
||||
configFile.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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", blynk_token, 32);
|
||||
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.setTimeout(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
|
||||
ESP.reset();
|
||||
// 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) {
|
||||
@@ -131,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() {
|
||||
+51
-68
@@ -1,19 +1,16 @@
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
#include <FS.h> // this needs to be first, or it all crashes and burns...
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
|
||||
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
||||
#ifdef ESP32
|
||||
#include <SPIFFS.h>
|
||||
#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";
|
||||
@@ -28,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...");
|
||||
@@ -60,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");
|
||||
}
|
||||
@@ -87,59 +74,54 @@ 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.setTimeout(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
|
||||
ESP.reset();
|
||||
// if we still have not connected restart and try all over again
|
||||
ESP.restart();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
@@ -149,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) {
|
||||
@@ -157,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) {
|
||||
@@ -173,6 +155,7 @@ void setup() {
|
||||
json.printTo(configFile);
|
||||
configFile.close();
|
||||
//end save
|
||||
shouldSaveConfig = false;
|
||||
}
|
||||
|
||||
Serial.println("local ip");
|
||||
+11
-14
@@ -1,19 +1,16 @@
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
// LED will blink when in config mode
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
#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
|
||||
@@ -31,27 +28,27 @@ 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.reset();
|
||||
ESP.restart();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
@@ -59,7 +56,7 @@ void setup() {
|
||||
Serial.println("connected...yeey :)");
|
||||
ticker.detach();
|
||||
//keep LED on
|
||||
digitalWrite(BUILTIN_LED, LOW);
|
||||
digitalWrite(LED, LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -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,198 @@
|
||||
/**
|
||||
* This is a kind of unit test for DEV for now
|
||||
*/
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
|
||||
#define TRIGGER_PIN 0
|
||||
const char* modes[] = { "NULL", "STA", "AP", "STA+AP" };
|
||||
|
||||
WiFiManager wm;
|
||||
|
||||
char ssid[] = "*************"; // your network SSID (name)
|
||||
char pass[] = "********"; // your network password
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void saveCallback(){
|
||||
Serial.println("saveCallback fired");
|
||||
}
|
||||
|
||||
|
||||
//gets called when WiFiManager enters configuration mode
|
||||
void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
Serial.println("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 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);
|
||||
|
||||
//WiFiManager
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
// WiFiManager wm;
|
||||
|
||||
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");
|
||||
wm.setAPCallback(configModeCallback);
|
||||
|
||||
//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);
|
||||
|
||||
// uint8_t menu[] = {wm.MENU_WIFI,wm.MENU_INFO,wm.MENU_PARAM,wm.MENU_CLOSE};
|
||||
// wm.setMenu(menu);
|
||||
|
||||
// std::vector<WiFiManager::menu_page_t> menu = {wm.MENU_WIFI,wm.MENU_INFO,wm.MENU_PARAM,wm.MENU_CLOSE,wm.MENU_SEP,wm.MENU_ERASE,wm.MENU_EXIT};
|
||||
// wm.setMenu(menu);
|
||||
|
||||
// std::vector<WiFiManager::menu_page_t> menu = {wm.MENU_WIFI,wm.MENU_INFO,wm.MENU_PARAM,wm.MENU_CLOSE,wm.MENU_SEP,wm.MENU_ERASE,wm.MENU_EXIT};
|
||||
// wm.setMenu(menu);
|
||||
|
||||
|
||||
WiFiManagerParameter custom_html("<p>This Is Custom HTML</p>");
|
||||
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}'");
|
||||
|
||||
// callbacks
|
||||
wm.setSaveConfigCallback(saveCallback);
|
||||
|
||||
//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);
|
||||
|
||||
// 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"};
|
||||
// wm.setMenu(menu,9);
|
||||
|
||||
std::vector<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
|
||||
wm.setMenu(menu);
|
||||
|
||||
// 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 {
|
||||
// start configportal always
|
||||
// wm.setConfigPortalTimeout(60);
|
||||
// wm.startConfigPortal();
|
||||
}
|
||||
|
||||
pinMode(TRIGGER_PIN, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// is configuration portal requested?
|
||||
if ( digitalRead(TRIGGER_PIN) == LOW ) {
|
||||
Serial.println("BUTTON PRESSED");
|
||||
//WiFiManager
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
//reset settings - for testing
|
||||
//wm.resetSettings();
|
||||
|
||||
//sets timeout until configuration portal gets turned off
|
||||
//useful to make it all retry or go to sleep, in seconds
|
||||
wm.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
|
||||
// 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 :)");
|
||||
}
|
||||
}
|
||||
|
||||
// put your main code here, to run repeatedly:
|
||||
delay(5000);
|
||||
}
|
||||
@@ -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,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-7
@@ -1,9 +1,4 @@
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include "WiFiManager.h" //https://github.com/tzapu/WiFiManager
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
|
||||
void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
Serial.println("Entered config mode");
|
||||
@@ -32,7 +27,7 @@ void setup() {
|
||||
if(!wifiManager.autoConnect()) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.reset();
|
||||
ESP.restart();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
+3
-9
@@ -1,11 +1,5 @@
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
#include <FS.h> // this needs to be first, or it all crashes and burns...
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
@@ -30,7 +24,7 @@ void setup() {
|
||||
if (!wifiManager.autoConnect("AutoConnectAP", "password")) {
|
||||
Serial.println("failed to connect, we should reset as see if it connects");
|
||||
delay(3000);
|
||||
ESP.reset();
|
||||
ESP.restart();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
+4
-13
@@ -1,12 +1,5 @@
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
|
||||
#include <FS.h> // this needs to be first, or it all crashes and burns...
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
|
||||
/**************************************************************************************
|
||||
* this example shows how to set a static IP configuration for the ESP
|
||||
@@ -15,9 +8,7 @@
|
||||
* if you want the ability to configure and persist the new IP configuration
|
||||
* look at the FS examples, which save the config to file
|
||||
*************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
//default custom static IP
|
||||
//char static_ip[16] = "10.0.1.59";
|
||||
//char static_gw[16] = "10.0.1.1";
|
||||
@@ -61,7 +52,7 @@ void setup() {
|
||||
if (!wifiManager.autoConnect("AutoConnectAP", "password")) {
|
||||
Serial.println("failed to connect, we should reset as see if it connects");
|
||||
delay(3000);
|
||||
ESP.reset();
|
||||
ESP.restart();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
+3
-10
@@ -1,11 +1,4 @@
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
|
||||
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
@@ -20,7 +13,7 @@ void setup() {
|
||||
//sets timeout until configuration portal gets turned off
|
||||
//useful to make it all retry or go to sleep
|
||||
//in seconds
|
||||
wifiManager.setTimeout(180);
|
||||
wifiManager.setConfigPortalTimeout(180);
|
||||
|
||||
//fetches ssid and pass and tries to connect
|
||||
//if it does not connect it starts an access point with the specified name
|
||||
@@ -30,7 +23,7 @@ void setup() {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(3000);
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.reset();
|
||||
ESP.restart();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
@@ -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,60 +0,0 @@
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <DNSServer.h>
|
||||
#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
|
||||
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.println("\n Starting");
|
||||
|
||||
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
|
||||
WiFiManager wifiManager;
|
||||
|
||||
//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.setTimeout(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);
|
||||
|
||||
if (!wifiManager.startConfigPortal("OnDemandAP")) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(3000);
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.reset();
|
||||
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,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( ¶m_str );
|
||||
wm.addParameter( ¶m_float );
|
||||
wm.addParameter( ¶m_int );
|
||||
wm.addParameter( ¶m_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() {
|
||||
}
|
||||
@@ -6,15 +6,158 @@
|
||||
<title>{v}</title>
|
||||
<!-- /HTTP_HEAD -->
|
||||
<!-- HTTP_STYLE -->
|
||||
<style>
|
||||
.c{text-align: center;}
|
||||
div,input{padding:5px;font-size:1em;}
|
||||
input{width:95%;}
|
||||
body{text-align: center;font-family:verdana;}
|
||||
button{border:0;border-radius:0.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%;}
|
||||
.q{float: right;width: 64px;text-align: right;}
|
||||
.l{background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==") no-repeat left center;background-size: 1em;}
|
||||
</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;
|
||||
font-family: verdana
|
||||
}
|
||||
.wrap {
|
||||
text-align:left;
|
||||
display:inline-block;
|
||||
min-width:260px;
|
||||
}
|
||||
div,
|
||||
input {
|
||||
padding: 5px;
|
||||
font-size: 1em;
|
||||
}
|
||||
input {
|
||||
width: 95%;
|
||||
margin:5px 0;
|
||||
}
|
||||
button {
|
||||
border: 0;
|
||||
border-radius: .3rem;
|
||||
background-color: #9933CC;
|
||||
color: #fff;
|
||||
line-height: 2.4rem;
|
||||
font-size: 1.2rem;
|
||||
width: 100%;
|
||||
}
|
||||
a {
|
||||
color: #000;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
color: #9933CC;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.h {
|
||||
display: none;
|
||||
}
|
||||
.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=');
|
||||
}
|
||||
@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 {
|
||||
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: #9933CC;
|
||||
}
|
||||
.msg.P h4 {
|
||||
color: #9933CC;
|
||||
}
|
||||
/*.msg.S {
|
||||
border-left-color: #5cb85c;
|
||||
}
|
||||
.msg.S h4 {
|
||||
color: #5cb85c;
|
||||
}*/
|
||||
.msg.D {
|
||||
border-left-color: #dc3630;
|
||||
}
|
||||
.msg.D h4 {
|
||||
color: #dc3630;
|
||||
}
|
||||
|
||||
dt {
|
||||
font-weight: bold;
|
||||
}
|
||||
dd {
|
||||
margin: 0;
|
||||
padding: 0 0 0.5em 0;
|
||||
}
|
||||
td {
|
||||
vertical-align: top;
|
||||
}
|
||||
button.D{
|
||||
background-color:#dc3630;
|
||||
}
|
||||
|
||||
</style>
|
||||
<!-- /HTTP_STYLE -->
|
||||
<!-- HTTP_SCRIPT -->
|
||||
<script>
|
||||
@@ -23,56 +166,133 @@
|
||||
<!-- /HTTP_SCRIPT -->
|
||||
<!-- HTTP_HEAD_END -->
|
||||
</head>
|
||||
<body>
|
||||
<div style="text-align:left;display:inline-block;min-width:260px;">
|
||||
<body class="invert">
|
||||
<div class='wrap'>
|
||||
<!-- <div class='wrap ql qinv'> -->
|
||||
<!-- /HTTP_HEAD_END -->
|
||||
|
||||
<!--
|
||||
<div><a href='#' onclick='c(this)'>{v}</a> {r}% {i}</div>
|
||||
<div><a href='#' onclick='c(this)'>{v}</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAKCAMAAAC+Ge+yAAAACVBMVEUAAAC7u7v///9etNz6AAAAI0lEQVQI133GsQ3AMAAEoXv2H9qNJacKFbEaWTQJ+uQB/nMdEaYAXeJkZ9AAAAAASUVORK5CYII='/></div>
|
||||
<div><a href='#' onclick='c(this)'>Vila17</a> 95% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAADFBMVEUAAAAAtgD///8AAADV1YIHAAAAA3RSTlMAAAD6dsTeAAAAHUlEQVR4AWMAAmYgYGBkArHAAMoEYnQmMxSQywQAKvMA3+mlSFAAAAAASUVORK5CYII='/></div>
|
||||
<div><a href='#'>LilRid</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAABlBMVEUAAAD///+l2Z/dAAAAIklEQVR4AWNgZGRkAAIQBURQDEZAgM5kgAJGEAQDwkxkbQAOhgBBk64+mQAAAABJRU5ErkJggg=='/></div>
|
||||
<div><a href='#'>Marcelica</a> 100% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAMAAAC67D+PAAAACVBMVEUAAAC7u7v///9etNz6AAAAJ0lEQVR4AY3GsREAIBSDUD77D63x4tlKw0MdmD0ijTO9f6SFnv7YXB4qAIVn0xoMAAAAAElFTkSuQmCC'/></div>
|
||||
<div><a href='#'>PMica</a> 110% <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==' width="13px"/></div>
|
||||
-->
|
||||
|
||||
<!--style>
|
||||
.q{float: right;width: 64px;text-align: right;}
|
||||
.l{background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==") no-repeat left center;background-size: 1em;}
|
||||
</style-->
|
||||
|
||||
|
||||
<!-- SAMPLE -->
|
||||
<h2>/</h2><hR>
|
||||
<!-- /SAMPLE -->
|
||||
<!-- HTTP_PORTAL_OPTIONS -->
|
||||
<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>
|
||||
<!-- /HTTP_PORTAL_OPTIONS -->
|
||||
|
||||
<div><a href='#' onclick='c(this)'>{v}</a> <span class="q {i}">{r}%</span></div>
|
||||
<div><a href='#'>PMisa</a> <span class="q l">100%</span> </div>
|
||||
<div><a href='#'>Dragos_Networks</a> <span class="q l">10%</span> </div>
|
||||
<div><a href='#'>PMisa</a> <span class="q l">8%</span> </div>
|
||||
|
||||
<!-- HTTP_PORTAL_MENU[] -->
|
||||
<form action='/wifi' method='get'><button>Configure WiFi</button></form><br/>
|
||||
<form action='/0wifi' method='get'><button>Configure WiFi (No Scan)</button></form><br/>
|
||||
<form action='/info' method='get'><button>Info</button></form><br/>
|
||||
<form action='/param' method='get'><button>Setup</button></form><br/>
|
||||
<Hr><br/>
|
||||
<form action='/close' method='post'><button>Close</button></form><br/>
|
||||
<form action='/erase' method='post'><button class='D'>Erase</button></form><br/>
|
||||
<form action='/restart' method='post'><button>Restart</button></form><br/>
|
||||
<form action='/exit' method='post'><button>Exit</button></form><br/>
|
||||
<!-- /HTTP_PORTAL_MENU -->
|
||||
<!-- SAMPLE -->
|
||||
<h2>/wifi</h2><hr>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 01</a><div role='img' aria-label='88%' title='88%' class='q q-4 l'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 02</a><div role='img' aria-label='88%' title='88%' class='q q-4'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 03</a><div role='img' aria-label='60%' title='60%' class='q q-3 l'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 04</a><div role='img' aria-label='60%' title='60%' class='q q-3'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 05</a><div role='img' aria-label='60%' title='60%' class='q q-3'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 06</a><div role='img' aria-label='40%' title='40%' class='q q-2'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 07</a><div role='img' aria-label='40%' title='40%' class='q q-2 l'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 08</a><div role='img' aria-label='20%' title='20%' class='q q-1'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 09</a><div role='img' aria-label='20%' title='20%' class='q q-1'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 10</a><div role='img' aria-label='20%' title='20%' class='q q-4 l'></div><div class='q '>100%</div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 11</a><div role='img' aria-label='10%' title='10%' class='q q-3'></div><div class='q '>70%</div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 12</a><div role='img' aria-label='10%' title='10%' class='q q-1 l'></div><div class='q '>10%</div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 13</a><div role='img' aria-label='10%' title='10%' class='q q-0 h'></div><div class='q '>100%</div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 14</a><div class='q'>66%</div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 15</a><div class='q'>56%</div></div>
|
||||
<!-- /SAMPLE -->
|
||||
<!-- HTTP_ITEM -->
|
||||
<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>
|
||||
<div><a href='#p' onclick='c(this)'>{v}</a><div role='img' aria-label='{r}%' title='{r}%' class='q q-{q} {i}'></div></div>
|
||||
<!-- /HTTP_ITEM -->
|
||||
<!-- HTTP_FORM_START -->
|
||||
<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 type='password' placeholder='password'><br/>
|
||||
<form method='get' action='wifisave'><label for='s'>SSID</label><br/><input id='s' name='s' length=32 placeholder='SSID'><br/><label for='p'>Password</label><input id='p' name='p' length=64 type='password' placeholder='password'><br/>
|
||||
<!-- /HTTP_FORM_START -->
|
||||
<!-- SAMPLE -->
|
||||
<h3>custom parameter</h3><hr>
|
||||
<br/><label for='custom'>Label for Custom Param</label>
|
||||
<br/><input id='custom' name='custom' length='255' placeholder='placeholder' value='' {c}>
|
||||
<!-- /SAMPLE -->
|
||||
<!-- HTTP_FORM_LABEL -->
|
||||
<br/><label for='{i}'>{p}</label>
|
||||
<!-- /HTTP_FORM_LABEL -->
|
||||
<!-- HTTP_FORM_PARAM -->
|
||||
<br/><input id='{i}' name='{n}' length='{l}' placeholder='{p}' value='{v}' {c}>
|
||||
<!-- /HTTP_FORM_PARAM -->
|
||||
<!-- HTTP_FORM_END -->
|
||||
<br/><button type='submit'>save</button></form>
|
||||
<br/><button type='submit'>Save</button></form>
|
||||
<!-- /HTTP_FORM_END -->
|
||||
<!-- HTTP_SCAN_LINK -->
|
||||
<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>
|
||||
<br/><form action='/wifi' method='get'><button>Refresh</button></form>
|
||||
<!-- /HTTP_SCAN_LINK -->
|
||||
<!-- HTTP_SAVED -->
|
||||
<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>
|
||||
<div class='msg'><h4>Saving Credentials</h4>Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>
|
||||
<!-- /HTTP_SAVED -->
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- HTTP_STATUS_ON -->
|
||||
<div class='msg P'><strong>Connected</strong> to {v}<br/><em><small>with IP {i}</small></em></div>
|
||||
<!-- /HTTP_STATUS_ON -->
|
||||
<!-- HTTP_STATUS_OFF -->
|
||||
<div class='msg {c}'><strong>Not Connected</strong> to {v}{r}</div>
|
||||
<!-- /HTTP_STATUS_OFF -->
|
||||
<!-- sample -->
|
||||
<div class='msg D'><strong>Not Connected</strong> to apname
|
||||
<!-- /sample -->
|
||||
<!-- HTTP_STATUS_OFFPW -->
|
||||
<br/>Authentication Failure
|
||||
<!-- /HTTP_STATUS_OFFPW -->
|
||||
<!-- HTTP_STATUS_OFFNOAP -->
|
||||
<br/>AP not found
|
||||
<!-- /HTTP_STATUS_OFFNOAP> -->
|
||||
<!-- HTTP_STATUS_OFFFAIL -->
|
||||
<br/>Could not Connect
|
||||
<!-- /HTTP_STATUS_OFFFAIL -->
|
||||
</div>
|
||||
<!-- HTTP_STATUS_NONE -->
|
||||
<div class='msg'>No AP set</div>
|
||||
<!-- /HTTP_STATUS_NONE -->
|
||||
<!-- SAMPLE -->
|
||||
<div class='msg P'><h4>Header</h4>content</div>
|
||||
<!-- /SAMPLE -->
|
||||
<!-- SAMPLE -->
|
||||
<h2>/info</h3><hr>
|
||||
<dl>
|
||||
<dt>Chip ID</dt><dd>123456</dd>
|
||||
<dt>Flash Chip ID</dt><dd>1234556</dd>
|
||||
<dt>IDE Flash Size</dt><dd>4194304 bytes</dd>
|
||||
<dt>Real Flash Size</dt><dd>4194304 bytes</dd>
|
||||
<dt>Empty</dt><dd></dd>
|
||||
<dt>Soft AP IP</dt><dd>192.168.4.1</dd>
|
||||
<dt>Soft AP MAC</dt><dd>00:00:00:00:00:00</dd>
|
||||
<dt>Station MAC</dt><dd>00:00:00:00:00:00</dd>
|
||||
</dl>
|
||||
<!-- /SAMPLE -->
|
||||
<!-- HTTP_HELP -->
|
||||
<br/><h3>Available Pages</h3><hr>
|
||||
<table class='table'>
|
||||
<thead><tr><th>Page</th><th>Function</th></tr></thead><tbody>
|
||||
<tr><td><a href='/'>/</a></td>
|
||||
<td>Menu page.</td></tr>
|
||||
<tr><td><a href='/wifi'>/wifi</a></td>
|
||||
<td>Show WiFi scan results and enter WiFi configuration.(/0wifi noscan)</td></tr>
|
||||
<tr><td><a href='/wifisave'>/wifisave</a></td>
|
||||
<td>Save WiFi configuration information and configure device. Needs variables supplied.</td></tr>
|
||||
<tr><td><a href='/close'>/close</a></td>
|
||||
<td>Close the configuration server and configuration WiFi network.</td></tr>
|
||||
<tr><td><a href='/info'>/info</a></td>
|
||||
<td>Information page</td></tr>
|
||||
<tr><td><a href='/close'>/close</a></td>
|
||||
<td>Close the captiveportal popup,configportal will remain active</td></tr>
|
||||
<tr><td><a href='/exit'>/exit</a></td>
|
||||
<td>Exit Config Portal, configportal will close</td></tr>
|
||||
<tr><td><a href='/restart'>/restart</a></td>
|
||||
<td>Reboot the device</td></tr>
|
||||
<tr><td><a href='/erase'>/erase</a></td>
|
||||
<td>Erase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.</td></tr>
|
||||
</table>
|
||||
<p/>More information about WiFiManager at <a href='https://github.com/tzapu/WiFiManager'>https://github.com/tzapu/WiFiManager</a>
|
||||
<!-- /HTTP_HELP -->
|
||||
<!-- HTTP_END -->
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
@@ -0,0 +1,176 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||||
<title>Config ESP</title>
|
||||
<script>
|
||||
|
||||
function c(l,e) {
|
||||
console.log(l);
|
||||
// preventDefault();
|
||||
document.getElementById('s').value = l.innerText || l.textContent;
|
||||
// document.location.href = document.location +"#wmform";
|
||||
document.getElementById('p').focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.c,
|
||||
body {
|
||||
text-align: center
|
||||
}
|
||||
|
||||
div,
|
||||
input {
|
||||
padding: 5px;
|
||||
font-size: 1em
|
||||
}
|
||||
|
||||
input {
|
||||
width: 95%
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: verdana
|
||||
}
|
||||
|
||||
button {
|
||||
border: 0;
|
||||
border-radius: .3rem;
|
||||
background-color: #1fa3ec;
|
||||
color: #fff;
|
||||
line-height: 2.4rem;
|
||||
font-size: 1.2rem;
|
||||
width: 100%
|
||||
}
|
||||
|
||||
a {
|
||||
color: #000;
|
||||
font-weight: 700;
|
||||
text-decoration: none
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #1fa3ec;
|
||||
text-decoration: underline
|
||||
}
|
||||
|
||||
.q {
|
||||
height: 16px;
|
||||
margin: 0;
|
||||
padding: 0 5px;
|
||||
text-align: right;
|
||||
min-width: 38px
|
||||
}
|
||||
|
||||
.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
|
||||
}
|
||||
|
||||
.qr .q {
|
||||
float: right
|
||||
}
|
||||
|
||||
.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;
|
||||
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAAQCAMAAADeZIrLAAAAJFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADHJj5lAAAAC3RSTlMAIjN3iJmqu8zd7vF8pzcAAABsSURBVHja7Y1BCsAwCASNSVo3/v+/BUEiXnIoXkoX5jAQMxTHzK9cVSnvDxwD8bFx8PhZ9q8FmghXBhqA1faxk92PsxvRc2CCCFdhQCbRkLoAQ3q/wWUBqG35ZxtVzW4Ed6LngPyBU2CobdIDQ5oPWI5nCUwAAAAASUVORK5CYII=');
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- classes, left/right invert -->
|
||||
<div class="qr" style='text-align:left;display:inline-block;min-width:260px;'>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 01</a><div role='img' aria-label='88%' title='88%' class='q q-4 l'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 02</a><div role='img' aria-label='88%' title='88%' class='q q-4'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 03</a><div role='img' aria-label='88%' title='88%' class='q q-3'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 04</a><div role='img' aria-label='88%' title='88%' class='q q-3'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 05</a><div role='img' aria-label='88%' title='88%' class='q q-3'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 06</a><div role='img' aria-label='88%' title='88%' class='q q-2'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 07</a><div role='img' aria-label='88%' title='88%' class='q q-2'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 08</a><div role='img' aria-label='88%' title='88%' class='q q-1'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 09</a><div role='img' aria-label='88%' title='88%' class='q q-1'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 10</a><div role='img' aria-label='88%' title='88%' class='q q-1'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 11</a><div role='img' aria-label='88%' title='88%' class='q q-0'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 12</a><div role='img' aria-label='88%' title='88%' class='q q-0'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 13</a><div role='img' aria-label='88%' title='88%' class='q q-0'></div></div>
|
||||
<div><a href='#p' onclick='c(this)'>Acccess Point 14</a><div role='img' aria-label='88%' title='88%' class='q q-0 l'></div></div>
|
||||
<br/>
|
||||
<form id="wmform" method='get' action='wifisave'>
|
||||
<input id='s' name='s' length=32 placeholder='SSID'>
|
||||
<br/>
|
||||
<input id='p' name='p' length=64 type='password' placeholder='password'>
|
||||
<br/>
|
||||
<br/>
|
||||
<input id='server' name='server' length=4 placeholder='mqtt server' value=''>
|
||||
<br/>
|
||||
<input id='port' name='port' length=5 placeholder='mqtt port' value='8080'>
|
||||
<br/>
|
||||
<input id='blynk' name='blynk' length=3 placeholder='blynk token' value='YOUR_BLYNK_TOKEN'>
|
||||
<br/>
|
||||
<br/>
|
||||
<input id='ip' name='ip' length=15 placeholder='Static IP' value='10.0.1.56'>
|
||||
<br/>
|
||||
<input id='gw' name='gw' length=15 placeholder='Static Gateway' value='10.0.1.1'>
|
||||
<br/>
|
||||
<input id='sn' name='sn' length=15 placeholder='Subnet' value='255.255.255.0'>
|
||||
<br/>
|
||||
<br/>
|
||||
<button type='submit'>save</button>
|
||||
</form>
|
||||
<br/>
|
||||
<div class="c"><a href="/wifi">Scan</a></div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+21
-5
@@ -1,13 +1,29 @@
|
||||
{
|
||||
"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"
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": "espressif8266",
|
||||
"version": "0.14"
|
||||
"platforms":
|
||||
[
|
||||
"espressif8266",
|
||||
"espressif32"
|
||||
],
|
||||
"version": "1.0.0"
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
name=WiFiManager
|
||||
version=0.14
|
||||
author=tzapu
|
||||
maintainer=tzapu
|
||||
sentence=ESP8266 WiFi Connection manager with fallback web configuration portal
|
||||
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
|
||||
architectures=esp8266,esp32
|
||||
|
||||
+327
@@ -0,0 +1,327 @@
|
||||
/**
|
||||
* strings_en.h
|
||||
* engligh strings for
|
||||
* WiFiManager, a library for the ESP8266/Arduino platform
|
||||
* for configuration of WiFi credentials using a Captive Portal
|
||||
*
|
||||
* @author Creator tzapu
|
||||
* @author tablatronix
|
||||
* @version 0.0.0
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
#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!
|
||||
|
||||
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 class='{c}'><div class='wrap'>";
|
||||
|
||||
const char HTTP_ROOT_MAIN[] PROGMEM = "<h1>{v}</h1><h3>WiFiManager</h3>";
|
||||
const char * const HTTP_PORTAL_MENU[] PROGMEM = {
|
||||
"<form action='/wifi' method='get'><button>Configure WiFi</button></form><br/>\n", // MENU_WIFI
|
||||
"<form action='/0wifi' method='get'><button>Configure WiFi (No Scan)</button></form><br/>\n", // MENU_WIFINOSCAN
|
||||
"<form action='/info' method='get'><button>Info</button></form><br/>\n", // MENU_INFO
|
||||
"<form action='/param' method='get'><button>Setup</button></form><br/>\n",//MENU_PARAM
|
||||
"<form action='/close' method='get'><button>Close</button></form><br/>\n", // MENU_CLOSE
|
||||
"<form action='/restart' method='get'><button>Restart</button></form><br/>\n",// MENU_RESTART
|
||||
"<form action='/exit' method='get'><button>Exit</button></form><br/>\n", // MENU_EXIT
|
||||
"<form action='/erase' method='get'><button class='D'>Erase</button></form><br/>\n", // MENU_ERASE
|
||||
"<hr><br/>" // MENU_SEP
|
||||
};
|
||||
|
||||
// const char HTTP_PORTAL_OPTIONS[] PROGMEM = strcat(HTTP_PORTAL_MENU[0] , HTTP_PORTAL_MENU[3] , HTTP_PORTAL_MENU[7]);
|
||||
const char HTTP_PORTAL_OPTIONS[] PROGMEM = "";
|
||||
const char HTTP_ITEM_QI[] PROGMEM = "<div role='img' aria-label='{r}%' title='{r}%' class='q q-{q} {i} {h}'></div>"; // rssi icons
|
||||
const char HTTP_ITEM_QP[] PROGMEM = "<div class='q {h}'>{r}%</div>"; // rssi percentage
|
||||
const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a>{qi}{qp}</div>"; // {q} = HTTP_ITEM_QI, {r} = HTTP_ITEM_QP
|
||||
// const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> {R} {r}% {q} {e}</div>"; // test all tokens
|
||||
|
||||
const char HTTP_FORM_START[] PROGMEM = "<form method='POST' action='{v}'>";
|
||||
const char HTTP_FORM_WIFI[] PROGMEM = "<label for='s'>SSID</label><input id='s' name='s' maxlength='32' autocorrect='off' autocapitalize='none' placeholder='{v}'><br/><label for='p'>Password</label><input id='p' name='p' maxlength='64' type='password' placeholder=''>";
|
||||
const char HTTP_FORM_WIFI_END[] PROGMEM = "";
|
||||
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_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>";
|
||||
const char HTTP_PARAMSAVED[] PROGMEM = "<div class='msg'>Saved<br/></div>";
|
||||
const char HTTP_END[] PROGMEM = "</div></body></html>";
|
||||
const char HTTP_ERASEBTN[] PROGMEM = "<br/><form action='/erase' method='get'><button class='D'>Erase WiFi Config</button></form>";
|
||||
|
||||
const char HTTP_STATUS_ON[] PROGMEM = "<div class='msg P'><strong>Connected</strong> to {v}<br/><em><small>with IP {i}</small></em></div>";
|
||||
const char HTTP_STATUS_OFF[] PROGMEM = "<div class='msg {c}'><strong>Not Connected</strong> to {v}{r}</div>";
|
||||
const char HTTP_STATUS_OFFPW[] PROGMEM = "<br/>Authentication Failure"; // STATION_WRONG_PASSWORD, no eps32
|
||||
const char HTTP_STATUS_OFFNOAP[] PROGMEM = "<br/>AP not found"; // WL_NO_SSID_AVAIL
|
||||
const char HTTP_STATUS_OFFFAIL[] PROGMEM = "<br/>Could not Connect"; // WL_CONNECT_FAILED
|
||||
const char HTTP_STATUS_NONE[] PROGMEM = "<div class='msg'>No AP set</div>";
|
||||
const char HTTP_BR[] PROGMEM = "<br/>";
|
||||
|
||||
const char HTTP_STYLE[] PROGMEM = "<style>"
|
||||
".c,body{text-align:center;font-family:verdana}div,input{padding:5px;font-size:1em}input{width:95%;margin:5px 0}button{cursor:pointer;border:0;border-radius:.3rem;background-color:#1fa3ec;color:#fff;line-height:2.4rem;font-size:1.2rem;width:100%}"
|
||||
".wrap {text-align:left;display:inline-block;min-width:260px}"
|
||||
// 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}.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:#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:#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 =
|
||||
"<br/><h3>Available Pages</h3><hr>"
|
||||
"<table class='table'>"
|
||||
"<thead><tr><th>Page</th><th>Function</th></tr></thead><tbody>"
|
||||
"<tr><td><a href='/'>/</a></td>"
|
||||
"<td>Menu page.</td></tr>"
|
||||
"<tr><td><a href='/wifi'>/wifi</a></td>"
|
||||
"<td>Show WiFi scan results and enter WiFi configuration.(/0wifi noscan)</td></tr>"
|
||||
"<tr><td><a href='/wifisave'>/wifisave</a></td>"
|
||||
"<td>Save WiFi configuration information and configure device. Needs variables supplied.</td></tr>"
|
||||
"<tr><td><a href='/param'>/param</a></td>"
|
||||
"<td>Parameter page</td></tr>"
|
||||
"<tr><td><a href='/info'>/info</a></td>"
|
||||
"<td>Information page</td></tr>"
|
||||
"<tr><td><a href='/close'>/close</a></td>"
|
||||
"<td>Close the captiveportal popup,configportal will remain active</td></tr>"
|
||||
"<tr><td><a href='/exit'>/exit</a></td>"
|
||||
"<td>Exit Config Portal, configportal will close</td></tr>"
|
||||
"<tr><td><a href='/restart'>/restart</a></td>"
|
||||
"<td>Reboot the device</td></tr>"
|
||||
"<tr><td><a href='/erase'>/erase</a></td>"
|
||||
"<td>Erase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.</td></tr>"
|
||||
"</table>"
|
||||
"<p/>More information about WiFiManager at <a href='https://github.com/tzapu/WiFiManager'>https://github.com/tzapu/WiFiManager</a>.";
|
||||
|
||||
#ifdef JSTEST
|
||||
const char HTTP_JS[] PROGMEM =
|
||||
"<script>function postAjax(url, data, success) {"
|
||||
" var params = typeof data == 'string' ? data : Object.keys(data).map("
|
||||
" function(k){ return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) }"
|
||||
" ).join('&');"
|
||||
" var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject(\"Microsoft.XMLHTTP\");"
|
||||
" xhr.open('POST', url);"
|
||||
" xhr.onreadystatechange = function() {"
|
||||
" if (xhr.readyState>3 && xhr.status==200) { success(xhr.responseText); }"
|
||||
" };"
|
||||
" xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');"
|
||||
" xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');"
|
||||
" xhr.send(params);"
|
||||
" return xhr;}"
|
||||
"postAjax('/status', 'p1=1&p2=Hello+World', function(data){ console.log(data); });"
|
||||
"postAjax('/status', { p1: 1, p2: 'Hello World' }, function(data){ console.log(data); });"
|
||||
"</script>";
|
||||
#endif
|
||||
|
||||
// Info html
|
||||
#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_aphost[] PROGMEM = "<dt>Acccess Point Hostname</dt><dd>{1}</dd>";
|
||||
#else
|
||||
const char HTTP_INFO_esphead[] PROGMEM = "<h3>esp8266</h3><hr><dl>";
|
||||
const char HTTP_INFO_flashsize[] PROGMEM = "<dt>Real Flash Size</dt><dd>{1} bytes</dd>";
|
||||
const char HTTP_INFO_fchipid[] PROGMEM = "<dt>Flash Chip ID</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_corever[] PROGMEM = "<dt>Core Version</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_bootver[] PROGMEM = "<dt>Boot Version</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_memsketch[] PROGMEM = "<dt>Memory - Sketch Size</dt><dd>Used / Total bytes<br/>{1} / {2}";
|
||||
const char HTTP_INFO_memsmeter[] PROGMEM = "<br/><progress value='{1}' max='{2}'></progress></dd>";
|
||||
const char HTTP_INFO_lastreset[] PROGMEM = "<dt>Last reset reason</dt><dd>{1}</dd>";
|
||||
#endif
|
||||
|
||||
const char HTTP_INFO_freeheap[] PROGMEM = "<dt>Memory - Free Heap</dt><dd>{1} bytes available</dd>";
|
||||
const char HTTP_INFO_wifihead[] PROGMEM = "<br/><h3>WiFi</h3><hr>";
|
||||
const char HTTP_INFO_uptime[] PROGMEM = "<dt>Uptime</dt><dd>{1} Mins {2} Secs</dd>";
|
||||
const char HTTP_INFO_chipid[] PROGMEM = "<dt>Chip ID</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_idesize[] PROGMEM = "<dt>Flash Size</dt><dd>{1} bytes</dd>";
|
||||
const char HTTP_INFO_sdkver[] PROGMEM = "<dt>SDK Version</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_cpufreq[] PROGMEM = "<dt>CPU Frequency</dt><dd>{1}MHz</dd>";
|
||||
const char HTTP_INFO_apip[] PROGMEM = "<dt>Access Point IP</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_apmac[] PROGMEM = "<dt>Access Point MAC</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_apssid[] PROGMEM = "<dt>SSID</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_apbssid[] PROGMEM = "<dt>BSSID</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_staip[] PROGMEM = "<dt>Station IP</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_stagw[] PROGMEM = "<dt>Station Gateway</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_stasub[] PROGMEM = "<dt>Station Subnet</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_dnss[] PROGMEM = "<dt>DNS Server</dt><dd>{1}</dd>";
|
||||
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° / {2} F°</dd>";
|
||||
|
||||
// Strings
|
||||
const char S_y[] PROGMEM = "Yes";
|
||||
const char S_n[] PROGMEM = "No";
|
||||
const char S_enable[] PROGMEM = "Enabled";
|
||||
const char S_disable[] PROGMEM = "Disabled";
|
||||
const char S_GET[] PROGMEM = "GET";
|
||||
const char S_POST[] PROGMEM = "POST";
|
||||
const char S_NA[] PROGMEM = "Unknown";
|
||||
|
||||
const char S_titlewifisaved[] PROGMEM = "Credentials Saved";
|
||||
const char S_titlewifi[] PROGMEM = "Config ESP";
|
||||
const char S_titleinfo[] PROGMEM = "Info";
|
||||
const char S_titleparam[] PROGMEM = "Setup";
|
||||
const char S_titleparamsaved[] PROGMEM = "Setup Saved";
|
||||
const char S_titleexit[] PROGMEM = "Exit";
|
||||
const char S_titlereset[] PROGMEM = "Reset";
|
||||
const char S_titleerase[] PROGMEM = "Erase";
|
||||
const char S_titleclose[] PROGMEM = "Close";
|
||||
const char S_options[] PROGMEM = "options";
|
||||
const char S_nonetworks[] PROGMEM = "No networks found. Refresh to scan again.";
|
||||
const char S_staticip[] PROGMEM = "Static IP";
|
||||
const char S_staticgw[] PROGMEM = "Static Gateway";
|
||||
const char S_staticdns[] PROGMEM = "Static DNS";
|
||||
const char S_subnet[] PROGMEM = "Subnet";
|
||||
const char S_exiting[] PROGMEM = "Exiting";
|
||||
const char S_resetting[] PROGMEM = "Module will reset in a few seconds.";
|
||||
const char S_closing[] PROGMEM = "You can close the page, portal will continue to run";
|
||||
const char S_error[] PROGMEM = "An Error Occured";
|
||||
const char S_notfound[] PROGMEM = "File Not Found\n\n";
|
||||
const char S_uri[] PROGMEM = "URI: ";
|
||||
const char S_method[] PROGMEM = "\nMethod: ";
|
||||
const char S_args[] PROGMEM = "\nArguments: ";
|
||||
const char S_parampre[] PROGMEM = "param_";
|
||||
|
||||
// debug strings
|
||||
const char D_HR[] PROGMEM = "--------------------";
|
||||
|
||||
// END WIFI_MANAGER_OVERRIDE_STRINGS
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// DO NOT EDIT BELOW THIS LINE
|
||||
|
||||
const uint8_t _nummenutokens = 9;
|
||||
const char * const _menutokens[9] PROGMEM = {
|
||||
"wifi",
|
||||
"wifinoscan",
|
||||
"info",
|
||||
"param",
|
||||
"close",
|
||||
"restart",
|
||||
"exit",
|
||||
"erase",
|
||||
"sep"
|
||||
};
|
||||
|
||||
const char R_root[] PROGMEM = "/";
|
||||
const char R_wifi[] PROGMEM = "/wifi";
|
||||
const char R_wifinoscan[] PROGMEM = "/0wifi";
|
||||
const char R_wifisave[] PROGMEM = "/wifisave";
|
||||
const char R_info[] PROGMEM = "/info";
|
||||
const char R_param[] PROGMEM = "/param";
|
||||
const char R_paramsave[] PROGMEM = "/paramsave";
|
||||
const char R_restart[] PROGMEM = "/restart";
|
||||
const char R_exit[] PROGMEM = "/exit";
|
||||
const char R_close[] PROGMEM = "/close";
|
||||
const char R_erase[] PROGMEM = "/erase";
|
||||
const char R_status[] PROGMEM = "/status";
|
||||
|
||||
|
||||
//Strings
|
||||
const char S_ip[] PROGMEM = "ip";
|
||||
const char S_gw[] PROGMEM = "gw";
|
||||
const char S_sn[] PROGMEM = "sn";
|
||||
const char S_dns[] PROGMEM = "dns";
|
||||
|
||||
// softap ssid default prefix
|
||||
#ifdef ESP8266
|
||||
const char S_ssidpre[] PROGMEM = "ESP";
|
||||
#elif defined(ESP32)
|
||||
const char S_ssidpre[] PROGMEM = "ESP32";
|
||||
#else
|
||||
const char S_ssidpre[] PROGMEM = "WM";
|
||||
#endif
|
||||
|
||||
//Tokens
|
||||
//@todo consolidate and reduce
|
||||
const char T_ss[] PROGMEM = "{"; // token start sentinel
|
||||
const char T_es[] PROGMEM = "}"; // token end sentinel
|
||||
const char T_1[] PROGMEM = "{1}"; // @token 1
|
||||
const char T_2[] PROGMEM = "{2}"; // @token 2
|
||||
const char T_v[] PROGMEM = "{v}"; // @token v
|
||||
const char T_I[] PROGMEM = "{I}"; // @token I
|
||||
const char T_i[] PROGMEM = "{i}"; // @token i
|
||||
const char T_n[] PROGMEM = "{n}"; // @token n
|
||||
const char T_p[] PROGMEM = "{p}"; // @token p
|
||||
const char T_t[] PROGMEM = "{t}"; // @token t
|
||||
const char T_l[] PROGMEM = "{l}"; // @token l
|
||||
const char T_c[] PROGMEM = "{c}"; // @token c
|
||||
const char T_e[] PROGMEM = "{e}"; // @token e
|
||||
const char T_q[] PROGMEM = "{q}"; // @token q
|
||||
const char T_r[] PROGMEM = "{r}"; // @token r
|
||||
const char T_R[] PROGMEM = "{R}"; // @token R
|
||||
const char T_h[] PROGMEM = "{h}"; // @token h
|
||||
|
||||
// http
|
||||
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
|
||||
{
|
||||
"WL_IDLE_STATUS", // 0 STATION_IDLE
|
||||
"WL_NO_SSID_AVAIL", // 1 STATION_NO_AP_FOUND
|
||||
"WL_SCAN_COMPLETED", // 2
|
||||
"WL_CONNECTED", // 3 STATION_GOT_IP
|
||||
"WL_CONNECT_FAILED", // 4 STATION_CONNECT_FAIL, STATION_WRONG_PASSWORD(NI)
|
||||
"WL_CONNECTION_LOST", // 5
|
||||
"WL_DISCONNECTED", // 6
|
||||
"WL_STATION_WRONG_PASSWORD" // 7 KLUDGE
|
||||
};
|
||||
|
||||
#ifdef ESP32
|
||||
const char * const AUTH_MODE_NAMES[] PROGMEM
|
||||
{
|
||||
"OPEN",
|
||||
"WEP",
|
||||
"WPA_PSK",
|
||||
"WPA2_PSK",
|
||||
"WPA_WPA2_PSK",
|
||||
"WPA2_ENTERPRISE",
|
||||
"MAX"
|
||||
};
|
||||
#elif defined(ESP8266)
|
||||
const char * const AUTH_MODE_NAMES[] PROGMEM
|
||||
{
|
||||
"",
|
||||
"",
|
||||
"WPA_PSK", // 2 ENC_TYPE_TKIP
|
||||
"",
|
||||
"WPA2_PSK", // 4 ENC_TYPE_CCMP
|
||||
"WEP", // 5 ENC_TYPE_WEP
|
||||
"",
|
||||
"OPEN", //7 ENC_TYPE_NONE
|
||||
"WPA_WPA2_PSK", // 8 ENC_TYPE_AUTO
|
||||
};
|
||||
#endif
|
||||
|
||||
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
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
function build_examples()
|
||||
{
|
||||
excludes=("$@")
|
||||
# track the exit code for this platform
|
||||
local exit_code=0
|
||||
# loop through results and add them to the array
|
||||
@@ -19,6 +20,14 @@ function build_examples()
|
||||
# store the filename for the example without the path
|
||||
local example_file=$(basename $example)
|
||||
|
||||
# skip files listed as excludes
|
||||
for exclude in "${excludes[@]}"; do
|
||||
if [ "${example_file}" == "${exclude}" ] ; then
|
||||
echo ">>>>>>>>>>>>>>>>>>>>>>>> Skipping ${example_file} <<<<<<<<<<<<<<<<<<<<<<<<<<"
|
||||
continue 2
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$example_file: "
|
||||
local sketch="$example_dir/$example_file"
|
||||
echo "$sketch"
|
||||
|
||||
Reference in New Issue
Block a user