Connect to best BSSID
This commit is contained in:
@@ -686,6 +686,11 @@ const String Network::networkDeviceName() const
|
|||||||
return _device->deviceName();
|
return _device->deviceName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const String Network::networkBSSID() const
|
||||||
|
{
|
||||||
|
return _device->BSSIDstr();
|
||||||
|
}
|
||||||
|
|
||||||
void Network::publishFloat(const char* prefix, const char* topic, const float value, const uint8_t precision)
|
void Network::publishFloat(const char* prefix, const char* topic, const float value, const uint8_t precision)
|
||||||
{
|
{
|
||||||
char str[30];
|
char str[30];
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public:
|
|||||||
int mqttConnectionState(); // 0 = not connected; 1 = connected; 2 = connected and mqtt processed
|
int mqttConnectionState(); // 0 = not connected; 1 = connected; 2 = connected and mqtt processed
|
||||||
bool encryptionSupported();
|
bool encryptionSupported();
|
||||||
const String networkDeviceName() const;
|
const String networkDeviceName() const;
|
||||||
|
const String networkBSSID() const;
|
||||||
|
|
||||||
const NetworkDeviceType networkDeviceType();
|
const NetworkDeviceType networkDeviceType();
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#define preference_network_hardware "nwhw"
|
#define preference_network_hardware "nwhw"
|
||||||
#define preference_network_hardware_gpio "nwhwdt" // obsolete
|
#define preference_network_hardware_gpio "nwhwdt" // obsolete
|
||||||
#define preference_network_wifi_fallback_disabled "nwwififb"
|
#define preference_network_wifi_fallback_disabled "nwwififb"
|
||||||
|
#define preference_find_best_rssi "nwbestrssi"
|
||||||
#define preference_rssi_publish_interval "rssipb"
|
#define preference_rssi_publish_interval "rssipb"
|
||||||
#define preference_hostname "hostname"
|
#define preference_hostname "hostname"
|
||||||
#define preference_network_timeout "nettmout"
|
#define preference_network_timeout "nettmout"
|
||||||
@@ -80,7 +81,7 @@ private:
|
|||||||
preference_mqtt_ca, preference_mqtt_crt, preference_mqtt_key, preference_mqtt_hass_discovery, preference_mqtt_hass_cu_url,
|
preference_mqtt_ca, preference_mqtt_crt, preference_mqtt_key, preference_mqtt_hass_discovery, preference_mqtt_hass_cu_url,
|
||||||
preference_ip_dhcp_enabled, preference_ip_address, preference_ip_subnet, preference_ip_gateway, preference_ip_dns_server,
|
preference_ip_dhcp_enabled, preference_ip_address, preference_ip_subnet, preference_ip_gateway, preference_ip_dns_server,
|
||||||
preference_network_hardware, preference_network_wifi_fallback_disabled, preference_rssi_publish_interval,
|
preference_network_hardware, preference_network_wifi_fallback_disabled, preference_rssi_publish_interval,
|
||||||
preference_hostname, preference_network_timeout, preference_restart_on_disconnect,
|
preference_find_best_rssi, preference_hostname, preference_network_timeout, preference_restart_on_disconnect,
|
||||||
preference_restart_ble_beacon_lost, preference_query_interval_lockstate,
|
preference_restart_ble_beacon_lost, preference_query_interval_lockstate,
|
||||||
preference_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad,
|
preference_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad,
|
||||||
preference_keypad_control_enabled, preference_admin_enabled, preference_keypad_info_enabled, preference_acl,
|
preference_keypad_control_enabled, preference_admin_enabled, preference_keypad_info_enabled, preference_acl,
|
||||||
@@ -100,7 +101,7 @@ private:
|
|||||||
std::vector<char*> _boolPrefs =
|
std::vector<char*> _boolPrefs =
|
||||||
{
|
{
|
||||||
preference_started_before, preference_mqtt_log_enabled, preference_check_updates, preference_lock_enabled, preference_opener_enabled, preference_opener_continuous_mode,
|
preference_started_before, preference_mqtt_log_enabled, preference_check_updates, preference_lock_enabled, preference_opener_enabled, preference_opener_continuous_mode,
|
||||||
preference_restart_on_disconnect, preference_keypad_control_enabled, preference_admin_enabled, preference_keypad_info_enabled,
|
preference_find_best_rssi, preference_restart_on_disconnect, preference_keypad_control_enabled, preference_admin_enabled, preference_keypad_info_enabled,
|
||||||
preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_register_as_app, preference_ip_dhcp_enabled,
|
preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_register_as_app, preference_ip_dhcp_enabled,
|
||||||
preference_publish_authdata, preference_has_mac_saved, preference_publish_debug_info, preference_network_wifi_fallback_disabled
|
preference_publish_authdata, preference_has_mac_saved, preference_publish_debug_info, preference_network_wifi_fallback_disabled
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ In a browser navigate to the IP address assigned to the ESP32.
|
|||||||
- MQTT SSL Client Key: Optionally set to the Client SSL key of the MQTT broker, see the "MQTT Encryption" section of this README.
|
- MQTT SSL Client Key: Optionally set to the Client SSL key of the MQTT broker, see the "MQTT Encryption" section of this README.
|
||||||
- Network hardware: "Wi-Fi only" by default, set to one of the specified ethernet modules if available, see the "Supported Ethernet devices" and "Connecting via Ethernet" section of this README.
|
- Network hardware: "Wi-Fi only" by default, set to one of the specified ethernet modules if available, see the "Supported Ethernet devices" and "Connecting via Ethernet" section of this README.
|
||||||
- Disable fallback to Wi-Fi / Wi-Fi config portal: By default the Nuki Hub will fallback to Wi-Fi and open the Wi-Fi configuration portal when the network connection fails. Enable this setting to disable this fallback.
|
- Disable fallback to Wi-Fi / Wi-Fi config portal: By default the Nuki Hub will fallback to Wi-Fi and open the Wi-Fi configuration portal when the network connection fails. Enable this setting to disable this fallback.
|
||||||
|
- Connect to AP with the best signal in an environment with multiple APs with the same SSID: Enable to perform a scan for the Access Point with the best signal strenght for the specified SSID in a multi AP/Mesh environment.
|
||||||
- RSSI Publish interval: Set to a positive integer to set the amount of seconds between updates to the maintenance/wifiRssi MQTT topic with the current Wi-Fi RSSI, set to -1 to disable, default 60.
|
- RSSI Publish interval: Set to a positive integer to set the amount of seconds between updates to the maintenance/wifiRssi MQTT topic with the current Wi-Fi RSSI, set to -1 to disable, default 60.
|
||||||
- Network Timeout until restart: Set to a positive integer to restart the Nuki Hub after the set amount of seconds has passed without an active connection to the MQTT broker, set to -1 to disable, default 60.
|
- Network Timeout until restart: Set to a positive integer to restart the Nuki Hub after the set amount of seconds has passed without an active connection to the MQTT broker, set to -1 to disable, default 60.
|
||||||
- Restart on disconnect: Enable to restart the Nuki Hub after 60 seconds without a connection to a network.
|
- Restart on disconnect: Enable to restart the Nuki Hub after 60 seconds without a connection to a network.
|
||||||
|
|||||||
@@ -371,6 +371,11 @@ bool WebCfgServer::processArgs(String& message)
|
|||||||
_preferences->putString(preference_mqtt_hass_cu_url, value);
|
_preferences->putString(preference_mqtt_hass_cu_url, value);
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
}
|
}
|
||||||
|
else if(key == "BESTRSSI")
|
||||||
|
{
|
||||||
|
_preferences->putBool(preference_find_best_rssi, (value == "1"));
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
else if(key == "HOSTNAME")
|
else if(key == "HOSTNAME")
|
||||||
{
|
{
|
||||||
_preferences->putString(preference_hostname, value);
|
_preferences->putString(preference_hostname, value);
|
||||||
@@ -955,6 +960,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
|||||||
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported(), true);
|
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported(), true);
|
||||||
printDropDown(response, "NWHW", "Network hardware", String(_preferences->getInt(preference_network_hardware)), getNetworkDetectionOptions());
|
printDropDown(response, "NWHW", "Network hardware", String(_preferences->getInt(preference_network_hardware)), getNetworkDetectionOptions());
|
||||||
printCheckBox(response, "NWHWWIFIFB", "Disable fallback to Wi-Fi / Wi-Fi config portal", _preferences->getBool(preference_network_wifi_fallback_disabled));
|
printCheckBox(response, "NWHWWIFIFB", "Disable fallback to Wi-Fi / Wi-Fi config portal", _preferences->getBool(preference_network_wifi_fallback_disabled));
|
||||||
|
printCheckBox(response, "BESTRSSI", "Connect to AP with the best signal in an environment with multiple APs with the same SSID", _preferences->getBool(preference_find_best_rssi));
|
||||||
printInputField(response, "RSSI", "RSSI Publish interval (seconds; -1 to disable)", _preferences->getInt(preference_rssi_publish_interval), 6);
|
printInputField(response, "RSSI", "RSSI Publish interval (seconds; -1 to disable)", _preferences->getInt(preference_rssi_publish_interval), 6);
|
||||||
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
|
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
|
||||||
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
|
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
|
||||||
@@ -1211,6 +1217,13 @@ void WebCfgServer::buildInfoHtml(String &response)
|
|||||||
response.concat(_network->networkDeviceName());
|
response.concat(_network->networkDeviceName());
|
||||||
response.concat("\n");
|
response.concat("\n");
|
||||||
|
|
||||||
|
if(_network->networkDeviceName() == "Built-in Wi-Fi")
|
||||||
|
{
|
||||||
|
response.concat("BSSID of AP: ");
|
||||||
|
response.concat(_network->networkBSSID());
|
||||||
|
response.concat("\n");
|
||||||
|
}
|
||||||
|
|
||||||
response.concat("Uptime: ");
|
response.concat("Uptime: ");
|
||||||
response.concat(millis() / 1000 / 60);
|
response.concat(millis() / 1000 / 60);
|
||||||
response.concat(" minutes\n");
|
response.concat(" minutes\n");
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "WiFiManager.h"
|
#include "WiFiManager.h"
|
||||||
|
#include "hardware/WifiEthServer.h"
|
||||||
|
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
|
||||||
@@ -211,6 +212,17 @@ WiFiManager::WiFiManager(Print& consolePort):_debugPort(consolePort){
|
|||||||
WiFiManagerInit();
|
WiFiManagerInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WiFiManager::WiFiManager(const char* user, const char* password) {
|
||||||
|
WiFiManagerInit();
|
||||||
|
|
||||||
|
if(strlen(user) > 0)
|
||||||
|
{
|
||||||
|
strcpy(_credUser, user);
|
||||||
|
strcpy(_credPassword, password);
|
||||||
|
_hasCredentials = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WiFiManager::WiFiManager() {
|
WiFiManager::WiFiManager() {
|
||||||
WiFiManagerInit();
|
WiFiManagerInit();
|
||||||
}
|
}
|
||||||
@@ -627,7 +639,7 @@ void WiFiManager::setupHTTPServer(){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
server.reset(new WM_WebServer(_httpPort));
|
server.reset(new WM_WebServer(new WifiEthServer(80)));
|
||||||
// This is not the safest way to reset the webserver, it can cause crashes on callbacks initilized before this and since its a shared pointer...
|
// This is not the safest way to reset the webserver, it can cause crashes on callbacks initilized before this and since its a shared pointer...
|
||||||
|
|
||||||
if ( _webservercallback != NULL) {
|
if ( _webservercallback != NULL) {
|
||||||
@@ -1110,7 +1122,65 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){
|
|||||||
#endif
|
#endif
|
||||||
WiFi_enableSTA(true,storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default)
|
WiFi_enableSTA(true,storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default)
|
||||||
WiFi.persistent(true);
|
WiFi.persistent(true);
|
||||||
ret = WiFi.begin(ssid.c_str(), pass.c_str(), 0, NULL, connect);
|
|
||||||
|
if (_findBestRSSI) {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(F("find best RSSI: TRUE"));
|
||||||
|
#endif
|
||||||
|
if (!_numNetworks)
|
||||||
|
WiFi_scanNetworks(); // scan in case this gets called before any scans
|
||||||
|
|
||||||
|
int n = _numNetworks;
|
||||||
|
if (n == 0) {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(F("No networks found"));
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(n, F("networks found"));
|
||||||
|
#endif
|
||||||
|
int bestConnection = -1;
|
||||||
|
// Find best RSSI AP for given SSID
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (ssid == WiFi.SSID(i)) {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(String(F("SSID ")) + ssid + String(F(" found with RSSI: ")) +
|
||||||
|
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||||
|
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||||
|
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||||
|
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||||
|
#endif
|
||||||
|
if (bestConnection == -1) {
|
||||||
|
bestConnection = i;
|
||||||
|
} else {
|
||||||
|
if (WiFi.RSSI(i) > WiFi.RSSI(bestConnection)) {
|
||||||
|
bestConnection = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bestConnection == -1) {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(F("No network found with SSID: "), ssid);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(String(F("Trying to connect to SSID ")) + ssid + String(F(" found with RSSI: ")) +
|
||||||
|
String(WiFi.RSSI(bestConnection)) + String(F("(")) +
|
||||||
|
String(constrain((100.0 + WiFi.RSSI(bestConnection)) * 2, 0, 100)) +
|
||||||
|
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(bestConnection) +
|
||||||
|
String(F(" and channel: ")) + String(WiFi.channel(bestConnection)));
|
||||||
|
#endif
|
||||||
|
ret = WiFi.begin(ssid.c_str(), pass.c_str(), 0, WiFi.BSSID(bestConnection), connect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(F("find best RSSI: FALSE"));
|
||||||
|
#endif
|
||||||
|
ret = WiFi.begin(ssid.c_str(), pass.c_str(), 0, NULL, connect);
|
||||||
|
}
|
||||||
|
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi begin failed"));
|
if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi begin failed"));
|
||||||
@@ -1126,9 +1196,12 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){
|
|||||||
bool WiFiManager::wifiConnectDefault(){
|
bool WiFiManager::wifiConnectDefault(){
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
|
String ssid = WiFi_SSID(true);
|
||||||
|
String pass = WiFi_psk(true);
|
||||||
|
|
||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(F("Connecting to SAVED AP:"),WiFi_SSID(true));
|
DEBUG_WM(F("Connecting to SAVED AP:"),ssid);
|
||||||
DEBUG_WM(WM_DEBUG_DEV,F("Using Password:"),WiFi_psk(true));
|
DEBUG_WM(WM_DEBUG_DEV,F("Using Password:"),pass);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = WiFi_enableSTA(true,storeSTAmode);
|
ret = WiFi_enableSTA(true,storeSTAmode);
|
||||||
@@ -1139,7 +1212,63 @@ bool WiFiManager::wifiConnectDefault(){
|
|||||||
if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi enableSta failed"));
|
if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi enableSta failed"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = WiFi.begin();
|
if (_findBestRSSI) {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(F("find best RSSI: TRUE"));
|
||||||
|
#endif
|
||||||
|
if (!_numNetworks)
|
||||||
|
WiFi_scanNetworks(); // scan in case this gets called before any scans
|
||||||
|
|
||||||
|
int n = _numNetworks;
|
||||||
|
if (n == 0) {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(F("No networks found"));
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(n, F("networks found"));
|
||||||
|
#endif
|
||||||
|
int bestConnection = -1;
|
||||||
|
// Find best RSSI AP for given SSID
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (ssid == WiFi.SSID(i)) {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(String(F("SSID ")) + ssid + String(F(" found with RSSI: ")) +
|
||||||
|
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||||
|
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||||
|
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||||
|
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||||
|
#endif
|
||||||
|
if (bestConnection == -1) {
|
||||||
|
bestConnection = i;
|
||||||
|
} else {
|
||||||
|
if (WiFi.RSSI(i) > WiFi.RSSI(bestConnection)) {
|
||||||
|
bestConnection = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bestConnection == -1) {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(F("No network found with SSID: "), ssid);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(String(F("Trying to connect to SSID ")) + ssid + String(F(" found with RSSI: ")) +
|
||||||
|
String(WiFi.RSSI(bestConnection)) + String(F("(")) +
|
||||||
|
String(constrain((100.0 + WiFi.RSSI(bestConnection)) * 2, 0, 100)) +
|
||||||
|
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(bestConnection) +
|
||||||
|
String(F(" and channel: ")) + String(WiFi.channel(bestConnection)));
|
||||||
|
#endif
|
||||||
|
ret = WiFi.begin(ssid.c_str(), pass.c_str(), 0, WiFi.BSSID(bestConnection), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#ifdef WM_DEBUG_LEVEL
|
||||||
|
DEBUG_WM(F("find best RSSI: FALSE"));
|
||||||
|
#endif
|
||||||
|
ret = WiFi.begin();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi begin failed"));
|
if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi begin failed"));
|
||||||
@@ -1330,6 +1459,9 @@ void WiFiManager::handleRoot() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Root"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Root"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(_title); // @token options @todo replace options with title
|
String page = getHTTPHead(_title); // @token options @todo replace options with title
|
||||||
@@ -1356,6 +1488,9 @@ void WiFiManager::handleWifi(boolean scan) {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Wifi"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Wifi"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi
|
String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi
|
||||||
if (scan) {
|
if (scan) {
|
||||||
@@ -1412,6 +1547,9 @@ void WiFiManager::handleParam(){
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi
|
String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi
|
||||||
|
|
||||||
@@ -1792,6 +1930,9 @@ void WiFiManager::handleWiFiStatus(){
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi status "));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi status "));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page;
|
String page;
|
||||||
// String page = "{\"result\":true,\"count\":1}";
|
// String page = "{\"result\":true,\"count\":1}";
|
||||||
@@ -1809,6 +1950,9 @@ void WiFiManager::handleWifiSave() {
|
|||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi save "));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi save "));
|
||||||
DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
|
|
||||||
//SAVE/connect here
|
//SAVE/connect here
|
||||||
@@ -1907,6 +2051,9 @@ void WiFiManager::handleParamSave() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
|
|
||||||
doParamSave();
|
doParamSave();
|
||||||
@@ -1976,6 +2123,9 @@ void WiFiManager::handleInfo() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Info"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Info"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo
|
String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo
|
||||||
reportStatus(page);
|
reportStatus(page);
|
||||||
@@ -2321,6 +2471,9 @@ void WiFiManager::handleExit() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Exit"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Exit"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
|
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
|
||||||
page += FPSTR(S_exiting); // @token exiting
|
page += FPSTR(S_exiting); // @token exiting
|
||||||
@@ -2338,6 +2491,9 @@ void WiFiManager::handleReset() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Reset"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Reset"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset
|
String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset
|
||||||
page += FPSTR(S_resetting); //@token resetting
|
page += FPSTR(S_resetting); //@token resetting
|
||||||
@@ -2363,6 +2519,9 @@ void WiFiManager::handleErase(boolean opt) {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_NOTIFY,F("<- HTTP Erase"));
|
DEBUG_WM(WM_DEBUG_NOTIFY,F("<- HTTP Erase"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
handleRequest();
|
handleRequest();
|
||||||
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
|
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
|
||||||
|
|
||||||
@@ -2425,7 +2584,7 @@ boolean WiFiManager::captivePortal() {
|
|||||||
|
|
||||||
if(!_enableCaptivePortal || !configPortalActive) return false; // skip redirections if cp not enabled or not in ap mode
|
if(!_enableCaptivePortal || !configPortalActive) return false; // skip redirections if cp not enabled or not in ap mode
|
||||||
|
|
||||||
String serverLoc = toStringIp(server->client().localIP());
|
String serverLoc = toStringIp(server->client()->localIP());
|
||||||
|
|
||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_DEV,"-> " + server->hostHeader());
|
DEBUG_WM(WM_DEBUG_DEV,"-> " + server->hostHeader());
|
||||||
@@ -2450,7 +2609,7 @@ boolean WiFiManager::captivePortal() {
|
|||||||
#endif
|
#endif
|
||||||
server->sendHeader(F("Location"), (String)F("http://") + serverLoc, true); // @HTTPHEAD send redirect
|
server->sendHeader(F("Location"), (String)F("http://") + serverLoc, true); // @HTTPHEAD send redirect
|
||||||
server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
|
||||||
server->client().stop(); // Stop is needed because we sent no content length
|
server->client()->stop(); // Stop is needed because we sent no content length
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -2464,6 +2623,9 @@ void WiFiManager::stopCaptivePortal(){
|
|||||||
// HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined
|
// HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined
|
||||||
void WiFiManager::handleClose(){
|
void WiFiManager::handleClose(){
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling Captive Portal"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling Captive Portal"));
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
stopCaptivePortal();
|
stopCaptivePortal();
|
||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP close"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP close"));
|
||||||
@@ -2991,6 +3153,14 @@ void WiFiManager::setCaptivePortalEnable(boolean enabled){
|
|||||||
_enableCaptivePortal = enabled;
|
_enableCaptivePortal = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* toggle connecting to the best AP based on RSSI
|
||||||
|
* @param boolean enabled [false]
|
||||||
|
*/
|
||||||
|
void WiFiManager::setFindBestRSSI(boolean enabled) {
|
||||||
|
_findBestRSSI = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* toggle wifi autoreconnect policy
|
* toggle wifi autoreconnect policy
|
||||||
* if enabled, then wifi will autoreconnect automatically always
|
* if enabled, then wifi will autoreconnect automatically always
|
||||||
@@ -3873,6 +4043,9 @@ void WiFiManager::handleUpdate() {
|
|||||||
#ifdef WM_DEBUG_LEVEL
|
#ifdef WM_DEBUG_LEVEL
|
||||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Handle update"));
|
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Handle update"));
|
||||||
#endif
|
#endif
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||||
String page = getHTTPHead(_title); // @token options
|
String page = getHTTPHead(_title); // @token options
|
||||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||||
@@ -3984,6 +4157,9 @@ void WiFiManager::handleUpdateDone() {
|
|||||||
DEBUG_WM(WM_DEBUG_VERBOSE, F("<- Handle update done"));
|
DEBUG_WM(WM_DEBUG_VERBOSE, F("<- Handle update done"));
|
||||||
// if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
// if (captivePortal()) return; // If captive portal redirect instead of displaying the page
|
||||||
|
|
||||||
|
if (_hasCredentials && !server->authenticate(_credUser, _credPassword)) {
|
||||||
|
return server->requestAuthentication();
|
||||||
|
}
|
||||||
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
String page = getHTTPHead(FPSTR(S_options)); // @token options
|
||||||
String str = FPSTR(HTTP_ROOT_MAIN);
|
String str = FPSTR(HTTP_ROOT_MAIN);
|
||||||
str.replace(FPSTR(T_t),_title);
|
str.replace(FPSTR(T_t),_title);
|
||||||
|
|||||||
@@ -248,6 +248,7 @@ class WiFiManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WiFiManager(Print& consolePort);
|
WiFiManager(Print& consolePort);
|
||||||
|
WiFiManager(const char* user, const char* password);
|
||||||
WiFiManager();
|
WiFiManager();
|
||||||
~WiFiManager();
|
~WiFiManager();
|
||||||
void WiFiManagerInit();
|
void WiFiManagerInit();
|
||||||
@@ -412,6 +413,9 @@ class WiFiManager
|
|||||||
// if true (default) then stop the config portal from autoConnect when wifi is saved
|
// if true (default) then stop the config portal from autoConnect when wifi is saved
|
||||||
void setDisableConfigPortal(boolean enable);
|
void setDisableConfigPortal(boolean enable);
|
||||||
|
|
||||||
|
// if true then find the AP with the best RSSI for the given SSID
|
||||||
|
void setFindBestRSSI(boolean enabled);
|
||||||
|
|
||||||
// set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266
|
// set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266
|
||||||
bool setHostname(const char * hostname);
|
bool setHostname(const char * hostname);
|
||||||
bool setHostname(String hostname);
|
bool setHostname(String hostname);
|
||||||
@@ -593,6 +597,7 @@ class WiFiManager
|
|||||||
boolean _showBack = false; // show back button
|
boolean _showBack = false; // show back button
|
||||||
boolean _enableConfigPortal = true; // FOR autoconnect - start config portal if autoconnect failed
|
boolean _enableConfigPortal = true; // FOR autoconnect - start config portal if autoconnect failed
|
||||||
boolean _disableConfigPortal = true; // FOR autoconnect - stop config portal if cp wifi save
|
boolean _disableConfigPortal = true; // FOR autoconnect - stop config portal if cp wifi save
|
||||||
|
boolean _findBestRSSI = false; // find best rssi ap in wifiscan
|
||||||
String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS
|
String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS
|
||||||
|
|
||||||
const char* _customHeadElement = ""; // store custom head element html from user isnide <head>
|
const char* _customHeadElement = ""; // store custom head element html from user isnide <head>
|
||||||
@@ -837,6 +842,10 @@ protected:
|
|||||||
std::function<void()> _preotaupdatecallback;
|
std::function<void()> _preotaupdatecallback;
|
||||||
std::function<void()> _configportaltimeoutcallback;
|
std::function<void()> _configportaltimeoutcallback;
|
||||||
|
|
||||||
|
bool _hasCredentials = false;
|
||||||
|
char _credUser[31] = {0};
|
||||||
|
char _credPassword[31] = {0};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
|
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {
|
||||||
return obj->fromString(s);
|
return obj->fromString(s);
|
||||||
|
|||||||
@@ -143,3 +143,8 @@ String EthLan8720Device::localIP()
|
|||||||
{
|
{
|
||||||
return ETH.localIP().toString();
|
return ETH.localIP().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String EthLan8720Device::BSSIDstr()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ public:
|
|||||||
int8_t signalStrength() override;
|
int8_t signalStrength() override;
|
||||||
|
|
||||||
String localIP() override;
|
String localIP() override;
|
||||||
|
String BSSIDstr() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onDisconnected();
|
void onDisconnected();
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public:
|
|||||||
virtual int8_t signalStrength() = 0;
|
virtual int8_t signalStrength() = 0;
|
||||||
|
|
||||||
virtual String localIP() = 0;
|
virtual String localIP() = 0;
|
||||||
|
virtual String BSSIDstr() = 0;
|
||||||
|
|
||||||
virtual void mqttSetClientId(const char* clientId);
|
virtual void mqttSetClientId(const char* clientId);
|
||||||
virtual void mqttSetCleanSession(bool cleanSession);
|
virtual void mqttSetCleanSession(bool cleanSession);
|
||||||
|
|||||||
@@ -225,3 +225,8 @@ String W5500Device::localIP()
|
|||||||
{
|
{
|
||||||
return Ethernet.localIP().toString();
|
return Ethernet.localIP().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String W5500Device::BSSIDstr()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@ public:
|
|||||||
int8_t signalStrength() override;
|
int8_t signalStrength() override;
|
||||||
|
|
||||||
String localIP() override;
|
String localIP() override;
|
||||||
|
String BSSIDstr() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resetDevice();
|
void resetDevice();
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ void WifiDevice::initialize()
|
|||||||
wm_menu.push_back("exit");
|
wm_menu.push_back("exit");
|
||||||
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
|
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
|
||||||
// reduced tieout if ESP is set to restart on disconnect
|
// reduced tieout if ESP is set to restart on disconnect
|
||||||
|
_wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi));
|
||||||
_wm.setConfigPortalTimeout(_restartOnDisconnect ? 60 * 3 : 60 * 30);
|
_wm.setConfigPortalTimeout(_restartOnDisconnect ? 60 * 3 : 60 * 30);
|
||||||
_wm.setShowInfoUpdate(false);
|
_wm.setShowInfoUpdate(false);
|
||||||
_wm.setMenu(wm_menu);
|
_wm.setMenu(wm_menu);
|
||||||
@@ -159,6 +160,11 @@ String WifiDevice::localIP()
|
|||||||
return WiFi.localIP().toString();
|
return WiFi.localIP().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String WifiDevice::BSSIDstr()
|
||||||
|
{
|
||||||
|
return WiFi.BSSIDstr();
|
||||||
|
}
|
||||||
|
|
||||||
void WifiDevice::clearRtcInitVar(WiFiManager *)
|
void WifiDevice::clearRtcInitVar(WiFiManager *)
|
||||||
{
|
{
|
||||||
memset(WiFiDevice_reconfdetect, 0, sizeof WiFiDevice_reconfdetect);
|
memset(WiFiDevice_reconfdetect, 0, sizeof WiFiDevice_reconfdetect);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public:
|
|||||||
int8_t signalStrength() override;
|
int8_t signalStrength() override;
|
||||||
|
|
||||||
String localIP() override;
|
String localIP() override;
|
||||||
|
String BSSIDstr() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void clearRtcInitVar(WiFiManager*);
|
static void clearRtcInitVar(WiFiManager*);
|
||||||
|
|||||||
Reference in New Issue
Block a user