mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-15 23:51:20 +10:00
Merge branch 'development' of https://github.com/tzapu/WiFiManager into development
This commit is contained in:
+35
-26
@@ -22,34 +22,38 @@ uint8_t WiFiManager::_lastconxresulttmp = WL_IDLE_STATUS;
|
||||
* --------------------------------------------------------------------------------
|
||||
**/
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter() {
|
||||
WiFiManagerParameter("");
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *custom) {
|
||||
_id = NULL;
|
||||
_placeholder = NULL;
|
||||
_label = NULL;
|
||||
_length = 1;
|
||||
_value = NULL;
|
||||
_labelPlacement = WFM_LABEL_BEFORE;
|
||||
_customHTML = custom;
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder) {
|
||||
init(id, placeholder, "", 0, "", WFM_LABEL_BEFORE);
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label) {
|
||||
init(id, label, "", 0, "", WFM_LABEL_BEFORE);
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) {
|
||||
init(id, placeholder, defaultValue, length, "", WFM_LABEL_BEFORE);
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length) {
|
||||
init(id, label, defaultValue, length, "", WFM_LABEL_BEFORE);
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) {
|
||||
init(id, placeholder, defaultValue, length, custom, WFM_LABEL_BEFORE);
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom) {
|
||||
init(id, label, defaultValue, length, custom, WFM_LABEL_BEFORE);
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) {
|
||||
init(id, placeholder, defaultValue, length, custom, labelPlacement);
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement) {
|
||||
init(id, label, defaultValue, length, custom, labelPlacement);
|
||||
}
|
||||
|
||||
void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) {
|
||||
void WiFiManagerParameter::init(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement) {
|
||||
_id = id;
|
||||
_placeholder = placeholder;
|
||||
_label = label;
|
||||
_labelPlacement = labelPlacement;
|
||||
_customHTML = custom;
|
||||
setValue(defaultValue,length);
|
||||
@@ -89,7 +93,10 @@ const char* WiFiManagerParameter::getID() {
|
||||
return _id;
|
||||
}
|
||||
const char* WiFiManagerParameter::getPlaceholder() {
|
||||
return _placeholder;
|
||||
return _label;
|
||||
}
|
||||
const char* WiFiManagerParameter::getLabel() {
|
||||
return _label;
|
||||
}
|
||||
int WiFiManagerParameter::getValueLength() {
|
||||
return _length;
|
||||
@@ -413,7 +420,7 @@ void WiFiManager::stopWebPortal() {
|
||||
|
||||
boolean WiFiManager::configPortalHasTimeout(){
|
||||
|
||||
if(_configPortalTimeout == 0 || (_cpClientCheck && (WiFi_softap_num_stations() > 0))){
|
||||
if(_configPortalTimeout == 0 || (_apClientCheck && (WiFi_softap_num_stations() > 0))){
|
||||
if(millis() - timer > 30000){
|
||||
timer = millis();
|
||||
DEBUG_WM(DEBUG_VERBOSE,"NUM CLIENTS: " + (String)WiFi_softap_num_stations());
|
||||
@@ -1218,7 +1225,7 @@ String WiFiManager::getParamOut(){
|
||||
bool tok_v = HTTP_PARAM_temp.indexOf(FPSTR(T_v)) > 0;
|
||||
bool tok_c = HTTP_PARAM_temp.indexOf(FPSTR(T_c)) > 0;
|
||||
|
||||
char parLength[5];
|
||||
char valLength[5];
|
||||
// add the extra parameters to the form
|
||||
for (int i = 0; i < _paramsCount; i++) {
|
||||
if (_params[i] == NULL || _params[i]->_length == 0) {
|
||||
@@ -1226,7 +1233,7 @@ String WiFiManager::getParamOut(){
|
||||
break;
|
||||
}
|
||||
|
||||
// label before or after, this could probably be done via floats however
|
||||
// label before or after, @todo this could be done via floats or CSS and eliminated
|
||||
String pitem;
|
||||
switch (_params[i]->getLabelPlacement()) {
|
||||
case WFM_LABEL_BEFORE:
|
||||
@@ -1243,17 +1250,19 @@ String WiFiManager::getParamOut(){
|
||||
break;
|
||||
}
|
||||
|
||||
// Input templating
|
||||
// "<br/><input id='{i}' name='{n}' maxlength='{l}' value='{v}' {c}>";
|
||||
// if no ID use customhtml for item, else generate from param string
|
||||
if (_params[i]->getID() != NULL) {
|
||||
if(tok_I)pitem.replace(FPSTR(T_I), (String)FPSTR(S_parampre)+(String)i);
|
||||
if(tok_i)pitem.replace(FPSTR(T_i), _params[i]->getID());
|
||||
if(tok_n)pitem.replace(FPSTR(T_n), _params[i]->getID());
|
||||
if(tok_p)pitem.replace(FPSTR(T_p), FPSTR(T_t));
|
||||
if(tok_t)pitem.replace(FPSTR(T_t), _params[i]->getPlaceholder());
|
||||
snprintf(parLength, 5, "%d", _params[i]->getValueLength());
|
||||
if(tok_l)pitem.replace(FPSTR(T_l), parLength);
|
||||
if(tok_v)pitem.replace(FPSTR(T_v), _params[i]->getValue());
|
||||
if(tok_c)pitem.replace(FPSTR(T_c), _params[i]->getCustomHTML()); // meant for additional attributes, not html
|
||||
if(tok_I)pitem.replace(FPSTR(T_I), (String)FPSTR(S_parampre)+(String)i); // T_I id number
|
||||
if(tok_i)pitem.replace(FPSTR(T_i), _params[i]->getID()); // T_i id name
|
||||
if(tok_n)pitem.replace(FPSTR(T_n), _params[i]->getID()); // T_n id name alias
|
||||
if(tok_p)pitem.replace(FPSTR(T_p), FPSTR(T_t)); // T_p replace legacy placeholder token
|
||||
if(tok_t)pitem.replace(FPSTR(T_t), _params[i]->getLabel()); // T_t title/label
|
||||
snprintf(valLength, 5, "%d", _params[i]->getValueLength());
|
||||
if(tok_l)pitem.replace(FPSTR(T_l), valLength); // T_l value length
|
||||
if(tok_v)pitem.replace(FPSTR(T_v), _params[i]->getValue()); // T_v value
|
||||
if(tok_c)pitem.replace(FPSTR(T_c), _params[i]->getCustomHTML()); // T_c meant for additional attributes, not html, but can stuff
|
||||
} else {
|
||||
pitem = _params[i]->getCustomHTML();
|
||||
}
|
||||
@@ -2182,8 +2191,8 @@ void WiFiManager::setWiFiAutoReconnect(boolean enabled){
|
||||
* @access public
|
||||
* @param boolean enabled [false]
|
||||
*/
|
||||
void WiFiManager::setCaptivePortalClientCheck(boolean enabled){
|
||||
_cpClientCheck = enabled;
|
||||
void WiFiManager::setAPClientCheck(boolean enabled){
|
||||
_apClientCheck = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+13
-11
@@ -104,28 +104,30 @@ class WiFiManagerParameter {
|
||||
Create custom parameters that can be added to the WiFiManager setup web page
|
||||
@id is used for HTTP queries and must not contain spaces nor other special characters
|
||||
*/
|
||||
WiFiManagerParameter();
|
||||
WiFiManagerParameter(const char *custom);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement);
|
||||
WiFiManagerParameter(const char *id, const char *label);
|
||||
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length);
|
||||
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom);
|
||||
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement);
|
||||
~WiFiManagerParameter();
|
||||
|
||||
const char *getID();
|
||||
const char *getValue();
|
||||
const char *getPlaceholder();
|
||||
const char *getLabel();
|
||||
const char *getPlaceholder(); // @deprecated, use getLabel
|
||||
int getValueLength();
|
||||
int getLabelPlacement();
|
||||
const char *getCustomHTML();
|
||||
void setValue(const char *defaultValue, int length);
|
||||
|
||||
protected:
|
||||
void init(const char *id, const char *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);
|
||||
void init(const char *id, const char *label, const char *defaultValue, int length, const char *custom);
|
||||
void init(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement);
|
||||
|
||||
private:
|
||||
const char *_id;
|
||||
const char *_placeholder;
|
||||
const char *_label;
|
||||
char *_value;
|
||||
int _length;
|
||||
int _labelPlacement;
|
||||
@@ -236,8 +238,8 @@ class WiFiManager
|
||||
void setShowDnsFields(boolean alwaysShow);
|
||||
//if false, disable captive portal redirection
|
||||
void setCaptivePortalEnable(boolean enabled);
|
||||
//if false, timeout captive portal even if a STA client connected (false), suggest disabling if captiveportal is open
|
||||
void setCaptivePortalClientCheck(boolean enabled);
|
||||
//if false, timeout captive portal even if a STA client connected to softAP (false), suggest disabling if captiveportal is open
|
||||
void setAPClientCheck(boolean enabled);
|
||||
//if true, reset timeout when webclient connects (true), suggest disabling if captiveportal is open
|
||||
void setWebPortalClientCheck(boolean enabled);
|
||||
// if true, enable autoreconnecting
|
||||
@@ -343,7 +345,7 @@ class WiFiManager
|
||||
boolean _enableCaptivePortal = true; // enable captive portal redirection
|
||||
boolean _userpersistent = true; // users preffered persistence to restore
|
||||
boolean _wifiAutoReconnect = true; // there is no platform getter for this, we must assume its true and make it so
|
||||
boolean _cpClientCheck = false; // keep cp alive if cp have station
|
||||
boolean _apClientCheck = false; // keep cp alive if ap have station
|
||||
boolean _webClientCheck = true; // keep cp alive if web have client
|
||||
boolean _scanDispOptions = false; // show percentage in scans not icons
|
||||
boolean _paramsInWifi = true; // show custom parameters on wifi page
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
#define TRIGGER_PIN 0
|
||||
|
||||
WiFiManager wm;
|
||||
WiFiManager wm; // global wm instance
|
||||
WiFiManagerParameter custom_field; // global param ( for non blocking w params )
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@@ -15,13 +16,14 @@ void setup() {
|
||||
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);
|
||||
new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder=\"Custom Field Placeholder\""); // reconstruct (hmm)
|
||||
wm.addParameter(&custom_field);
|
||||
wm.setSaveParamsCallback(saveParamCallback);
|
||||
|
||||
// custom menu via array or vector
|
||||
//
|
||||
@@ -33,15 +35,17 @@ void setup() {
|
||||
|
||||
// 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
|
||||
wm.setConfigPortalTimeout(30); // auto close configportal after n seconds
|
||||
// wm.setCaptivePortalEnable(false); // disable captive portal redirection
|
||||
// wm.setAPClientCheck(true); // avoid timeout if client connected to softap
|
||||
|
||||
// wifi scan settings
|
||||
// wm.setRemoveDuplicateAPs(false); // do not remove duplicate ap names (true)
|
||||
@@ -72,11 +76,12 @@ void checkButton(){
|
||||
// poor mans debounce/press-hold, code not ideal for production
|
||||
delay(50);
|
||||
if( digitalRead(TRIGGER_PIN) == LOW ){
|
||||
|
||||
Serial.println("Button Pressed");
|
||||
// still holding button for 3000 ms, reset settings, code not ideaa for production
|
||||
delay(3000); // reset delay hold
|
||||
if( digitalRead(TRIGGER_PIN) == LOW ){
|
||||
Serial.println("Erasing Config");
|
||||
Serial.println("Button Held");
|
||||
Serial.println("Erasing Config, restarting");
|
||||
wm.resetSettings();
|
||||
ESP.restart();
|
||||
}
|
||||
@@ -85,7 +90,7 @@ void checkButton(){
|
||||
Serial.println("Starting config portal");
|
||||
wm.setConfigPortalTimeout(120);
|
||||
|
||||
if (!wm.startConfigPortal("OnDemandAP")) {
|
||||
if (!wm.startConfigPortal("OnDemandAP","password")) {
|
||||
Serial.println("failed to connect or hit timeout");
|
||||
delay(3000);
|
||||
// ESP.restart();
|
||||
@@ -97,6 +102,10 @@ void checkButton(){
|
||||
}
|
||||
}
|
||||
|
||||
void saveParamCallback(){
|
||||
Serial.println("[CALLBACK] saveParamCallback fired");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
checkButton();
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ const char HTTP_FORM_STATIC_HEAD[] PROGMEM = "<hr><br/>";
|
||||
const char HTTP_FORM_END[] PROGMEM = "<br/><br/><button type='submit'>Save</button></form>";
|
||||
const char HTTP_FORM_LABEL[] PROGMEM = "<label for='{i}'>{t}</label>";
|
||||
const char HTTP_FORM_PARAM_HEAD[] PROGMEM = "<hr><br/>";
|
||||
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength='{l}' placeholder='' value='{v}' {c}>";
|
||||
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength='{l}' value='{v}' {c}>";
|
||||
|
||||
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><form action='/wifi?refresh=1' method='POST'><button name='refresh' value='1'>Refresh</button></form>";
|
||||
const char HTTP_SAVED[] PROGMEM = "<div class='msg'>Saving Credentials<br/>Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
|
||||
|
||||
Reference in New Issue
Block a user