mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-18 00:41:43 +10:00
added signal quality filter
This commit is contained in:
+25
-15
@@ -1,8 +1,7 @@
|
||||
/**************************************************************
|
||||
WiFiManager is a library for the ESP8266/Arduino platform
|
||||
(https://github.com/esp8266/Arduino) to enable easy
|
||||
configuration and reconfiguration of WiFi credentials and
|
||||
store them in EEPROM.
|
||||
configuration and reconfiguration of WiFi credentials using a Captive Portal
|
||||
inspired by:
|
||||
http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||
https://github.com/chriscook8/esp-arduino-apboot
|
||||
@@ -127,7 +126,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) {
|
||||
//setup AP
|
||||
WiFi.mode(WIFI_AP);
|
||||
|
||||
|
||||
_apName = apName;
|
||||
_apPassword = apPassword;
|
||||
|
||||
@@ -135,7 +134,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
|
||||
if ( _apcallback != NULL) {
|
||||
_apcallback(this);
|
||||
}
|
||||
|
||||
|
||||
connect = false;
|
||||
setupConfigPortal();
|
||||
DEBUG_WM("start loop");
|
||||
@@ -267,6 +266,10 @@ void WiFiManager::setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn) {
|
||||
_sn = sn;
|
||||
}
|
||||
|
||||
void WiFiManager::setMinimumSignalQuality(int quality) {
|
||||
_minimumQuality = quality;
|
||||
}
|
||||
|
||||
|
||||
/** Handle root or redirect to captive portal */
|
||||
void WiFiManager::handleRoot() {
|
||||
@@ -328,19 +331,26 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
{
|
||||
DEBUG_WM(WiFi.SSID(i));
|
||||
DEBUG_WM(WiFi.RSSI(i));
|
||||
String item = FPSTR(HTTP_ITEM);
|
||||
String rssiQ;
|
||||
rssiQ += getRSSIasQuality(WiFi.RSSI(i));
|
||||
item.replace("{v}", WiFi.SSID(i));
|
||||
item.replace("{r}", rssiQ);
|
||||
if (WiFi.encryptionType(i) != ENC_TYPE_NONE) {
|
||||
item.replace("{i}", FPSTR(HTTP_ITEM_PADLOCK));
|
||||
int quality = getRSSIasQuality(WiFi.RSSI(i));
|
||||
|
||||
if (_minimumQuality == -1 || _minimumQuality < quality) {
|
||||
String item = FPSTR(HTTP_ITEM);
|
||||
String rssiQ;
|
||||
rssiQ += quality;
|
||||
item.replace("{v}", WiFi.SSID(i));
|
||||
item.replace("{r}", rssiQ);
|
||||
if (WiFi.encryptionType(i) != ENC_TYPE_NONE) {
|
||||
item.replace("{i}", FPSTR(HTTP_ITEM_PADLOCK));
|
||||
} else {
|
||||
item.replace("{i}", "");
|
||||
}
|
||||
//DEBUG_WM(item);
|
||||
server->sendContent(item);
|
||||
delay(0);
|
||||
} else {
|
||||
item.replace("{i}", "");
|
||||
DEBUG_WM(F("Skipping due to quality"));
|
||||
}
|
||||
//DEBUG_WM(item);
|
||||
server->sendContent(item);
|
||||
delay(0);
|
||||
|
||||
}
|
||||
server->sendContent("<br/>");
|
||||
}
|
||||
|
||||
+9
-6
@@ -1,10 +1,11 @@
|
||||
/**************************************************************
|
||||
WiFiManager is a library for the ESP8266/Arduino platform
|
||||
(https://github.com/esp8266/Arduino) to enable easy
|
||||
configuration and reconfiguration of WiFi credentials and
|
||||
store them in EEPROM.
|
||||
inspired by http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||
configuration and reconfiguration of WiFi credentials using a Captive Portal
|
||||
inspired by:
|
||||
http://www.esp8266.com/viewtopic.php?f=29&t=2520
|
||||
https://github.com/chriscook8/esp-arduino-apboot
|
||||
https://github.com/esp8266/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/DNSServer/examples/CaptivePortalAdvanced
|
||||
Built by AlexT https://github.com/tzapu
|
||||
Licensed under MIT license
|
||||
**************************************************************/
|
||||
@@ -79,6 +80,8 @@ class WiFiManager
|
||||
//in seconds
|
||||
void setTimeout(unsigned long seconds);
|
||||
void setDebugOutput(boolean debug);
|
||||
//defaults to not showing anything under 8% signal quality if called
|
||||
void setMinimumSignalQuality(int quality = 8);
|
||||
|
||||
//sets a custom ip /gateway /subnet configuration
|
||||
void setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
|
||||
@@ -112,11 +115,11 @@ class WiFiManager
|
||||
IPAddress _gw;
|
||||
IPAddress _sn;
|
||||
int _paramsCount = 0;
|
||||
int _minimumQuality = -1;
|
||||
|
||||
String getEEPROMString(int start, int len);
|
||||
void setEEPROMString(int start, int len, String string);
|
||||
//String getEEPROMString(int start, int len);
|
||||
//void setEEPROMString(int start, int len, String string);
|
||||
|
||||
// boolean keepLooping = true;
|
||||
int status = WL_IDLE_STATUS;
|
||||
int connectWifi(String ssid, String pass);
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ const char *mqtt_server = NULL;
|
||||
const char *mqtt_port = "8080";
|
||||
const char *blynk_token = "YOUR_BLYNK_TOKEN";
|
||||
|
||||
//flag for saving data
|
||||
bool shouldSaveConfig = false;
|
||||
//flag for saving data
|
||||
bool shouldSaveConfig = false;
|
||||
|
||||
//callback notifying us of the need to save config
|
||||
void saveConfigCallback () {
|
||||
@@ -79,18 +79,22 @@ void setup() {
|
||||
//WiFiManager
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
WiFiManager wifiManager;
|
||||
|
||||
|
||||
//set config save notify callback
|
||||
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
||||
|
||||
|
||||
//add all your parameters here
|
||||
wifiManager.addParameter(&custom_mqtt_server);
|
||||
wifiManager.addParameter(&custom_mqtt_port);
|
||||
wifiManager.addParameter(&custom_blynk_token);
|
||||
|
||||
//reset settings - for testing
|
||||
//wifiManager.resetSettings();
|
||||
wifiManager.resetSettings();
|
||||
|
||||
//set minimu quality of signal so it ignores AP's under that quality
|
||||
//defaults to 8%
|
||||
wifiManager.setMinimumSignalQuality();
|
||||
|
||||
//sets timeout until configuration portal gets turned off
|
||||
//useful to make it all retry or go to sleep
|
||||
//in seconds
|
||||
@@ -100,7 +104,7 @@ void setup() {
|
||||
//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("AutoConnectAP", "password")) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(3000);
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
|
||||
Reference in New Issue
Block a user