mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-15 23:51:20 +10:00
Merge branch 'master' into resetConfigCallback
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
## Contributing PRs and ISSUES
|
||||
|
||||
The development branch is the active branch, no features or bugs will be fixed against master ( hotfixes may be considered ).
|
||||
|
||||
Please test against development branch before submitting issues, issues against master will be closed,
|
||||
|
||||
PRs against master may be kept open if provides something useful to other members.
|
||||
|
||||
Please open issues before sumbitting PRs against development, as commits might be occuring very frequently.
|
||||
|
||||
### Documentation is in progress
|
||||
https://github.com/tzapu/WiFiManager/issues/500
|
||||
@@ -0,0 +1,69 @@
|
||||
## 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 ;)
|
||||
|
||||
if you have a stack dump decode it:
|
||||
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.rst
|
||||
|
||||
for better debug messages:
|
||||
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst
|
||||
|
||||
----------------------------- Remove above -----------------------------
|
||||
|
||||
### Basic Infos
|
||||
|
||||
#### Hardware
|
||||
**WiFimanager Branch/Release:**
|
||||
- [ ] Master
|
||||
- [ ] Development
|
||||
|
||||
**Esp8266/Esp32:**
|
||||
- [ ] ESP8266
|
||||
- [ ] ESP32
|
||||
|
||||
**Hardware: ESP-12e, esp01, esp25**
|
||||
- [ ] ESP01
|
||||
- [ ] ESP12 E/F/S (nodemcu, wemos, feather)
|
||||
- [ ] Other
|
||||
|
||||
|
||||
**ESP Core Version: 2.4.0, staging**
|
||||
- [ ] 2.3.0
|
||||
- [ ] 2.4.0
|
||||
- [ ] staging (master/dev)
|
||||
|
||||
### Description
|
||||
|
||||
Problem description
|
||||
|
||||
### Settings in IDE
|
||||
|
||||
Module: NodeMcu, Wemos D1
|
||||
|
||||
Additional libraries:
|
||||
|
||||
### Sketch
|
||||
|
||||
```cpp
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
void setup() {
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### Debug Messages
|
||||
|
||||
```
|
||||
messages here
|
||||
```
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
## Current development going on here :arrow_right: [Development Branch](https://github.com/tzapu/WiFiManager/tree/development)
|
||||
|
||||
# WiFiManager
|
||||
ESP8266 WiFi Connection manager with fallback web configuration portal
|
||||
|
||||
|
||||
+68
-29
@@ -34,7 +34,7 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c
|
||||
_placeholder = placeholder;
|
||||
_length = length;
|
||||
_value = new char[length + 1];
|
||||
for (int i = 0; i < length; i++) {
|
||||
for (int i = 0; i < length + 1; i++) {
|
||||
_value[i] = 0;
|
||||
}
|
||||
if (defaultValue != NULL) {
|
||||
@@ -44,6 +44,12 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c
|
||||
_customHTML = custom;
|
||||
}
|
||||
|
||||
WiFiManagerParameter::~WiFiManagerParameter() {
|
||||
if (_value != NULL) {
|
||||
delete[] _value;
|
||||
}
|
||||
}
|
||||
|
||||
const char* WiFiManagerParameter::getValue() {
|
||||
return _value;
|
||||
}
|
||||
@@ -60,22 +66,42 @@ const char* WiFiManagerParameter::getCustomHTML() {
|
||||
return _customHTML;
|
||||
}
|
||||
|
||||
|
||||
WiFiManager::WiFiManager() {
|
||||
_max_params = WIFI_MANAGER_MAX_PARAMS;
|
||||
_params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*));
|
||||
}
|
||||
|
||||
void WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS)
|
||||
WiFiManager::~WiFiManager()
|
||||
{
|
||||
if (_params != NULL)
|
||||
{
|
||||
DEBUG_WM(F("freeing allocated params!"));
|
||||
free(_params);
|
||||
}
|
||||
}
|
||||
|
||||
bool WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
if(_paramsCount + 1 > _max_params)
|
||||
{
|
||||
//Max parameters exceeded!
|
||||
DEBUG_WM("WIFI_MANAGER_MAX_PARAMS exceeded, increase number (in WiFiManager.h) before adding more parameters!");
|
||||
DEBUG_WM("Skipping parameter with ID:");
|
||||
DEBUG_WM(p->getID());
|
||||
return;
|
||||
// rezise the params array
|
||||
_max_params += WIFI_MANAGER_MAX_PARAMS;
|
||||
DEBUG_WM(F("Increasing _max_params to:"));
|
||||
DEBUG_WM(_max_params);
|
||||
WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*));
|
||||
if (new_params != NULL) {
|
||||
_params = new_params;
|
||||
} else {
|
||||
DEBUG_WM(F("ERROR: failed to realloc params, size not increased!"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_params[_paramsCount] = p;
|
||||
_paramsCount++;
|
||||
DEBUG_WM("Adding parameter");
|
||||
DEBUG_WM(F("Adding parameter"));
|
||||
DEBUG_WM(p->getID());
|
||||
return true;
|
||||
}
|
||||
|
||||
void WiFiManager::setupConfigPortal() {
|
||||
@@ -117,14 +143,14 @@ void WiFiManager::setupConfigPortal() {
|
||||
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
|
||||
|
||||
/* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */
|
||||
server->on("/", std::bind(&WiFiManager::handleRoot, this));
|
||||
server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true));
|
||||
server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false));
|
||||
server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this));
|
||||
server->on("/i", std::bind(&WiFiManager::handleInfo, this));
|
||||
server->on("/r", std::bind(&WiFiManager::handleReset, this));
|
||||
server->on(String(F("/")), std::bind(&WiFiManager::handleRoot, this));
|
||||
server->on(String(F("/wifi")), std::bind(&WiFiManager::handleWifi, this, true));
|
||||
server->on(String(F("/0wifi")), std::bind(&WiFiManager::handleWifi, this, false));
|
||||
server->on(String(F("/wifisave")), std::bind(&WiFiManager::handleWifiSave, this));
|
||||
server->on(String(F("/i")), std::bind(&WiFiManager::handleInfo, this));
|
||||
server->on(String(F("/r")), std::bind(&WiFiManager::handleReset, this));
|
||||
//server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check.
|
||||
server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
|
||||
server->on(String(F("/fwlink")), std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
|
||||
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
|
||||
server->begin(); // Web server start
|
||||
DEBUG_WM(F("HTTP server started"));
|
||||
@@ -171,9 +197,20 @@ boolean WiFiManager::startConfigPortal() {
|
||||
}
|
||||
|
||||
boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) {
|
||||
//setup AP
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
DEBUG_WM("SET AP STA");
|
||||
|
||||
if(!WiFi.isConnected()){
|
||||
WiFi.persistent(false);
|
||||
// disconnect sta, start ap
|
||||
WiFi.disconnect(); // this alone is not enough to stop the autoconnecter
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.persistent(true);
|
||||
}
|
||||
else {
|
||||
//setup AP
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
DEBUG_WM(F("SET AP STA"));
|
||||
}
|
||||
|
||||
|
||||
_apName = apName;
|
||||
_apPassword = apPassword;
|
||||
@@ -247,7 +284,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
||||
}
|
||||
//fix for auto connect racing issue
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
DEBUG_WM("Already connected. Bailing out.");
|
||||
DEBUG_WM(F("Already connected. Bailing out."));
|
||||
return WL_CONNECTED;
|
||||
}
|
||||
//check if we have ssid and pass and force those, if not, try with last saved values
|
||||
@@ -255,7 +292,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
||||
WiFi.begin(ssid.c_str(), pass.c_str());
|
||||
} else {
|
||||
if (WiFi.SSID()) {
|
||||
DEBUG_WM("Using last saved values, should be faster");
|
||||
DEBUG_WM(F("Using last saved values, should be faster"));
|
||||
//trying to fix connection in progress hanging
|
||||
ETS_UART_INTR_DISABLE();
|
||||
wifi_station_disconnect();
|
||||
@@ -263,7 +300,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
||||
|
||||
WiFi.begin();
|
||||
} else {
|
||||
DEBUG_WM("No saved credentials");
|
||||
DEBUG_WM(F("No saved credentials"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,11 +308,13 @@ int WiFiManager::connectWifi(String ssid, String pass) {
|
||||
DEBUG_WM ("Connection result: ");
|
||||
DEBUG_WM ( connRes );
|
||||
//not connected, WPS enabled, no pass - first attempt
|
||||
#ifdef NO_EXTRA_4K_HEAP
|
||||
if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
|
||||
startWPS();
|
||||
//should be connected at the end of WPS
|
||||
connRes = waitForConnectResult();
|
||||
}
|
||||
#endif
|
||||
return connRes;
|
||||
}
|
||||
|
||||
@@ -303,9 +342,9 @@ uint8_t WiFiManager::waitForConnectResult() {
|
||||
}
|
||||
|
||||
void WiFiManager::startWPS() {
|
||||
DEBUG_WM("START WPS");
|
||||
DEBUG_WM(F("START WPS"));
|
||||
WiFi.beginWPSConfig();
|
||||
DEBUG_WM("END WPS");
|
||||
DEBUG_WM(F("END WPS"));
|
||||
}
|
||||
/*
|
||||
String WiFiManager::getSSID() {
|
||||
@@ -389,10 +428,10 @@ void WiFiManager::handleRoot() {
|
||||
page += FPSTR(HTTP_STYLE);
|
||||
page += _customHeadElement;
|
||||
page += FPSTR(HTTP_HEAD_END);
|
||||
page += "<h1>";
|
||||
page += String(F("<h1>"));
|
||||
page += _apName;
|
||||
page += "</h1>";
|
||||
page += F("<h3>WiFiManager</h3>");
|
||||
page += String(F("</h1>"));
|
||||
page += String(F("<h3>WiFiManager</h3>"));
|
||||
page += FPSTR(HTTP_PORTAL_OPTIONS);
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
@@ -573,7 +612,7 @@ void WiFiManager::handleWifiSave() {
|
||||
//read parameter
|
||||
String value = server->arg(_params[i]->getID()).c_str();
|
||||
//store it in array
|
||||
value.toCharArray(_params[i]->_value, _params[i]->_length);
|
||||
value.toCharArray(_params[i]->_value, _params[i]->_length + 1);
|
||||
DEBUG_WM(F("Parameter"));
|
||||
DEBUG_WM(_params[i]->getID());
|
||||
DEBUG_WM(value);
|
||||
@@ -765,7 +804,7 @@ int WiFiManager::getRSSIasQuality(int RSSI) {
|
||||
|
||||
/** Is this an IP? */
|
||||
boolean WiFiManager::isIp(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
for (size_t i = 0; i < str.length(); i++) {
|
||||
int c = str.charAt(i);
|
||||
if (c != '.' && (c < '0' || c > '9')) {
|
||||
return false;
|
||||
|
||||
+13
-4
@@ -22,7 +22,7 @@ extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
|
||||
const char HTTP_HEAD[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\"/><title>{v}</title>";
|
||||
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;'>";
|
||||
@@ -35,13 +35,20 @@ const char HTTP_SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wi
|
||||
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>";
|
||||
|
||||
#ifndef WIFI_MANAGER_MAX_PARAMS
|
||||
#define WIFI_MANAGER_MAX_PARAMS 10
|
||||
#endif
|
||||
|
||||
class WiFiManagerParameter {
|
||||
public:
|
||||
/**
|
||||
Create custom parameters that can be added to the WiFiManager setup web page
|
||||
@id is used for HTTP queries and must not contain spaces nor other special characters
|
||||
*/
|
||||
WiFiManagerParameter(const char *custom);
|
||||
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 *getID();
|
||||
const char *getValue();
|
||||
@@ -65,6 +72,7 @@ class WiFiManager
|
||||
{
|
||||
public:
|
||||
WiFiManager();
|
||||
~WiFiManager();
|
||||
|
||||
boolean autoConnect();
|
||||
boolean autoConnect(char const *apName, char const *apPassword = NULL);
|
||||
@@ -101,8 +109,8 @@ class WiFiManager
|
||||
void setSaveConfigCallback( void (*func)(void) );
|
||||
//called when settings reset have been triggered
|
||||
void setConfigResetCallback(void(*func)(void));
|
||||
//adds a custom parameter
|
||||
void addParameter(WiFiManagerParameter *p);
|
||||
//adds a custom parameter, returns false on failure
|
||||
bool addParameter(WiFiManagerParameter *p);
|
||||
//if this is set, it will exit after config, even if connection is unsuccessful.
|
||||
void setBreakAfterConfig(boolean shouldBreak);
|
||||
//if this is set, try WPS setup when starting (this will delay config portal for up to 2 mins)
|
||||
@@ -179,7 +187,8 @@ class WiFiManager
|
||||
void (*_savecallback)(void) = NULL;
|
||||
void (*_resetcallback)(void) = NULL;
|
||||
|
||||
WiFiManagerParameter* _params[WIFI_MANAGER_MAX_PARAMS];
|
||||
int _max_params;
|
||||
WiFiManagerParameter** _params;
|
||||
|
||||
template <typename Generic>
|
||||
void DEBUG_WM(Generic text);
|
||||
|
||||
@@ -61,6 +61,7 @@ void setup() {
|
||||
} else {
|
||||
Serial.println("failed to load json config");
|
||||
}
|
||||
configFile.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": "espressif8266",
|
||||
"version": "0.12"
|
||||
"version": "0.14"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name=WiFiManager
|
||||
version=0.12
|
||||
version=0.14
|
||||
author=tzapu
|
||||
maintainer=tzapu
|
||||
sentence=ESP8266 WiFi Connection manager with fallback web configuration portal
|
||||
|
||||
Reference in New Issue
Block a user