mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
getmodestr, handleerase(bool)
This commit is contained in:
+16
-8
@@ -712,7 +712,6 @@ void WiFiManager::updateConxResult(uint8_t status){
|
||||
DEBUG_WM(DEBUG_DEV,"lastconxresult:",getWLStatusString(_lastconxresult));
|
||||
}
|
||||
|
||||
// @todo uses _connectTimeout for wifi save also, add timeout argument to bypass?
|
||||
|
||||
uint8_t WiFiManager::waitForConnectResult() {
|
||||
return waitForConnectResult(_connectTimeout);
|
||||
@@ -730,7 +729,7 @@ uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) {
|
||||
}
|
||||
|
||||
unsigned long timeoutmillis = millis() + timeout;
|
||||
DEBUG_WM(DEBUG_NOTIFY,timeout,F("connectTimeout set, waiting for connect...."));
|
||||
DEBUG_WM(DEBUG_NOTIFY,timeout,F("ms connectTimeout set, waiting for connect...."));
|
||||
uint8_t status = WiFi.status();
|
||||
|
||||
while(millis() < timeoutmillis) {
|
||||
@@ -1491,13 +1490,17 @@ void WiFiManager::handleReset() {
|
||||
/**
|
||||
* HTTPD CALLBACK erase page
|
||||
*/
|
||||
void WiFiManager::handleErase() {
|
||||
|
||||
// void WiFiManager::handleErase() {
|
||||
// handleErase(false);
|
||||
// }
|
||||
void WiFiManager::handleErase(boolean opt) {
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Erase"));
|
||||
handleRequest();
|
||||
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
|
||||
page += FPSTR(HTTP_HEAD_END);
|
||||
|
||||
bool ret = WiFi_eraseConfig();
|
||||
bool ret = erase(opt);
|
||||
|
||||
if(ret) page += FPSTR(S_resetting); // @token resetting
|
||||
else {
|
||||
@@ -1664,10 +1667,10 @@ bool WiFiManager::erase(bool opt){
|
||||
DEBUG_WM("Erasing NVS");
|
||||
int err;
|
||||
err=nvs_flash_init();
|
||||
DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_init: ",err ? (String)err : "Success");
|
||||
DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_init: ",err==ESP_OK ? (String)err : "Success");
|
||||
err=nvs_flash_erase();
|
||||
DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err ? (String)err : "Success");
|
||||
return err;
|
||||
DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err==ESP_OK ? (String)err : "Success");
|
||||
return err == ESP_OK;
|
||||
}
|
||||
#else
|
||||
(void)opt;
|
||||
@@ -2172,6 +2175,11 @@ String WiFiManager::encryptionTypeStr(uint8_t authmode) {
|
||||
return AUTH_MODE_NAMES[authmode];
|
||||
}
|
||||
|
||||
String WiFiManager::getModeString(uint8_t mode){
|
||||
if(mode <= 3) return WIFI_MODES[mode];
|
||||
return FPSTR(S_NA);
|
||||
}
|
||||
|
||||
// set mode ignores WiFi.persistent
|
||||
bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) {
|
||||
#ifdef ESP8266
|
||||
@@ -2242,7 +2250,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable) {
|
||||
return WiFi_enableSTA(enable,false);
|
||||
}
|
||||
|
||||
bool WiFiManager::WiFi_eraseConfig(void) {
|
||||
bool WiFiManager::WiFi_eraseConfig() {
|
||||
#ifdef ESP8266
|
||||
#ifndef WM_FIXERASECONFIG
|
||||
return ESP.eraseConfig();
|
||||
|
||||
+4
-2
@@ -210,7 +210,7 @@ class WiFiManager
|
||||
void setShowInfoErase(boolean enabled);
|
||||
// set custom menu
|
||||
|
||||
// void setMenu(std::vector<menu_page_t>& menu);
|
||||
// set custom menu items and order
|
||||
void setMenu(std::vector<const char*>& menu);
|
||||
void setMenu(const char* menu[], uint8_t size);
|
||||
|
||||
@@ -218,6 +218,7 @@ class WiFiManager
|
||||
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();
|
||||
|
||||
@@ -322,7 +323,8 @@ class WiFiManager
|
||||
void handleNotFound();
|
||||
void handleExit();
|
||||
void handleClose();
|
||||
void handleErase();
|
||||
// void handleErase();
|
||||
void handleErase(boolean opt);
|
||||
void handleParam();
|
||||
void handleWiFiStatus();
|
||||
void handleRequest();
|
||||
|
||||
@@ -12,12 +12,16 @@ WiFiManager wifiManager;
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(true);
|
||||
delay(3000);
|
||||
Serial.println("\n Starting");
|
||||
|
||||
Serial.setDebugOutput(true);
|
||||
Serial.println(modes[WiFi.getMode()]);
|
||||
WiFi.printDiag(Serial);
|
||||
// Serial.println(modes[WiFi.getMode()]);
|
||||
// WiFi.printDiag(Serial);
|
||||
|
||||
//WiFiManager
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
WiFiManager wifiManager;
|
||||
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
//reset settings - for testing
|
||||
@@ -26,10 +30,52 @@ void setup() {
|
||||
//sets timeout until configuration portal gets turned off
|
||||
//useful to make it all retry or go to sleep
|
||||
//in seconds
|
||||
wifiManager.setConfigPortalTimeout(180);
|
||||
wifiManager.setConfigPortalTimeout(20);
|
||||
wifiManager.setConnectTimeout(10);
|
||||
// wifiManager.setShowStaticFields(true);
|
||||
|
||||
// uint8_t menu[] = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE};
|
||||
// wifiManager.setMenu(menu);
|
||||
|
||||
// std::vector<WiFiManager::menu_page_t> menu = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE,wifiManager.MENU_SEP,wifiManager.MENU_ERASE,wifiManager.MENU_EXIT};
|
||||
// wifiManager.setMenu(menu);
|
||||
|
||||
// std::vector<WiFiManager::menu_page_t> menu = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE,wifiManager.MENU_SEP,wifiManager.MENU_ERASE,wifiManager.MENU_EXIT};
|
||||
// wifiManager.setMenu(menu);
|
||||
|
||||
|
||||
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
|
||||
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6);
|
||||
WiFiManagerParameter custom_token("api_token", "api token", "", 0);
|
||||
WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0);
|
||||
|
||||
//add all your parameters here
|
||||
wifiManager.addParameter(&custom_mqtt_server);
|
||||
wifiManager.addParameter(&custom_mqtt_port);
|
||||
wifiManager.addParameter(&custom_token);
|
||||
wifiManager.addParameter(&custom_tokenb);
|
||||
|
||||
// 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"};
|
||||
// wifiManager.setMenu(menu,9);
|
||||
|
||||
std::vector<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
|
||||
wifiManager.setMenu(menu);
|
||||
|
||||
//set static ip
|
||||
wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
|
||||
// wifiManager.setShowStaticFields(false);
|
||||
// wifiManager.setShowDnsFields(false);
|
||||
|
||||
//fetches ssid and pass and tries to connect
|
||||
//if it does not connect it starts an access point with the specified name
|
||||
//here "AutoConnectAP"
|
||||
@@ -76,4 +122,4 @@ void loop() {
|
||||
}
|
||||
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -313,4 +313,6 @@ const char * const AUTH_MODE_NAMES[] PROGMEM
|
||||
"OPEN", //7 ENC_TYPE_NONE
|
||||
"WPA_WPA2_PSK", // 8 ENC_TYPE_AUTO
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const char* const WIFI_MODES[] PROGMEM = { "NULL", "STA", "AP", "STA+AP" };
|
||||
Reference in New Issue
Block a user