mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
Merge branch 'master' into esp32s2
This commit is contained in:
@@ -15,7 +15,7 @@ https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst
|
||||
### Basic Infos
|
||||
|
||||
#### Hardware
|
||||
WiFimanager Branch/Release: Development
|
||||
WiFimanager Branch/Release: Master
|
||||
|
||||
Esp8266/Esp32:
|
||||
|
||||
@@ -36,7 +36,7 @@ Additional libraries:
|
||||
### Sketch
|
||||
|
||||
```cpp
|
||||
|
||||
#BEGIN
|
||||
#include <Arduino.h>
|
||||
|
||||
void setup() {
|
||||
@@ -46,6 +46,7 @@ void setup() {
|
||||
void loop() {
|
||||
|
||||
}
|
||||
#END
|
||||
```
|
||||
|
||||
### Debug Messages
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
name: Compile examples for ESP8266
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
example:
|
||||
- "examples/AutoConnect/AutoConnectWithFSParametersAndCustomIP/AutoConnectWithFSParametersAndCustomIP.ino"
|
||||
- "examples/AutoConnect/AutoConnect.ino"
|
||||
- "examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino"
|
||||
- "examples/AutoConnect/AutoConnectWithFeedbackLED/AutoConnectWithFeedbackLED.ino"
|
||||
- "examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino"
|
||||
- "examples/NonBlocking/AutoConnectNonBlockingwParams/AutoConnectNonBlockingwParams.ino"
|
||||
- "examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino"
|
||||
- "examples/Basic/Basic.ino"
|
||||
- "examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino"
|
||||
- "examples/Advanced/Advanced.ino"
|
||||
- "examples/Old_examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino"
|
||||
- "examples/Old_examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino"
|
||||
- "examples/Old_examples/AutoConnectWithReset/AutoConnectWithReset.ino"
|
||||
- "examples/Old_examples/AutoConnectWithTimeout/AutoConnectWithTimeout.ino"
|
||||
- "examples/ParamsChildClass/ParamsChildClass.ino"
|
||||
- "examples/OnDemand/OnDemandConfigPortal/OnDemandConfigPortal.ino"
|
||||
- "examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Cache pip
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||
restore-keys: ${{ runner.os }}-pip-
|
||||
- name: Cache PlatformIO
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.platformio
|
||||
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
- name: Install PlatformIO
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install --upgrade platformio
|
||||
- name: Install 3rd party dependecies
|
||||
run: |
|
||||
pio lib -g install \
|
||||
https://github.com/tzapu/WiFiManager \
|
||||
https://github.com/bblanchon/ArduinoJson \
|
||||
https://github.com/knolleary/pubsubclient
|
||||
|
||||
- name: Run PlatformIO Examples
|
||||
run: pio ci --board=nodemcuv2
|
||||
env:
|
||||
PLATFORMIO_CI_SRC: ${{ matrix.example }}
|
||||
+1
-12
@@ -13,22 +13,11 @@ before_install:
|
||||
install:
|
||||
- ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager
|
||||
- arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json,http://dl.espressif.com/dl/package_esp32_index.json" --save-prefs
|
||||
- arduino --install-library "ArduinoJson:5.13.2"
|
||||
- arduino --install-library "ArduinoJson:6.18.0"
|
||||
- arduino --install-boards esp8266:esp8266
|
||||
- arduino --pref "compiler.warning_level=all" --save-prefs
|
||||
# install esp32
|
||||
- arduino --install-boards esp32: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"
|
||||
|
||||
@@ -6,7 +6,7 @@ ESP8266 WiFi Connection manager with fallback web configuration portal
|
||||
|
||||
:warning: This Documentation is out of date, see notes below
|
||||
|
||||
[](https://travis-ci.org/tzapu/WiFiManager)
|
||||
[](https://travis-ci.com/tzapu/WiFiManager)
|
||||
|
||||
[](https://www.ardu-badge.com/WiFiManager)
|
||||
|
||||
@@ -179,7 +179,7 @@ lib_deps =
|
||||
```
|
||||
[env]
|
||||
lib_deps =
|
||||
https://github.com/tzapu/WiFiManager.git#development
|
||||
https://github.com/tzapu/WiFiManager.git
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
+89
-46
@@ -94,26 +94,26 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) {
|
||||
strncpy(_value, defaultValue, _length);
|
||||
}
|
||||
}
|
||||
const char* WiFiManagerParameter::getValue() {
|
||||
const char* WiFiManagerParameter::getValue() const {
|
||||
// Serial.println(printf("Address of _value is %p\n", (void *)_value));
|
||||
return _value;
|
||||
}
|
||||
const char* WiFiManagerParameter::getID() {
|
||||
const char* WiFiManagerParameter::getID() const {
|
||||
return _id;
|
||||
}
|
||||
const char* WiFiManagerParameter::getPlaceholder() {
|
||||
const char* WiFiManagerParameter::getPlaceholder() const {
|
||||
return _label;
|
||||
}
|
||||
const char* WiFiManagerParameter::getLabel() {
|
||||
const char* WiFiManagerParameter::getLabel() const {
|
||||
return _label;
|
||||
}
|
||||
int WiFiManagerParameter::getValueLength() {
|
||||
int WiFiManagerParameter::getValueLength() const {
|
||||
return _length;
|
||||
}
|
||||
int WiFiManagerParameter::getLabelPlacement() {
|
||||
int WiFiManagerParameter::getLabelPlacement() const {
|
||||
return _labelPlacement;
|
||||
}
|
||||
const char* WiFiManagerParameter::getCustomHTML() {
|
||||
const char* WiFiManagerParameter::getCustomHTML() const {
|
||||
return _customHTML;
|
||||
}
|
||||
|
||||
@@ -525,6 +525,7 @@ void WiFiManager::stopWebPortal() {
|
||||
}
|
||||
|
||||
boolean WiFiManager::configPortalHasTimeout(){
|
||||
if(!configPortalActive) return false;
|
||||
uint16_t logintvl = 30000; // how often to emit timeing out counter logging
|
||||
|
||||
// handle timeout portal client check
|
||||
@@ -714,7 +715,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
// if timed out or abort, break
|
||||
if(configPortalHasTimeout() || abort){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_DEV,F("configportal abort"));
|
||||
DEBUG_WM(DEBUG_DEV,F("configportal loop abort"));
|
||||
#endif
|
||||
shutdownConfigPortal();
|
||||
result = abort ? portalAbortResult : portalTimeoutResult; // false, false
|
||||
@@ -722,13 +723,16 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
}
|
||||
|
||||
state = processConfigPortal();
|
||||
|
||||
|
||||
// status change, break
|
||||
if(state != WL_IDLE_STATUS){
|
||||
result = (state == WL_CONNECTED); // true if connected
|
||||
DEBUG_WM(DEBUG_DEV,F("configportal loop break"));
|
||||
break;
|
||||
}
|
||||
|
||||
if(!configPortalActive) break;
|
||||
|
||||
yield(); // watchdog
|
||||
}
|
||||
|
||||
@@ -782,18 +786,23 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
}
|
||||
else{
|
||||
// attempt sta connection to submitted _ssid, _pass
|
||||
if (connectWifi(_ssid, _pass) == WL_CONNECTED) {
|
||||
|
||||
uint8_t res = connectWifi(_ssid, _pass, _connectonsave) == WL_CONNECTED;
|
||||
if (res || (!_connectonsave)) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(F("Connect to new AP [SUCCESS]"));
|
||||
DEBUG_WM(F("Got IP Address:"));
|
||||
DEBUG_WM(WiFi.localIP());
|
||||
if(!_connectonsave){
|
||||
DEBUG_WM(F("SAVED with no connect to new AP"));
|
||||
} else {
|
||||
DEBUG_WM(F("Connect to new AP [SUCCESS]"));
|
||||
DEBUG_WM(F("Got IP Address:"));
|
||||
DEBUG_WM(WiFi.localIP());
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( _savewificallback != NULL) {
|
||||
_savewificallback();
|
||||
}
|
||||
shutdownConfigPortal();
|
||||
if(!_connectonsave) return WL_IDLE_STATUS;
|
||||
return WL_CONNECTED; // CONNECT SUCCESS
|
||||
}
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -837,6 +846,10 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
* @return bool success (softapdisconnect)
|
||||
*/
|
||||
bool WiFiManager::shutdownConfigPortal(){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("shutdownConfigPortal"));
|
||||
#endif
|
||||
|
||||
if(webPortalActive) return false;
|
||||
|
||||
if(configPortalActive){
|
||||
@@ -863,9 +876,6 @@ bool WiFiManager::shutdownConfigPortal(){
|
||||
// https://github.com/esp8266/Arduino/issues/3793
|
||||
// [APdisconnect] set_config failed! *WM: disconnect configportal - softAPdisconnect failed
|
||||
// still no way to reproduce reliably
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("disconnect configportal"));
|
||||
#endif
|
||||
|
||||
bool ret = false;
|
||||
ret = WiFi.softAPdisconnect(false);
|
||||
@@ -887,6 +897,7 @@ bool WiFiManager::shutdownConfigPortal(){
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("wifi mode:"),getModeString(WiFi.getMode()));
|
||||
#endif
|
||||
configPortalActive = false;
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("configportal closed"));
|
||||
_end();
|
||||
return ret;
|
||||
}
|
||||
@@ -894,7 +905,7 @@ bool WiFiManager::shutdownConfigPortal(){
|
||||
// @todo refactor this up into seperate functions
|
||||
// one for connecting to flash , one for new client
|
||||
// clean up, flow is convoluted, and causes bugs
|
||||
uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client..."));
|
||||
#endif
|
||||
@@ -917,10 +928,10 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
}
|
||||
// if ssid argument provided connect to that
|
||||
if (ssid != "") {
|
||||
wifiConnectNew(ssid,pass);
|
||||
wifiConnectNew(ssid,pass,connect);
|
||||
if(_saveTimeout > 0){
|
||||
connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop
|
||||
}
|
||||
}
|
||||
else {
|
||||
connRes = waitForConnectResult(0);
|
||||
}
|
||||
@@ -968,17 +979,18 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) {
|
||||
* @param String ssid
|
||||
* @param String pass
|
||||
* @return bool success
|
||||
* @return connect only save if false
|
||||
*/
|
||||
bool WiFiManager::wifiConnectNew(String ssid, String pass){
|
||||
bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){
|
||||
bool ret = false;
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(F("CONNECTED:"),WiFi.status() == WL_CONNECTED);
|
||||
// DEBUG_WM(DEBUG_DEV,F("CONNECTED: "),WiFi.status() == WL_CONNECTED ? "Y" : "NO");
|
||||
DEBUG_WM(F("Connecting to NEW AP:"),ssid);
|
||||
DEBUG_WM(DEBUG_DEV,F("Using Password:"),pass);
|
||||
#endif
|
||||
WiFi_enableSTA(true,storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default)
|
||||
WiFi.persistent(true);
|
||||
ret = WiFi.begin(ssid.c_str(), pass.c_str());
|
||||
ret = WiFi.begin(ssid.c_str(), pass.c_str(), 0, NULL, connect);
|
||||
WiFi.persistent(false);
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi begin failed"));
|
||||
@@ -1028,7 +1040,7 @@ bool WiFiManager::setSTAConfig(){
|
||||
#endif
|
||||
bool ret = true;
|
||||
if (_sta_static_ip) {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS"));
|
||||
#endif
|
||||
if(_sta_static_dns) {
|
||||
@@ -1044,12 +1056,13 @@ bool WiFiManager::setSTAConfig(){
|
||||
ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
|
||||
}
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi config failed"));
|
||||
else DEBUG_WM(F("STA IP set:"),WiFi.localIP());
|
||||
#endif
|
||||
} else {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi config failed"));
|
||||
else DEBUG_WM(F("STA IP set:"),WiFi.localIP());
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping"));
|
||||
#endif
|
||||
}
|
||||
@@ -1172,13 +1185,16 @@ void WiFiManager::handleRequest() {
|
||||
// bool authenticateDigest(const String& username, const String& H1);
|
||||
// void requestAuthentication(HTTPAuthMethod mode = BASIC_AUTH, const char* realm = NULL, const String& authFailMsg = String("") );
|
||||
|
||||
// 2.3 NO AUTH available
|
||||
bool testauth = false;
|
||||
if(!testauth) return;
|
||||
|
||||
DEBUG_WM(DEBUG_DEV,F("DOING AUTH"));
|
||||
bool res = server->authenticate("admin","12345");
|
||||
if(!res){
|
||||
#ifndef WM_NOAUTH
|
||||
server->requestAuthentication(HTTPAuthMethod::BASIC_AUTH); // DIGEST_AUTH
|
||||
#endif
|
||||
DEBUG_WM(DEBUG_DEV,F("AUTH FAIL"));
|
||||
}
|
||||
}
|
||||
@@ -1202,7 +1218,8 @@ void WiFiManager::handleRoot() {
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->setContentLength(page.length());
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
// server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan
|
||||
if(_preloadwifiscan) WiFi_scanNetworks(_scancachetime,true); // preload wifiscan throttled, async
|
||||
@@ -1260,7 +1277,7 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
// server->close(); // testing reliability fix for content length mismatches during mutiple flood hits
|
||||
|
||||
@@ -1291,7 +1308,7 @@ void WiFiManager::handleParam(){
|
||||
reportStatus(page);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -1635,7 +1652,7 @@ void WiFiManager::handleWiFiStatus(){
|
||||
#ifdef WM_JSTEST
|
||||
page = FPSTR(HTTP_JS);
|
||||
#endif
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
}
|
||||
|
||||
@@ -1650,7 +1667,7 @@ void WiFiManager::handleWifiSave() {
|
||||
handleRequest();
|
||||
|
||||
// @todo use new callback for before paramsaves
|
||||
if ( _presavecallback != NULL) {
|
||||
if (!_paramsInWifi && _presavecallback != NULL) {
|
||||
_presavecallback();
|
||||
}
|
||||
|
||||
@@ -1702,7 +1719,7 @@ void WiFiManager::handleWifiSave() {
|
||||
}
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
@@ -1729,7 +1746,7 @@ void WiFiManager::handleParamSave() {
|
||||
page += FPSTR(HTTP_PARAMSAVED);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -1880,7 +1897,7 @@ void WiFiManager::handleInfo() {
|
||||
page += FPSTR(HTTP_HELP);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -2022,11 +2039,13 @@ String WiFiManager::getInfoData(String id){
|
||||
}
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
#ifndef WM_NOSOFTAPSSID
|
||||
else if(id==F("apssid")){
|
||||
p = FPSTR(HTTP_INFO_apssid);
|
||||
p.replace(FPSTR(T_1),htmlEntities(WiFi.softAPSSID()));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
else if(id==F("apbssid")){
|
||||
p = FPSTR(HTTP_INFO_apbssid);
|
||||
p.replace(FPSTR(T_1),(String)WiFi.BSSIDstr());
|
||||
@@ -2103,7 +2122,7 @@ void WiFiManager::handleExit() {
|
||||
page += FPSTR(S_exiting); // @token exiting
|
||||
server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"));
|
||||
// ('Logout', 401, {'WWW-Authenticate': 'Basic realm="Login required"'})
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
delay(2000);
|
||||
abort = true;
|
||||
@@ -2121,7 +2140,7 @@ void WiFiManager::handleReset() {
|
||||
page += FPSTR(S_resetting); //@token resetting
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
@@ -2156,7 +2175,7 @@ void WiFiManager::handleErase(boolean opt) {
|
||||
}
|
||||
|
||||
page += FPSTR(HTTP_END);
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
if(ret){
|
||||
@@ -2189,7 +2208,7 @@ void WiFiManager::handleNotFound() {
|
||||
server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate"));
|
||||
server->sendHeader(F("Pragma"), F("no-cache"));
|
||||
server->sendHeader(F("Expires"), F("-1"));
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(message.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(message.length()));
|
||||
server->send ( 404, FPSTR(HTTP_HEAD_CT2), message );
|
||||
}
|
||||
|
||||
@@ -2237,7 +2256,7 @@ void WiFiManager::handleClose(){
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose
|
||||
page += FPSTR(S_closing); // @token closing
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
}
|
||||
|
||||
@@ -2471,6 +2490,16 @@ void WiFiManager::setSaveConnectTimeout(unsigned long seconds) {
|
||||
_saveTimeout = seconds * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set save portal connect on save option,
|
||||
* if false, will only save credentials not connect
|
||||
* @access public
|
||||
* @param {[type]} bool connect [description]
|
||||
*/
|
||||
void WiFiManager::setSaveConnect(bool connect) {
|
||||
_connectonsave = connect;
|
||||
}
|
||||
|
||||
/**
|
||||
* [setDebugOutput description]
|
||||
* @access public
|
||||
@@ -2601,6 +2630,15 @@ void WiFiManager::setPreSaveConfigCallback( std::function<void()> func ) {
|
||||
_presavecallback = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* setPreOtaUpdateCallback, set a callback to fire before OTA update
|
||||
* @access public
|
||||
* @param {[type]} void (*func)(void)
|
||||
*/
|
||||
void WiFiManager::setPreOtaUpdateCallback( std::function<void()> func ) {
|
||||
_preotaupdatecallback = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* set custom head html
|
||||
* custom element will be added to head, eg. new style tag etc.
|
||||
@@ -3528,7 +3566,7 @@ void WiFiManager::handleUpdate() {
|
||||
page += FPSTR(HTTP_UPDATE);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
}
|
||||
@@ -3559,6 +3597,10 @@ void WiFiManager::handleUpdating(){
|
||||
if(_debug) Serial.setDebugOutput(true);
|
||||
uint32_t maxSketchSpace;
|
||||
|
||||
// Use new callback for before OTA update
|
||||
if (_preotaupdatecallback != NULL) {
|
||||
_preotaupdatecallback();
|
||||
}
|
||||
#ifdef ESP8266
|
||||
WiFiUDP::stopAll();
|
||||
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
@@ -3596,7 +3638,7 @@ void WiFiManager::handleUpdating(){
|
||||
else if (upload.status == UPLOAD_FILE_END) {
|
||||
if (Update.end(true)) { // true to set the size to the current progress
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("[OTA] OTA FILE END bytes: "), upload.totalSize);
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("\n\n[OTA] OTA FILE END bytes: "), upload.totalSize);
|
||||
// Serial.printf("Updated: %u bytes\r\nRebooting...\r\n", upload.totalSize);
|
||||
#endif
|
||||
}
|
||||
@@ -3622,6 +3664,7 @@ void WiFiManager::handleUpdateDone() {
|
||||
|
||||
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||
str.replace(FPSTR(T_t),_title);
|
||||
str.replace(FPSTR(T_v), configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading
|
||||
page += str;
|
||||
|
||||
@@ -3640,7 +3683,7 @@ void WiFiManager::handleUpdateDone() {
|
||||
}
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
// server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
server->send(200, FPSTR(HTTP_HEAD_CT), page);
|
||||
|
||||
delay(1000); // send page
|
||||
|
||||
+19
-11
@@ -34,6 +34,8 @@
|
||||
#warning "ARDUINO_ESP8266_RELEASE_2_3_0, some WM features disabled"
|
||||
#define WM_NOASYNC // esp8266 no async scan wifi
|
||||
#define WM_NOCOUNTRY // esp8266 no country
|
||||
#define WM_NOAUTH // no httpauth
|
||||
#define WM_NOSOFTAPSSID // no softapssid() @todo shim
|
||||
#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.
|
||||
@@ -120,13 +122,13 @@ class WiFiManagerParameter {
|
||||
~WiFiManagerParameter();
|
||||
// WiFiManagerParameter& operator=(const WiFiManagerParameter& rhs);
|
||||
|
||||
const char *getID();
|
||||
const char *getValue();
|
||||
const char *getLabel();
|
||||
const char *getPlaceholder(); // @deprecated, use getLabel
|
||||
int getValueLength();
|
||||
int getLabelPlacement();
|
||||
const char *getCustomHTML();
|
||||
const char *getID() const;
|
||||
const char *getValue() const;
|
||||
const char *getLabel() const;
|
||||
const char *getPlaceholder() const; // @deprecated, use getLabel
|
||||
int getValueLength() const;
|
||||
int getLabelPlacement() const;
|
||||
const char *getCustomHTML() const;
|
||||
void setValue(const char *defaultValue, int length);
|
||||
|
||||
protected:
|
||||
@@ -218,6 +220,8 @@ class WiFiManager
|
||||
//called when saving params-in-wifi or params before anything else happens (eg wifi)
|
||||
void setPreSaveConfigCallback( std::function<void()> func );
|
||||
|
||||
//called just before doing OTA update
|
||||
void setPreOtaUpdateCallback( std::function<void()> func );
|
||||
|
||||
//sets timeout before AP,webserver loop ends and exits even if there has been no setup.
|
||||
//useful for devices that failed to connect at some point and got stuck in a webserver loop
|
||||
@@ -234,6 +238,9 @@ class WiFiManager
|
||||
//sets timeout for which to attempt connecting on saves, useful if there are bugs in esp waitforconnectloop
|
||||
void setSaveConnectTimeout(unsigned long seconds);
|
||||
|
||||
// lets you disable automatically connecting after save from webportal
|
||||
void setSaveConnect(bool connect = true);
|
||||
|
||||
// toggle debug output
|
||||
void setDebugOutput(boolean debug);
|
||||
void setDebugOutput(boolean debug, String prefix); // log line prefix, default "*wm:"
|
||||
@@ -427,7 +434,7 @@ class WiFiManager
|
||||
unsigned long _startscan = 0; // ms for timing wifi scans
|
||||
int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast.
|
||||
bool _cleanConnect = false; // disconnect before connect in connectwifi, increases stability on connects
|
||||
|
||||
bool _connectonsave = true; // connect to wifi when saving creds
|
||||
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 same wifi sta channel when starting ap
|
||||
@@ -508,10 +515,10 @@ class WiFiManager
|
||||
bool startAP();
|
||||
void setupDNSD();
|
||||
|
||||
uint8_t connectWifi(String ssid, String pass);
|
||||
uint8_t connectWifi(String ssid, String pass, bool connect = true);
|
||||
bool setSTAConfig();
|
||||
bool wifiConnectDefault();
|
||||
bool wifiConnectNew(String ssid, String pass);
|
||||
bool wifiConnectNew(String ssid, String pass,bool connect = true);
|
||||
|
||||
uint8_t waitForConnectResult();
|
||||
uint8_t waitForConnectResult(uint32_t timeout);
|
||||
@@ -628,7 +635,7 @@ class WiFiManager
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
uint8_t _debugLevel = (uint8_t)WM_DEBUG_LEVEL;
|
||||
#else
|
||||
uint8_t _debugLevel = DEBUG_DEV; // default debug level
|
||||
uint8_t _debugLevel = DEBUG_VERBOSE; // default debug level
|
||||
#endif
|
||||
|
||||
// @todo use DEBUG_ESP_PORT ?
|
||||
@@ -656,6 +663,7 @@ class WiFiManager
|
||||
std::function<void()> _presavecallback;
|
||||
std::function<void()> _saveparamscallback;
|
||||
std::function<void()> _resetcallback;
|
||||
std::function<void()> _preotaupdatecallback;
|
||||
|
||||
template <class T>
|
||||
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* 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
|
||||
* startAP = true will start both the configportal AP and webportal
|
||||
*/
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
|
||||
|
||||
+3
@@ -171,6 +171,9 @@ void setup() {
|
||||
// set wifi connect retries
|
||||
// wm.setConnectRetries(2);
|
||||
|
||||
// connect after portal save toggle
|
||||
wm.setSaveConnect(false); // do not connect, only save
|
||||
|
||||
// show static ip fields
|
||||
// wm.setShowStaticFields(true);
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
#include <WiFiManager.h>
|
||||
#include <PubSubClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
char mqtt_server[40];
|
||||
void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
||||
// message received
|
||||
}
|
||||
|
||||
void mqttReconnect() {
|
||||
// reconnect code from PubSubClient example
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
WiFiManager wifiManager;
|
||||
wifiManager.setTimeout(180);
|
||||
|
||||
if(!wifiManager.autoConnect("AutoConnectAP")) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(3000);
|
||||
ESP.restart();
|
||||
delay(5000);
|
||||
}
|
||||
// id/name, placeholder/prompt, default, length
|
||||
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
|
||||
wifiManager.addParameter(&custom_mqtt_server);
|
||||
|
||||
const char* mqtt_server = custom_mqtt_server.getValue();
|
||||
|
||||
Serial.println("connected...yeey :)");
|
||||
|
||||
client.setServer(mqtt_server, 1883);
|
||||
client.setCallback(mqttCallback);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!client.connected()) {
|
||||
mqttReconnect();
|
||||
}
|
||||
client.loop();
|
||||
yield();
|
||||
}
|
||||
Reference in New Issue
Block a user