Merge branch 'master' of github.com:technyon/nuki_hub

This commit is contained in:
technyon
2024-07-31 13:18:42 +02:00
29 changed files with 184 additions and 42 deletions

View File

@@ -20,8 +20,8 @@ jobs:
- name: Get new commits - name: Get new commits
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV
- name: Check if commits larger than 1 - name: Check if commits larger than 1
if: ${{ env.NEW_COMMIT_COUNT > 1 }} if: ${{ env.NEW_COMMIT_COUNT < 2 }}
run: echo run: exit 1
build: build:
name: Build ${{ matrix.board }} (${{ matrix.build }}) name: Build ${{ matrix.board }} (${{ matrix.build }})
if: github.repository == 'technyon/nuki_hub' if: github.repository == 'technyon/nuki_hub'

View File

@@ -128,6 +128,7 @@ In a browser navigate to the IP address assigned to the ESP32.
- 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.
- MQTT 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. - MQTT 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 when disconnected from the network. - Restart on disconnect: Enable to restart the Nuki Hub when disconnected from the network.
- Reconnect network on MQTT connection failure: Enable to force reconnection to the network when connection to the MQTT broker fails (after 15 tries).
- Enable MQTT logging: Enable to fill the maintenance/log MQTT topic with debug log information. - Enable MQTT logging: Enable to fill the maintenance/log MQTT topic with debug log information.
- Check for Firmware Updates every 24h: Enable to allow the Nuki Hub to check the latest release of the Nuki Hub firmware on boot and every 24 hours. Requires the Nuki Hub to be able to connect to github.com. The latest version will be published to MQTT and will be visible on the main page of the Web Configurator. - Check for Firmware Updates every 24h: Enable to allow the Nuki Hub to check the latest release of the Nuki Hub firmware on boot and every 24 hours. Requires the Nuki Hub to be able to connect to github.com. The latest version will be published to MQTT and will be visible on the main page of the Web Configurator.
- Allow updating using MQTT: Enable to allow starting the Nuki Hub update process using MQTT. Will also enable the Home Assistant update functionality if auto discovery is enabled. - Allow updating using MQTT: Enable to allow starting the Nuki Hub update process using MQTT. Will also enable the Home Assistant update functionality if auto discovery is enabled.
@@ -440,8 +441,8 @@ After about a minute the new firmware should be installed afterwhich the ESP wil
Selecting the wrong binary will lead to an unsuccessfull update<br> Selecting the wrong binary will lead to an unsuccessfull update<br>
<br> <br>
<b> Note for users upgrading from Nuki Hub 8.35 or lower:</b><br> <b> Note for users upgrading from Nuki Hub 8.35 or lower:</b><br>
Updating to version 8.36 requires a change to the partition table of the ESP32.<br> Updating to version 9.00 requires a change to the partition table of the ESP32.<br>
Please follow the instructions for the [First time installation](#first-time-installation) once when updating to Nuki Hub 8.36 from an earlier version.<br> Please follow the instructions for the [First time installation](#first-time-installation) once when updating to Nuki Hub 9.00 from an earlier version.<br>
Your settings will not be affected when updating using the above instructions (do not select erase device when updating using Webflash).<br> Your settings will not be affected when updating using the above instructions (do not select erase device when updating using Webflash).<br>
## MQTT Encryption (optional; Wi-Fi and LAN8720 only) ## MQTT Encryption (optional; Wi-Fi and LAN8720 only)

View File

@@ -1124,6 +1124,9 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){
WiFi.persistent(true); WiFi.persistent(true);
if (_findBestRSSI) { if (_findBestRSSI) {
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
#ifdef WM_DEBUG_LEVEL #ifdef WM_DEBUG_LEVEL
DEBUG_WM(F("find best RSSI: TRUE")); DEBUG_WM(F("find best RSSI: TRUE"));
#endif #endif
@@ -1691,6 +1694,10 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){
return false; return false;
} }
void WiFiManager::resetScan(){
_numNetworks = 0;
}
String WiFiManager::WiFiManager::getScanItemOut(){ String WiFiManager::WiFiManager::getScanItemOut(){
String page; String page;
@@ -4013,7 +4020,7 @@ String WiFiManager::WiFi_psk(bool persistent) const {
#ifdef WM_DEBUG_LEVEL #ifdef WM_DEBUG_LEVEL
DEBUG_WM(WM_DEBUG_VERBOSE,F("[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting")); DEBUG_WM(WM_DEBUG_VERBOSE,F("[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"));
#endif #endif
WiFi.reconnect(); //WiFi.reconnect();
#endif #endif
} }
else if(event == ARDUINO_EVENT_WIFI_SCAN_DONE && _asyncScan){ else if(event == ARDUINO_EVENT_WIFI_SCAN_DONE && _asyncScan){

View File

@@ -280,6 +280,9 @@ class WiFiManager
// erase wifi credentials // erase wifi credentials
void resetSettings(); void resetSettings();
// reset wifi scan
void resetScan();
// reboot esp // reboot esp
void reboot(); void reboot();

View File

@@ -10,8 +10,8 @@
"build": "10011844059.2.1" "build": "10011844059.2.1"
}, },
"master": { "master": {
"time": "2024-07-28 01:58:24", "time": "2024-07-31 01:35:29",
"version": "9.00", "version": "9.00",
"build": "10128035068.11.1" "build": "10172451695.14.1"
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -104,6 +104,7 @@
#define mqtt_topic_restart_reason_esp "/maintenance/restartReasonNukiEsp" #define mqtt_topic_restart_reason_esp "/maintenance/restartReasonNukiEsp"
#define mqtt_topic_mqtt_connection_state "/maintenance/mqttConnectionState" #define mqtt_topic_mqtt_connection_state "/maintenance/mqttConnectionState"
#define mqtt_topic_network_device "/maintenance/networkDevice" #define mqtt_topic_network_device "/maintenance/networkDevice"
#define mqtt_hybrid_state "/maintenance/hybridConnected"
#define mqtt_topic_presence "/presence/devices" #define mqtt_topic_presence "/presence/devices"

View File

@@ -237,6 +237,8 @@ bool NukiNetwork::update()
void NukiNetwork::initialize() void NukiNetwork::initialize()
{ {
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect, false); _restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect, false);
_checkUpdates = _preferences->getBool(preference_check_updates, false);
_reconnectNetworkOnMqttDisconnect = _preferences->getBool(preference_recon_netw_on_mqtt_discon, false);
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000; _rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000;
_hostname = _preferences->getString(preference_hostname); _hostname = _preferences->getString(preference_hostname);
@@ -358,8 +360,10 @@ bool NukiNetwork::update()
return true; return true;
} }
if(!_device->isConnected()) if(!_device->isConnected() || (_mqttConnectCounter > 15 && _reconnectNetworkOnMqttDisconnect && !_firstConnect))
{ {
_mqttConnectCounter = 0;
if(_firstDisconnected) { if(_firstDisconnected) {
_firstDisconnected = false; _firstDisconnected = false;
_device->mqttDisconnect(true); _device->mqttDisconnect(true);
@@ -371,7 +375,7 @@ bool NukiNetwork::update()
} }
Log->println(F("Network not connected. Trying reconnect.")); Log->println(F("Network not connected. Trying reconnect."));
ReconnectStatus reconnectStatus = _device->reconnect(); ReconnectStatus reconnectStatus = _device->reconnect(true);
switch(reconnectStatus) switch(reconnectStatus)
{ {
@@ -405,8 +409,11 @@ bool NukiNetwork::update()
bool success = reconnect(); bool success = reconnect();
if(!success) if(!success)
{ {
delay(2000);
_mqttConnectCounter++;
return false; return false;
} }
_mqttConnectCounter = 0;
delay(2000); delay(2000);
} }
@@ -471,7 +478,7 @@ bool NukiNetwork::update()
_lastMaintenanceTs = ts; _lastMaintenanceTs = ts;
} }
if(_preferences->getBool(preference_check_updates)) if(_checkUpdates)
{ {
if(_lastUpdateCheckTs == 0 || (ts - _lastUpdateCheckTs) > 86400000) if(_lastUpdateCheckTs == 0 || (ts - _lastUpdateCheckTs) > 86400000)
{ {
@@ -1015,6 +1022,105 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
{ (char*)"stat_on", (char*)"1" }, { (char*)"stat_on", (char*)"1" },
{ (char*)"stat_off", (char*)"0" }}); { (char*)"stat_off", (char*)"0" }});
// Network device
publishHassTopic("sensor",
"network_device",
uidString,
"_network_device",
"Network device",
name,
baseTopic,
_lockPath + mqtt_topic_network_device,
deviceType,
"",
"",
"diagnostic",
"",
{ { (char*)"en", (char*)"true" }});
// Nuki Hub Webserver enabled
publishHassTopic("switch",
"webserver",
uidString,
"_webserver",
"Nuki Hub webserver enabled",
name,
baseTopic,
_lockPath + mqtt_topic_webserver_state,
deviceType,
"",
"",
"diagnostic",
_lockPath + mqtt_topic_webserver_action,
{ { (char*)"pl_on", (char*)"1" },
{ (char*)"pl_off", (char*)"0" },
{ (char*)"stat_on", (char*)"1" },
{ (char*)"stat_off", (char*)"0" }});
// Uptime
publishHassTopic("sensor",
"uptime",
uidString,
"_uptime",
"Uptime",
name,
baseTopic,
_lockPath + mqtt_topic_uptime,
deviceType,
"",
"",
"diagnostic",
"",
{ { (char*)"en", (char*)"true" }});
if(_preferences->getBool(preference_mqtt_log_enabled, false))
{
// MQTT Log
publishHassTopic("sensor",
"mqtt_log",
uidString,
"_mqtt_log",
"MQTT Log",
name,
baseTopic,
_lockPath + mqtt_topic_log,
deviceType,
"",
"",
"diagnostic",
"",
{ { (char*)"en", (char*)"true" }});
}
else
{
removeHassTopic((char*)"sensor", (char*)"mqtt_log", uidString);
}
if(_preferences->getBool(preference_official_hybrid, false))
{
// Hybrid connected
publishHassTopic("binary_sensor",
"hybrid_connected",
uidString,
"_hybrid_connected",
"Hybrid connected",
name,
baseTopic,
_lockPath + mqtt_hybrid_state,
deviceType,
"",
"",
"diagnostic",
"",
{ {(char*)"pl_on", (char*)"1"},
{(char*)"pl_off", (char*)"0"},
{ (char*)"en", (char*)"true" }});
}
else
{
removeHassTopic((char*)"binary_sensor", (char*)"hybrid_connected", uidString);
}
// Firmware version // Firmware version
publishHassTopic("sensor", publishHassTopic("sensor",
"firmware_version", "firmware_version",
@@ -3437,6 +3543,11 @@ void NukiNetwork::removeHASSConfig(char* uidString)
removeHassTopic((char*)"number", (char*)"unlocked_position_offset_degrees", uidString); removeHassTopic((char*)"number", (char*)"unlocked_position_offset_degrees", uidString);
removeHassTopic((char*)"switch", (char*)"pairing_enabled", uidString); removeHassTopic((char*)"switch", (char*)"pairing_enabled", uidString);
removeHassTopic((char*)"switch", (char*)"auto_unlatch", uidString); removeHassTopic((char*)"switch", (char*)"auto_unlatch", uidString);
removeHassTopic((char*)"sensor", (char*)"network_device", uidString);
removeHassTopic((char*)"switch", (char*)"webserver", uidString);
removeHassTopic((char*)"sensor", (char*)"uptime", uidString);
removeHassTopic((char*)"sensor", (char*)"mqtt_log", uidString);
removeHassTopic((char*)"binary_sensor", (char*)"hybrid_connected", uidString);
} }
void NukiNetwork::removeHASSConfigTopic(char *deviceType, char *name, char *uidString) void NukiNetwork::removeHASSConfigTopic(char *deviceType, char *name, char *uidString)

View File

@@ -159,6 +159,7 @@ private:
Gpio* _gpio; Gpio* _gpio;
int _mqttConnectionState = 0; int _mqttConnectionState = 0;
int _mqttConnectCounter = 0;
long _mqttConnectedTs = -1; long _mqttConnectedTs = -1;
bool _connectReplyReceived = false; bool _connectReplyReceived = false;
bool _firstDisconnected = true; bool _firstDisconnected = true;
@@ -172,6 +173,8 @@ private:
int _networkTimeout = 0; int _networkTimeout = 0;
std::vector<MqttReceiver*> _mqttReceivers; std::vector<MqttReceiver*> _mqttReceivers;
bool _restartOnDisconnect = false; bool _restartOnDisconnect = false;
bool _checkUpdates = false;
bool _reconnectNetworkOnMqttDisconnect = false;
bool _firstConnect = true; bool _firstConnect = true;
bool _publishDebugInfo = false; bool _publishDebugInfo = false;
bool _logIp = true; bool _logIp = true;

View File

@@ -864,6 +864,11 @@ void NukiWrapper::onConfigUpdateReceivedCallback(const char *value)
nukiInst->onConfigUpdateReceived(value); nukiInst->onConfigUpdateReceived(value);
} }
bool NukiWrapper::offConnected()
{
return _network->_offConnected;
}
Nuki::AdvertisingMode NukiWrapper::advertisingModeToEnum(const char *str) Nuki::AdvertisingMode NukiWrapper::advertisingModeToEnum(const char *str)
{ {
if(strcmp(str, "Automatic") == 0) return Nuki::AdvertisingMode::Automatic; if(strcmp(str, "Automatic") == 0) return Nuki::AdvertisingMode::Automatic;
@@ -972,6 +977,7 @@ void NukiWrapper::onOfficialUpdateReceived(const char *topic, const char *value)
Log->print(F("Connected: ")); Log->print(F("Connected: "));
Log->println((strcmp(value, "true") == 0 ? 1 : 0)); Log->println((strcmp(value, "true") == 0 ? 1 : 0));
_network->_offConnected = (strcmp(value, "true") == 0 ? 1 : 0); _network->_offConnected = (strcmp(value, "true") == 0 ? 1 : 0);
_network->publishBool(mqtt_hybrid_state, _network->_offConnected, true);
if(!_network->_offConnected) _nextHybridLockStateUpdateTs = (esp_timer_get_time() / 1000) + _intervalHybridLockstate * 1000; if(!_network->_offConnected) _nextHybridLockStateUpdateTs = (esp_timer_get_time() / 1000) + _intervalHybridLockstate * 1000;
else _nextHybridLockStateUpdateTs = 0; else _nextHybridLockStateUpdateTs = 0;

View File

@@ -37,6 +37,7 @@ public:
const bool isPaired() const; const bool isPaired() const;
const bool hasKeypad() const; const bool hasKeypad() const;
bool hasDoorSensor() const; bool hasDoorSensor() const;
bool offConnected();
const BLEAddress getBleAddress() const; const BLEAddress getBleAddress() const;
std::string firmwareVersion() const; std::string firmwareVersion() const;

View File

@@ -97,6 +97,7 @@
#define preference_ota_updater_url (char*)"otaUpdUrl" #define preference_ota_updater_url (char*)"otaUpdUrl"
#define preference_update_from_mqtt (char*)"updMqtt" #define preference_update_from_mqtt (char*)"updMqtt"
#define preference_show_secrets (char*)"showSecr" #define preference_show_secrets (char*)"showSecr"
#define preference_recon_netw_on_mqtt_discon (char*)"recNtwMqttDis"
inline bool initPreferences(Preferences* preferences) inline bool initPreferences(Preferences* preferences)
{ {
@@ -248,7 +249,8 @@ private:
preference_cred_password, preference_disable_non_json, preference_publish_authdata, preference_publish_debug_info, preference_presence_detection_timeout, preference_cred_password, preference_disable_non_json, preference_publish_authdata, preference_publish_debug_info, preference_presence_detection_timeout,
preference_official_hybrid, preference_query_interval_hybrid_lockstate, preference_official_hybrid_actions, preference_official_hybrid_retry, preference_has_mac_saved, preference_official_hybrid, preference_query_interval_hybrid_lockstate, preference_official_hybrid_actions, preference_official_hybrid_retry, preference_has_mac_saved,
preference_has_mac_byte_0, preference_has_mac_byte_1, preference_has_mac_byte_2, preference_latest_version, preference_task_size_network, preference_task_size_nuki, preference_has_mac_byte_0, preference_has_mac_byte_1, preference_has_mac_byte_2, preference_latest_version, preference_task_size_network, preference_task_size_nuki,
preference_authlog_max_entries, preference_keypad_max_entries, preference_timecontrol_max_entries, preference_update_from_mqtt, preference_show_secrets preference_authlog_max_entries, preference_keypad_max_entries, preference_timecontrol_max_entries, preference_update_from_mqtt, preference_show_secrets,
preference_recon_netw_on_mqtt_discon
}; };
std::vector<char*> _redact = std::vector<char*> _redact =
{ {
@@ -262,7 +264,8 @@ private:
preference_restart_on_disconnect, preference_keypad_control_enabled, preference_keypad_info_enabled, preference_keypad_publish_code, preference_show_secrets, preference_restart_on_disconnect, preference_keypad_control_enabled, preference_keypad_info_enabled, preference_keypad_publish_code, preference_show_secrets,
preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_register_as_app, preference_register_opener_as_app, preference_ip_dhcp_enabled, preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_register_as_app, preference_register_opener_as_app, preference_ip_dhcp_enabled,
preference_publish_authdata, preference_has_mac_saved, preference_publish_debug_info, preference_network_wifi_fallback_disabled, preference_official_hybrid, preference_publish_authdata, preference_has_mac_saved, preference_publish_debug_info, preference_network_wifi_fallback_disabled, preference_official_hybrid,
preference_official_hybrid_actions, preference_official_hybrid_retry, preference_conf_info_enabled, preference_disable_non_json, preference_update_from_mqtt preference_official_hybrid_actions, preference_official_hybrid_retry, preference_conf_info_enabled, preference_disable_non_json, preference_update_from_mqtt,
preference_recon_netw_on_mqtt_discon
}; };
std::vector<char*> _bytePrefs = std::vector<char*> _bytePrefs =
{ {

View File

@@ -1013,6 +1013,11 @@ bool WebCfgServer::processArgs(String& message)
_preferences->putBool(preference_restart_on_disconnect, (value == "1")); _preferences->putBool(preference_restart_on_disconnect, (value == "1"));
configChanged = true; configChanged = true;
} }
else if(key == "RECNWTMQTTDIS")
{
_preferences->putBool(preference_recon_netw_on_mqtt_discon, (value == "1"));
configChanged = true;
}
else if(key == "MQTTLOG") else if(key == "MQTTLOG")
{ {
_preferences->putBool(preference_mqtt_log_enabled, (value == "1")); _preferences->putBool(preference_mqtt_log_enabled, (value == "1"));
@@ -2000,6 +2005,12 @@ void WebCfgServer::buildHtml(String& response)
{ {
String lockState = pinStateToString(_preferences->getInt(preference_lock_pin_status, 4)); String lockState = pinStateToString(_preferences->getInt(preference_lock_pin_status, 4));
printParameter(response, "Nuki Lock PIN status", lockState.c_str(), "", "lockPin"); printParameter(response, "Nuki Lock PIN status", lockState.c_str(), "", "lockPin");
if(_preferences->getBool(preference_official_hybrid, false))
{
String offConnected = _nuki->offConnected() ? "Yes": "No";
printParameter(response, "Nuki Lock hybrid mode connected", offConnected.c_str(), "", "lockHybrid");
}
} }
} }
if(_nukiOpener != nullptr) if(_nukiOpener != nullptr)
@@ -2153,6 +2164,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
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", "MQTT Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5, ""); printInputField(response, "NETTIMEOUT", "MQTT 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), "");
printCheckBox(response, "RECNWTMQTTDIS", "Reconnect network on MQTT connection failure", _preferences->getBool(preference_recon_netw_on_mqtt_discon), "");
printCheckBox(response, "MQTTLOG", "Enable MQTT logging", _preferences->getBool(preference_mqtt_log_enabled), ""); printCheckBox(response, "MQTTLOG", "Enable MQTT logging", _preferences->getBool(preference_mqtt_log_enabled), "");
printCheckBox(response, "CHECKUPDATE", "Check for Firmware Updates every 24h", _preferences->getBool(preference_check_updates), ""); printCheckBox(response, "CHECKUPDATE", "Check for Firmware Updates every 24h", _preferences->getBool(preference_check_updates), "");
printCheckBox(response, "UPDATEMQTT", "Allow updating using MQTT", _preferences->getBool(preference_update_from_mqtt), ""); printCheckBox(response, "UPDATEMQTT", "Allow updating using MQTT", _preferences->getBool(preference_update_from_mqtt), "");

View File

@@ -143,7 +143,7 @@ bool EthLan8720Device::isConnected()
return ETH.linkUp(); return ETH.linkUp();
} }
ReconnectStatus EthLan8720Device::reconnect() ReconnectStatus EthLan8720Device::reconnect(bool force)
{ {
if(!_hardwareInitialized) if(!_hardwareInitialized)
{ {

View File

@@ -55,7 +55,7 @@ public:
virtual void initialize(); virtual void initialize();
virtual void reconfigure(); virtual void reconfigure();
virtual ReconnectStatus reconnect(); virtual ReconnectStatus reconnect(bool force = false);
bool supportsEncryption() override; bool supportsEncryption() override;
virtual bool isConnected(); virtual bool isConnected();

View File

@@ -24,7 +24,7 @@ public:
virtual const String deviceName() const = 0; virtual const String deviceName() const = 0;
virtual void initialize() = 0; virtual void initialize() = 0;
virtual ReconnectStatus reconnect() = 0; virtual ReconnectStatus reconnect(bool force = false) = 0;
virtual void reconfigure() = 0; virtual void reconfigure() = 0;
virtual void printError(); virtual void printError();
virtual bool supportsEncryption() = 0; virtual bool supportsEncryption() = 0;

View File

@@ -79,7 +79,7 @@ void W5500Device::initialize()
reconnect(); reconnect();
} }
ReconnectStatus W5500Device::reconnect() ReconnectStatus W5500Device::reconnect(bool force)
{ {
_hasDHCPAddress = false; _hasDHCPAddress = false;

View File

@@ -23,7 +23,7 @@ public:
const String deviceName() const override; const String deviceName() const override;
virtual void initialize(); virtual void initialize();
virtual ReconnectStatus reconnect(); virtual ReconnectStatus reconnect(bool force = false);
virtual void reconfigure(); virtual void reconfigure();
bool supportsEncryption() override; bool supportsEncryption() override;

View File

@@ -72,6 +72,7 @@ void WifiDevice::initialize()
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled)); _wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
// reduced timeout if ESP is set to restart on disconnect // reduced timeout if ESP is set to restart on disconnect
_wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi)); _wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi));
_wm.setConnectTimeout(5);
_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);
@@ -141,29 +142,22 @@ bool WifiDevice::isConnected()
return WiFi.isConnected(); return WiFi.isConnected();
} }
ReconnectStatus WifiDevice::reconnect() ReconnectStatus WifiDevice::reconnect(bool force)
{ {
if(!isConnected() && !_isReconnecting) if((!isConnected() || force) && !_isReconnecting)
{ {
_isReconnecting = true; _isReconnecting = true;
WiFi.disconnect(); WiFi.disconnect();
delay(1000); int loop = 0;
if(!_preferences->getBool(preference_find_best_rssi, false)) WiFi.reconnect();
else while(isConnected() && loop <20)
{ {
if(WiFi.getMode() & WIFI_STA){ delay(100);
WiFi.mode(WIFI_OFF); loop++;
int timeout = (esp_timer_get_time() / 1000)+1200;
while(WiFi.getMode()!= WIFI_OFF && (esp_timer_get_time() / 1000)<timeout){
delay(0);
}
}
delay(5000);
_wm.WiFi_scanNetworks(true, false);
delay(5000);
_wm.wifiConnectDefault();
} }
delay(10000);
_wm.resetScan();
_wm.autoConnect();
_isReconnecting = false; _isReconnecting = false;
} }

View File

@@ -23,7 +23,7 @@ public:
virtual void initialize(); virtual void initialize();
virtual void reconfigure(); virtual void reconfigure();
virtual ReconnectStatus reconnect(); virtual ReconnectStatus reconnect(bool force = false);
bool supportsEncryption() override; bool supportsEncryption() override;
virtual bool isConnected(); virtual bool isConnected();