mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-13 14:51:21 +10:00
Merge branch 'development' into ota
This commit is contained in:
+93
-14
@@ -184,7 +184,8 @@ WiFiManager::WiFiManager(Stream& consolePort):_debugPort(consolePort){
|
||||
WiFiManagerInit();
|
||||
}
|
||||
|
||||
WiFiManager::WiFiManager():WiFiManager(Serial) {
|
||||
WiFiManager::WiFiManager() {
|
||||
WiFiManagerInit();
|
||||
}
|
||||
|
||||
void WiFiManager::WiFiManagerInit(){
|
||||
@@ -371,20 +372,21 @@ bool WiFiManager::startAP(){
|
||||
}
|
||||
|
||||
// start soft AP with password or anonymous
|
||||
// default channel is 1 here and in esplib, @todo just change to default remove conditionals
|
||||
if (_apPassword != "") {
|
||||
if(channel>0){
|
||||
ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),channel);
|
||||
ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),channel,_apHidden);
|
||||
}
|
||||
else{
|
||||
ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option
|
||||
ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),1,_apHidden);//password option
|
||||
}
|
||||
} else {
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!"));
|
||||
if(channel>0){
|
||||
ret = WiFi.softAP(_apName.c_str(),"",channel);
|
||||
ret = WiFi.softAP(_apName.c_str(),"",channel,_apHidden);
|
||||
}
|
||||
else{
|
||||
ret = WiFi.softAP(_apName.c_str());
|
||||
ret = WiFi.softAP(_apName.c_str(),"",1,_apHidden);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,7 +628,7 @@ uint8_t WiFiManager::processConfigPortal(){
|
||||
|
||||
// skip wifi if no ssid
|
||||
if(_ssid == ""){
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi"));
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi save"));
|
||||
}
|
||||
else{
|
||||
// attempt sta connection to submitted _ssid, _pass
|
||||
@@ -976,6 +978,13 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
|
||||
pitem = FPSTR(HTTP_FORM_WIFI);
|
||||
pitem.replace(FPSTR(T_v), WiFi_SSID());
|
||||
|
||||
if(_showPassword){
|
||||
pitem.replace(FPSTR(T_p), WiFi_psk());
|
||||
}
|
||||
else {
|
||||
pitem.replace(FPSTR(T_p),FPSTR(S_passph));
|
||||
}
|
||||
page += pitem;
|
||||
|
||||
page += getStaticOut();
|
||||
@@ -1026,7 +1035,7 @@ String WiFiManager::getMenuOut(){
|
||||
String page;
|
||||
|
||||
for(auto menuId :_menuIds ){
|
||||
if(((String)menuId == "param") && (_paramsCount == 0)) continue; // no params set, omit params
|
||||
if(((String)menuId == "param") && (_paramsCount == 0)) continue; // no params set, omit params from menu, @todo this may be undesired by someone
|
||||
page += HTTP_PORTAL_MENU[menuId];
|
||||
}
|
||||
|
||||
@@ -1354,8 +1363,16 @@ void WiFiManager::handleWifiSave() {
|
||||
DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns);
|
||||
}
|
||||
|
||||
String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
|
||||
page += FPSTR(HTTP_SAVED);
|
||||
String page;
|
||||
|
||||
if(_ssid == ""){
|
||||
page = getHTTPHead(FPSTR(S_titlewifisettings)); // @token titleparamsaved
|
||||
page += FPSTR(HTTP_PARAMSAVED);
|
||||
}
|
||||
else {
|
||||
String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
|
||||
page += FPSTR(HTTP_SAVED);
|
||||
}
|
||||
page += FPSTR(HTTP_END);
|
||||
|
||||
server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length()));
|
||||
@@ -1926,10 +1943,21 @@ bool WiFiManager::erase(bool opt){
|
||||
DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err!=ESP_OK ? (String)err : "Success");
|
||||
return err == ESP_OK;
|
||||
}
|
||||
#elif defined(ESP8266) && defined(spiffs_api_h)
|
||||
if(opt){
|
||||
bool ret = false;
|
||||
if(SPIFFS.begin()){
|
||||
DEBUG_WM("Erasing SPIFFS");
|
||||
bool ret = SPIFFS.format();
|
||||
DEBUG_WM(DEBUG_VERBOSE,"spiffs erase: ",ret ? "Success" : "ERROR");
|
||||
} else DEBUG_WM("[ERROR] Could not start SPIFFS");
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
(void)opt;
|
||||
#endif
|
||||
|
||||
DEBUG_WM("Erasing WiFi Config");
|
||||
return WiFi_eraseConfig();
|
||||
}
|
||||
|
||||
@@ -2186,6 +2214,17 @@ void WiFiManager::setShowDnsFields(boolean alwaysShow){
|
||||
_staShowDns = alwaysShow ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle showing password in wifi password field
|
||||
* if not enabled, placeholder will be S_passph
|
||||
* @since $dev
|
||||
* @access public
|
||||
* @param boolean alwaysShow [false]
|
||||
*/
|
||||
void WiFiManager::setShowPassword(boolean show){
|
||||
_showPassword = show;
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle captive portal
|
||||
* if enabled, then devices that use captive portal checks will be redirected to root
|
||||
@@ -2278,6 +2317,15 @@ void WiFiManager::setWiFiAPChannel(int32_t channel){
|
||||
_apChannel = channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the soft ap hidden
|
||||
* @param bool wifi ap hidden, default is false
|
||||
*/
|
||||
void WiFiManager::setWiFiAPHidden(bool hidden){
|
||||
_apHidden = hidden;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* toggle showing erase wifi config button on info page
|
||||
* @param boolean enabled
|
||||
@@ -2333,6 +2381,18 @@ void WiFiManager::setMenu(std::vector<const char *>& menu){
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set params as sperate page not in wifi
|
||||
* NOT COMPATIBLE WITH setMenu! @todo scan menuids and insert param after wifi or something
|
||||
* @param bool enable
|
||||
* @since $dev
|
||||
*/
|
||||
void WiFiManager::setParamsPage(bool enable){
|
||||
_paramsInWifi= false;
|
||||
_menuIdsDefault = {"wifi","param","info","exit"};
|
||||
setMenu(_menuIdsDefault);
|
||||
}
|
||||
|
||||
// GETTERS
|
||||
|
||||
/**
|
||||
@@ -2436,8 +2496,27 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) {
|
||||
if(!_debug || _debugLevel < level) return;
|
||||
|
||||
if(_debugLevel >= DEBUG_MAX){
|
||||
_debugPort.print("MEM: ");
|
||||
_debugPort.println((String)ESP.getFreeHeap());
|
||||
uint32_t free;
|
||||
uint16_t max;
|
||||
uint8_t frag;
|
||||
#ifdef ESP8266
|
||||
ESP.getHeapStats(&free, &max, &frag);
|
||||
_debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag);
|
||||
#elif defined ESP32
|
||||
// total_free_bytes; ///< Total free bytes in the heap. Equivalent to multi_free_heap_size().
|
||||
// total_allocated_bytes; ///< Total bytes allocated to data in the heap.
|
||||
// largest_free_block; ///< Size of largest free block in the heap. This is the largest malloc-able size.
|
||||
// minimum_free_bytes; ///< Lifetime minimum free heap size. Equivalent to multi_minimum_free_heap_size().
|
||||
// allocated_blocks; ///< Number of (variable size) blocks allocated in the heap.
|
||||
// free_blocks; ///< Number of (variable size) free blocks in the heap.
|
||||
// total_blocks; ///< Total number of (variable size) blocks in the heap.
|
||||
multi_heap_info_t info;
|
||||
heap_caps_get_info(&info, MALLOC_CAP_INTERNAL);
|
||||
free = info.total_free_bytes;
|
||||
max = info.largest_free_block;
|
||||
frag = 100 - (max * 100) / free;
|
||||
_debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag);
|
||||
#endif
|
||||
}
|
||||
_debugPort.print("*WM: ");
|
||||
if(_debugLevel == DEBUG_DEV) _debugPort.print("["+(String)level+"] ");
|
||||
@@ -2602,9 +2681,9 @@ bool WiFiManager::WiFiSetCountry(){
|
||||
|
||||
#elif defined(ESP8266)
|
||||
// if(WiFi.getMode() == WIFI_OFF); // exception if wifi not init!
|
||||
if(_wificountry == "US") ret = wifi_set_country(&WM_COUNTRY_US);
|
||||
else if(_wificountry == "JP") ret = wifi_set_country(&WM_COUNTRY_JP);
|
||||
else if(_wificountry == "CN") ret = wifi_set_country(&WM_COUNTRY_CN);
|
||||
if(_wificountry == "US") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_US);
|
||||
else if(_wificountry == "JP") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_JP);
|
||||
else if(_wificountry == "CN") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_CN);
|
||||
else DEBUG_WM(DEBUG_ERROR,"[ERROR] country code not found");
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user