mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
cleanup and get said name as per https://github.com/tzapu/WiFiManager/pull/52
added example of above
This commit is contained in:
+11
-7
@@ -49,13 +49,11 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
DEBUG_WM(p->getID());
|
||||
}
|
||||
|
||||
void WiFiManager::setupConfigPortal(char const *apName, char const *apPassword) {
|
||||
void WiFiManager::setupConfigPortal() {
|
||||
dnsServer.reset(new DNSServer());
|
||||
server.reset(new ESP8266WebServer(80));
|
||||
|
||||
DEBUG_WM(F(""));
|
||||
_apName = apName;
|
||||
_apPassword = apPassword;
|
||||
start = millis();
|
||||
|
||||
DEBUG_WM(F("Configuring access point... "));
|
||||
@@ -130,14 +128,17 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
//setup AP
|
||||
WiFi.mode(WIFI_AP);
|
||||
|
||||
_apName = apName;
|
||||
_apPassword = apPassword;
|
||||
|
||||
//notify we entered AP mode
|
||||
if ( _apcallback != NULL) {
|
||||
_apcallback();
|
||||
}
|
||||
|
||||
connect = false;
|
||||
setupConfigPortal(apName, apPassword);
|
||||
|
||||
setupConfigPortal();
|
||||
DEBUG_WM("start loop");
|
||||
while (timeout == 0 || millis() < start + timeout) {
|
||||
//DNS
|
||||
dnsServer->processNextRequest();
|
||||
@@ -169,7 +170,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
|
||||
server.reset();
|
||||
dnsServer.reset();
|
||||
|
||||
DEBUG_WM("end loop");
|
||||
return WiFi.status() == WL_CONNECTED;
|
||||
}
|
||||
|
||||
@@ -205,6 +206,10 @@ String WiFiManager::getPassword() {
|
||||
return _pass;
|
||||
}
|
||||
|
||||
String WiFiManager::getConfigPortalSSID() {
|
||||
return _apName;
|
||||
}
|
||||
|
||||
String WiFiManager::urldecode(const char *src)
|
||||
{
|
||||
String decoded = "";
|
||||
@@ -477,7 +482,6 @@ void WiFiManager::DEBUG_WM(Generic text) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int WiFiManager::getRSSIasQuality(int RSSI) {
|
||||
int quality = 0;
|
||||
|
||||
|
||||
+4
-1
@@ -67,6 +67,9 @@ class WiFiManager
|
||||
String getSSID();
|
||||
String getPassword();
|
||||
|
||||
// get the AP name of the config portal, so it can be used in the callback
|
||||
String getConfigPortalSSID();
|
||||
|
||||
void resetSettings();
|
||||
//for convenience
|
||||
String urldecode(const char*);
|
||||
@@ -96,7 +99,7 @@ class WiFiManager
|
||||
|
||||
const String HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>";
|
||||
|
||||
void setupConfigPortal(char const *apName, char const *apPassword);
|
||||
void setupConfigPortal();
|
||||
|
||||
int _eepromStart;
|
||||
const char* _apName = "no-net";
|
||||
|
||||
@@ -3,11 +3,17 @@
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
#include "WiFiManager.h" //https://github.com/tzapu/WiFiManager
|
||||
|
||||
//WiFiManger
|
||||
//global intialization: this wastes memory, only used here to have access to wifiManager.getConfigPortalSSID()
|
||||
WiFiManager wifiManager;
|
||||
|
||||
void configModeCallback () {
|
||||
Serial.println("Entered config mode");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
//if you used auto generated SSID, print it
|
||||
Serial.println(wifiManager.getConfigPortalSSID());
|
||||
}
|
||||
|
||||
void setup() {
|
||||
@@ -16,17 +22,18 @@ void setup() {
|
||||
|
||||
//WiFiManager
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
WiFiManager wifiManager;
|
||||
//WiFiManager wifiManager;
|
||||
//reset settings - for testing
|
||||
//wifiManager.resetSettings();
|
||||
|
||||
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
|
||||
wifiManager.setAPCallback(configModeCallback);
|
||||
|
||||
//fetches ssid and pass and tries to connect
|
||||
//if it does not connect it starts an access point with the specified name
|
||||
//here "AutoConnectAP"
|
||||
//and goes into a blocking loop awaiting configuration
|
||||
if(!wifiManager.autoConnect("AutoConnectAP")) {
|
||||
if(!wifiManager.autoConnect()) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.reset();
|
||||
|
||||
Reference in New Issue
Block a user