Skip to content

Commit

Permalink
Connect to best BSSID
Browse files Browse the repository at this point in the history
  • Loading branch information
iranl committed May 4, 2024
1 parent 2a22ae0 commit 1bfbbba
Show file tree
Hide file tree
Showing 14 changed files with 352 additions and 126 deletions.
5 changes: 5 additions & 0 deletions Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,11 @@ const String Network::networkDeviceName() const
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)
{
char str[30];
Expand Down
1 change: 1 addition & 0 deletions Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Network
int mqttConnectionState(); // 0 = not connected; 1 = connected; 2 = connected and mqtt processed
bool encryptionSupported();
const String networkDeviceName() const;
const String networkBSSID() const;

const NetworkDeviceType networkDeviceType();

Expand Down
5 changes: 3 additions & 2 deletions PreferencesKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define preference_network_hardware "nwhw"
#define preference_network_hardware_gpio "nwhwdt" // obsolete
#define preference_network_wifi_fallback_disabled "nwwififb"
#define preference_find_best_rssi "nwbestrssi"
#define preference_rssi_publish_interval "rssipb"
#define preference_hostname "hostname"
#define preference_network_timeout "nettmout"
Expand Down Expand Up @@ -80,7 +81,7 @@ class DebugPreferences
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_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_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad,
preference_keypad_control_enabled, preference_admin_enabled, preference_keypad_info_enabled, preference_acl,
Expand All @@ -100,7 +101,7 @@ class DebugPreferences
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_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_publish_authdata, preference_has_mac_saved, preference_publish_debug_info, preference_network_wifi_fallback_disabled
};
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- 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.
- 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.
- 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.
Expand Down
13 changes: 13 additions & 0 deletions WebCfgServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ bool WebCfgServer::processArgs(String& message)
_preferences->putString(preference_mqtt_hass_cu_url, value);
configChanged = true;
}
else if(key == "BESTRSSI")
{
_preferences->putBool(preference_find_best_rssi, (value == "1"));
configChanged = true;
}
else if(key == "HOSTNAME")
{
_preferences->putString(preference_hostname, value);
Expand Down Expand Up @@ -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);
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, "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, "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));
Expand Down Expand Up @@ -1210,6 +1216,13 @@ void WebCfgServer::buildInfoHtml(String &response)
response.concat("Network device: ");
response.concat(_network->networkDeviceName());
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(millis() / 1000 / 60);
Expand Down
Loading

0 comments on commit 1bfbbba

Please sign in to comment.