mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-17 16:41:31 +10:00
removed EEPROM dependencies
removed need to reset on save
This commit is contained in:
+35
-22
@@ -104,25 +104,33 @@ boolean WiFiManager::autoConnect(char const *apName) {
|
||||
//HTTP
|
||||
server.handleClient();
|
||||
|
||||
if(connect) {
|
||||
/*if(connect) {
|
||||
delay(5000);
|
||||
ESP.reset();
|
||||
delay(1000);
|
||||
}
|
||||
/*
|
||||
}*/
|
||||
|
||||
if(connect) {
|
||||
delay(2000);
|
||||
DEBUG_PRINT("Connecting to new AP");
|
||||
connect = false;
|
||||
ssid = getSSID();
|
||||
pass = getPassword();
|
||||
connectWifi(ssid, pass);
|
||||
//ssid = getSSID();
|
||||
//pass = getPassword();
|
||||
connectWifi(_ssid, _pass);
|
||||
int s = WiFi.status();
|
||||
if (s == WL_CONNECTED) {
|
||||
//connected
|
||||
if (s != WL_CONNECTED) {
|
||||
DEBUG_PRINT("Failed to connect.");
|
||||
//not connected, should retry everything
|
||||
//ESP.reset();
|
||||
//delay(1000);
|
||||
//return false;
|
||||
} else {
|
||||
//connected
|
||||
WiFi.mode(WIFI_STA);
|
||||
return true;
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
@@ -132,7 +140,7 @@ boolean WiFiManager::autoConnect(char const *apName) {
|
||||
|
||||
void WiFiManager::connectWifi(String ssid, String pass) {
|
||||
DEBUG_PRINT("Connecting as wifi client...");
|
||||
WiFi.disconnect();
|
||||
//WiFi.disconnect();
|
||||
WiFi.begin(ssid.c_str(), pass.c_str());
|
||||
int connRes = WiFi.waitForConnectResult();
|
||||
DEBUG_PRINT ("Connection result: ");
|
||||
@@ -143,7 +151,7 @@ void WiFiManager::connectWifi(String ssid, String pass) {
|
||||
String WiFiManager::getSSID() {
|
||||
if (_ssid == "") {
|
||||
DEBUG_PRINT("Reading EEPROM SSID");
|
||||
_ssid = getEEPROMString(0, 32);
|
||||
_ssid = WiFi.SSID();//getEEPROMString(0, 32);
|
||||
DEBUG_PRINT("SSID: ");
|
||||
DEBUG_PRINT(_ssid);
|
||||
}
|
||||
@@ -153,14 +161,14 @@ String WiFiManager::getSSID() {
|
||||
String WiFiManager::getPassword() {
|
||||
if (_pass == "") {
|
||||
DEBUG_PRINT("Reading EEPROM Password");
|
||||
_pass = getEEPROMString(32, 64);
|
||||
_pass = WiFi.psk();//getEEPROMString(32, 64);
|
||||
DEBUG_PRINT("Password: " + _pass);
|
||||
//DEBUG_PRINT(_pass);
|
||||
}
|
||||
return _pass;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void WiFiManager::setSSID(String s) {
|
||||
_ssid = s;
|
||||
setEEPROMString(0, 32, _ssid);
|
||||
@@ -171,8 +179,8 @@ void WiFiManager::setPassword(String p) {
|
||||
DEBUG_PRINT(p);
|
||||
_pass = p;
|
||||
setEEPROMString(32, 64, _pass);
|
||||
}
|
||||
|
||||
}*/
|
||||
/*
|
||||
String WiFiManager::getEEPROMString(int start, int len) {
|
||||
EEPROM.begin(512);
|
||||
delay(10);
|
||||
@@ -184,7 +192,8 @@ String WiFiManager::getEEPROMString(int start, int len) {
|
||||
EEPROM.end();
|
||||
return string;
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
void WiFiManager::setEEPROMString(int start, int len, String string) {
|
||||
EEPROM.begin(512);
|
||||
delay(10);
|
||||
@@ -203,7 +212,7 @@ void WiFiManager::setEEPROMString(int start, int len, String string) {
|
||||
}
|
||||
EEPROM.end();
|
||||
DEBUG_PRINT("Wrote " + string);
|
||||
}
|
||||
}*/
|
||||
|
||||
String WiFiManager::urldecode(const char *src)
|
||||
{
|
||||
@@ -243,12 +252,12 @@ String WiFiManager::urldecode(const char *src)
|
||||
|
||||
void WiFiManager::resetSettings() {
|
||||
//need to call it only after lib has been started with autoConnect or begin
|
||||
setEEPROMString(0, 32, "-");
|
||||
setEEPROMString(32, 64, "-");
|
||||
//setEEPROMString(0, 32, "-");
|
||||
//setEEPROMString(32, 64, "-");
|
||||
|
||||
DEBUG_PRINT("settings invalidated");
|
||||
delay(200);
|
||||
WiFi.disconnect();
|
||||
delay(200);
|
||||
}
|
||||
|
||||
void WiFiManager::setTimeout(unsigned long seconds) {
|
||||
@@ -344,8 +353,12 @@ void WiFiManager::handleWifiSave() {
|
||||
DEBUG_PRINT("WiFi save");
|
||||
//server.arg("s").toCharArray(ssid, sizeof(ssid) - 1);
|
||||
//server.arg("p").toCharArray(password, sizeof(password) - 1);
|
||||
setSSID(urldecode(server.arg("s").c_str()));
|
||||
setPassword(urldecode(server.arg("p").c_str()));
|
||||
|
||||
//SAVE/connect here
|
||||
//setSSID(urldecode(server.arg("s").c_str()));
|
||||
//setPassword(urldecode(server.arg("p").c_str()));
|
||||
_ssid = urldecode(server.arg("s").c_str());
|
||||
_pass = urldecode(server.arg("p").c_str());
|
||||
|
||||
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
server.sendHeader("Pragma", "no-cache");
|
||||
|
||||
+3
-3
@@ -14,8 +14,8 @@
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
#include <EEPROM.h>
|
||||
#include <WiFiClient.h>
|
||||
//#include <EEPROM.h>
|
||||
//#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <DNSServer.h>
|
||||
|
||||
@@ -70,7 +70,7 @@ private:
|
||||
const String HTTP_HEAD_END = "</head><body>";
|
||||
const String HTTP_ITEM = "<div><a href='#' onclick='c(this)'>{v}</a></div>";
|
||||
const String HTTP_FORM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><input id='p' name='p' length=64 placeholder='password'><br/><button type='submit'>save</button></form>";
|
||||
const String HTTP_SAVED = "<div>Credentials Saved<br />Node will reboot in 5 seconds.</div>";
|
||||
const String HTTP_SAVED = "<div>Credentials Saved<br />Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
|
||||
const String HTTP_END = "</body></html>";
|
||||
//const char HTTP_END[] PROGMEM = R"=====(
|
||||
//</body></html>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <EEPROM.h>
|
||||
#include <WiFiClient.h>
|
||||
//#include <EEPROM.h>
|
||||
//#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <DNSServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
@@ -20,7 +20,7 @@ void setup() {
|
||||
WiFiManager wifi;
|
||||
|
||||
//reset settings - for testing
|
||||
//wifi.resetSettings();
|
||||
wifi.resetSettings();
|
||||
|
||||
//sets timeout until configuration portal gets turned off
|
||||
//useful to make it all retry or go to sleep
|
||||
@@ -33,7 +33,7 @@ void setup() {
|
||||
//and goes into a blocking loop awaiting configuration
|
||||
if(!wifi.autoConnect("AutoConnectAP")) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(5000);
|
||||
delay(3000);
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.reset();
|
||||
delay(5000);
|
||||
|
||||
Reference in New Issue
Block a user