Merge branch 'master' of github.com:technyon/nuki_hub
This commit is contained in:
4
.github/workflows/nightly.yml
vendored
4
.github/workflows/nightly.yml
vendored
@@ -20,8 +20,8 @@ jobs:
|
||||
- name: Get new commits
|
||||
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV
|
||||
- name: Check if commits larger than 1
|
||||
if: ${{ env.NEW_COMMIT_COUNT > 1 }}
|
||||
run: echo
|
||||
if: ${{ env.NEW_COMMIT_COUNT < 2 }}
|
||||
run: exit 1
|
||||
build:
|
||||
name: Build ${{ matrix.board }} (${{ matrix.build }})
|
||||
if: github.repository == 'technyon/nuki_hub'
|
||||
|
||||
@@ -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.
|
||||
- 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.
|
||||
- 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.
|
||||
- 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.
|
||||
@@ -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>
|
||||
<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>
|
||||
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>
|
||||
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 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>
|
||||
|
||||
## MQTT Encryption (optional; Wi-Fi and LAN8720 only)
|
||||
|
||||
@@ -1124,6 +1124,9 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){
|
||||
WiFi.persistent(true);
|
||||
|
||||
if (_findBestRSSI) {
|
||||
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(F("find best RSSI: TRUE"));
|
||||
#endif
|
||||
@@ -1691,6 +1694,10 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){
|
||||
return false;
|
||||
}
|
||||
|
||||
void WiFiManager::resetScan(){
|
||||
_numNetworks = 0;
|
||||
}
|
||||
|
||||
String WiFiManager::WiFiManager::getScanItemOut(){
|
||||
String page;
|
||||
|
||||
@@ -4013,7 +4020,7 @@ String WiFiManager::WiFi_psk(bool persistent) const {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(WM_DEBUG_VERBOSE,F("[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"));
|
||||
#endif
|
||||
WiFi.reconnect();
|
||||
//WiFi.reconnect();
|
||||
#endif
|
||||
}
|
||||
else if(event == ARDUINO_EVENT_WIFI_SCAN_DONE && _asyncScan){
|
||||
|
||||
@@ -279,6 +279,9 @@ class WiFiManager
|
||||
|
||||
// erase wifi credentials
|
||||
void resetSettings();
|
||||
|
||||
// reset wifi scan
|
||||
void resetScan();
|
||||
|
||||
// reboot esp
|
||||
void reboot();
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
"build": "10011844059.2.1"
|
||||
},
|
||||
"master": {
|
||||
"time": "2024-07-28 01:58:24",
|
||||
"time": "2024-07-31 01:35:29",
|
||||
"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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -104,6 +104,7 @@
|
||||
#define mqtt_topic_restart_reason_esp "/maintenance/restartReasonNukiEsp"
|
||||
#define mqtt_topic_mqtt_connection_state "/maintenance/mqttConnectionState"
|
||||
#define mqtt_topic_network_device "/maintenance/networkDevice"
|
||||
#define mqtt_hybrid_state "/maintenance/hybridConnected"
|
||||
|
||||
#define mqtt_topic_presence "/presence/devices"
|
||||
|
||||
|
||||
@@ -237,6 +237,8 @@ bool NukiNetwork::update()
|
||||
void NukiNetwork::initialize()
|
||||
{
|
||||
_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;
|
||||
|
||||
_hostname = _preferences->getString(preference_hostname);
|
||||
@@ -358,20 +360,22 @@ bool NukiNetwork::update()
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!_device->isConnected())
|
||||
if(!_device->isConnected() || (_mqttConnectCounter > 15 && _reconnectNetworkOnMqttDisconnect && !_firstConnect))
|
||||
{
|
||||
_mqttConnectCounter = 0;
|
||||
|
||||
if(_firstDisconnected) {
|
||||
_firstDisconnected = false;
|
||||
_device->mqttDisconnect(true);
|
||||
}
|
||||
|
||||
|
||||
if(_restartOnDisconnect && (esp_timer_get_time() / 1000) > 60000)
|
||||
{
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
|
||||
Log->println(F("Network not connected. Trying reconnect."));
|
||||
ReconnectStatus reconnectStatus = _device->reconnect();
|
||||
ReconnectStatus reconnectStatus = _device->reconnect(true);
|
||||
|
||||
switch(reconnectStatus)
|
||||
{
|
||||
@@ -405,8 +409,11 @@ bool NukiNetwork::update()
|
||||
bool success = reconnect();
|
||||
if(!success)
|
||||
{
|
||||
delay(2000);
|
||||
_mqttConnectCounter++;
|
||||
return false;
|
||||
}
|
||||
_mqttConnectCounter = 0;
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
@@ -418,11 +425,11 @@ bool NukiNetwork::update()
|
||||
delay(200);
|
||||
restartEsp(RestartReason::NetworkTimeoutWatchdog);
|
||||
}
|
||||
|
||||
|
||||
delay(2000);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
_lastConnectedTs = ts;
|
||||
|
||||
#if PRESENCE_DETECTION_ENABLED
|
||||
@@ -471,7 +478,7 @@ bool NukiNetwork::update()
|
||||
_lastMaintenanceTs = ts;
|
||||
}
|
||||
|
||||
if(_preferences->getBool(preference_check_updates))
|
||||
if(_checkUpdates)
|
||||
{
|
||||
if(_lastUpdateCheckTs == 0 || (ts - _lastUpdateCheckTs) > 86400000)
|
||||
{
|
||||
@@ -846,7 +853,7 @@ void NukiNetwork::publishLongLong(const char* prefix, const char *topic, int64_t
|
||||
char c;
|
||||
uint8_t base = 10;
|
||||
|
||||
while (value)
|
||||
while (value)
|
||||
{
|
||||
int num = value % base;
|
||||
value /= base;
|
||||
@@ -1015,6 +1022,105 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (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
|
||||
publishHassTopic("sensor",
|
||||
"firmware_version",
|
||||
@@ -3437,6 +3543,11 @@ void NukiNetwork::removeHASSConfig(char* uidString)
|
||||
removeHassTopic((char*)"number", (char*)"unlocked_position_offset_degrees", uidString);
|
||||
removeHassTopic((char*)"switch", (char*)"pairing_enabled", 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)
|
||||
|
||||
@@ -159,6 +159,7 @@ private:
|
||||
Gpio* _gpio;
|
||||
|
||||
int _mqttConnectionState = 0;
|
||||
int _mqttConnectCounter = 0;
|
||||
long _mqttConnectedTs = -1;
|
||||
bool _connectReplyReceived = false;
|
||||
bool _firstDisconnected = true;
|
||||
@@ -172,6 +173,8 @@ private:
|
||||
int _networkTimeout = 0;
|
||||
std::vector<MqttReceiver*> _mqttReceivers;
|
||||
bool _restartOnDisconnect = false;
|
||||
bool _checkUpdates = false;
|
||||
bool _reconnectNetworkOnMqttDisconnect = false;
|
||||
bool _firstConnect = true;
|
||||
bool _publishDebugInfo = false;
|
||||
bool _logIp = true;
|
||||
|
||||
@@ -864,6 +864,11 @@ void NukiWrapper::onConfigUpdateReceivedCallback(const char *value)
|
||||
nukiInst->onConfigUpdateReceived(value);
|
||||
}
|
||||
|
||||
bool NukiWrapper::offConnected()
|
||||
{
|
||||
return _network->_offConnected;
|
||||
}
|
||||
|
||||
Nuki::AdvertisingMode NukiWrapper::advertisingModeToEnum(const char *str)
|
||||
{
|
||||
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->println((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;
|
||||
else _nextHybridLockStateUpdateTs = 0;
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
const bool isPaired() const;
|
||||
const bool hasKeypad() const;
|
||||
bool hasDoorSensor() const;
|
||||
bool offConnected();
|
||||
const BLEAddress getBleAddress() const;
|
||||
|
||||
std::string firmwareVersion() const;
|
||||
@@ -126,13 +127,13 @@ private:
|
||||
int _retryConfigCount = 0;
|
||||
int _retryLockstateCount = 0;
|
||||
int _rssiPublishInterval = 0;
|
||||
int64_t _nextRetryTs = 0;
|
||||
int64_t _nextRetryTs = 0;
|
||||
int64_t _nextLockStateUpdateTs = 0;
|
||||
int64_t _nextHybridLockStateUpdateTs = 0;
|
||||
int64_t _nextBatteryReportTs = 0;
|
||||
int64_t _nextConfigUpdateTs = 0;
|
||||
int64_t _waitAuthLogUpdateTs = 0;
|
||||
int64_t _waitKeypadUpdateTs = 0;
|
||||
int64_t _waitKeypadUpdateTs = 0;
|
||||
int64_t _waitTimeControlUpdateTs = 0;
|
||||
int64_t _nextKeypadUpdateTs = 0;
|
||||
int64_t _nextRssiTs = 0;
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
#define preference_ota_updater_url (char*)"otaUpdUrl"
|
||||
#define preference_update_from_mqtt (char*)"updMqtt"
|
||||
#define preference_show_secrets (char*)"showSecr"
|
||||
#define preference_recon_netw_on_mqtt_discon (char*)"recNtwMqttDis"
|
||||
|
||||
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_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_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 =
|
||||
{
|
||||
@@ -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_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_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 =
|
||||
{
|
||||
|
||||
@@ -1013,6 +1013,11 @@ bool WebCfgServer::processArgs(String& message)
|
||||
_preferences->putBool(preference_restart_on_disconnect, (value == "1"));
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "RECNWTMQTTDIS")
|
||||
{
|
||||
_preferences->putBool(preference_recon_netw_on_mqtt_discon, (value == "1"));
|
||||
configChanged = true;
|
||||
}
|
||||
else if(key == "MQTTLOG")
|
||||
{
|
||||
_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));
|
||||
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)
|
||||
@@ -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, "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, "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, "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), "");
|
||||
|
||||
@@ -143,7 +143,7 @@ bool EthLan8720Device::isConnected()
|
||||
return ETH.linkUp();
|
||||
}
|
||||
|
||||
ReconnectStatus EthLan8720Device::reconnect()
|
||||
ReconnectStatus EthLan8720Device::reconnect(bool force)
|
||||
{
|
||||
if(!_hardwareInitialized)
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
|
||||
virtual void initialize();
|
||||
virtual void reconfigure();
|
||||
virtual ReconnectStatus reconnect();
|
||||
virtual ReconnectStatus reconnect(bool force = false);
|
||||
bool supportsEncryption() override;
|
||||
|
||||
virtual bool isConnected();
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
virtual const String deviceName() const = 0;
|
||||
|
||||
virtual void initialize() = 0;
|
||||
virtual ReconnectStatus reconnect() = 0;
|
||||
virtual ReconnectStatus reconnect(bool force = false) = 0;
|
||||
virtual void reconfigure() = 0;
|
||||
virtual void printError();
|
||||
virtual bool supportsEncryption() = 0;
|
||||
|
||||
@@ -79,7 +79,7 @@ void W5500Device::initialize()
|
||||
reconnect();
|
||||
}
|
||||
|
||||
ReconnectStatus W5500Device::reconnect()
|
||||
ReconnectStatus W5500Device::reconnect(bool force)
|
||||
{
|
||||
_hasDHCPAddress = false;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
const String deviceName() const override;
|
||||
|
||||
virtual void initialize();
|
||||
virtual ReconnectStatus reconnect();
|
||||
virtual ReconnectStatus reconnect(bool force = false);
|
||||
virtual void reconfigure();
|
||||
|
||||
bool supportsEncryption() override;
|
||||
|
||||
@@ -72,6 +72,7 @@ void WifiDevice::initialize()
|
||||
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
|
||||
// reduced timeout if ESP is set to restart on disconnect
|
||||
_wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi));
|
||||
_wm.setConnectTimeout(5);
|
||||
_wm.setConfigPortalTimeout(_restartOnDisconnect ? 60 * 3 : 60 * 30);
|
||||
_wm.setShowInfoUpdate(false);
|
||||
_wm.setMenu(wm_menu);
|
||||
@@ -141,32 +142,25 @@ bool WifiDevice::isConnected()
|
||||
return WiFi.isConnected();
|
||||
}
|
||||
|
||||
ReconnectStatus WifiDevice::reconnect()
|
||||
ReconnectStatus WifiDevice::reconnect(bool force)
|
||||
{
|
||||
if(!isConnected() && !_isReconnecting)
|
||||
if((!isConnected() || force) && !_isReconnecting)
|
||||
{
|
||||
_isReconnecting = true;
|
||||
WiFi.disconnect();
|
||||
delay(1000);
|
||||
if(!_preferences->getBool(preference_find_best_rssi, false)) WiFi.reconnect();
|
||||
else
|
||||
int loop = 0;
|
||||
|
||||
while(isConnected() && loop <20)
|
||||
{
|
||||
if(WiFi.getMode() & WIFI_STA){
|
||||
WiFi.mode(WIFI_OFF);
|
||||
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(100);
|
||||
loop++;
|
||||
}
|
||||
delay(10000);
|
||||
|
||||
_wm.resetScan();
|
||||
_wm.autoConnect();
|
||||
_isReconnecting = false;
|
||||
}
|
||||
|
||||
|
||||
if(!isConnected() && _disconnectTs > (esp_timer_get_time() / 1000) - 120000) _wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled));
|
||||
return isConnected() ? ReconnectStatus::Success : ReconnectStatus::Failure;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
virtual void initialize();
|
||||
virtual void reconfigure();
|
||||
virtual ReconnectStatus reconnect();
|
||||
virtual ReconnectStatus reconnect(bool force = false);
|
||||
bool supportsEncryption() override;
|
||||
|
||||
virtual bool isConnected();
|
||||
|
||||
Reference in New Issue
Block a user