diff --git a/Config.h b/Config.h index f85e225..fb1ed2d 100644 --- a/Config.h +++ b/Config.h @@ -1,6 +1,6 @@ #pragma once -#define NUKI_HUB_VERSION "8.14" +#define NUKI_HUB_VERSION "8.15" #define MQTT_QOS_LEVEL 1 #define MQTT_CLEAN_SESSIONS false diff --git a/Network.cpp b/Network.cpp index c06ae1a..69b79d7 100644 --- a/Network.cpp +++ b/Network.cpp @@ -196,6 +196,11 @@ bool Network::update() _device->update(); + if(!_mqttEnabled) + { + return true; + } + if(!_device->isConnected()) { if(_restartOnDisconnect && millis() > 60000) @@ -1073,3 +1078,9 @@ void Network::clearWifiFallback() { memset(WiFi_fallbackDetect, 0, sizeof(WiFi_fallbackDetect)); } + +void Network::disableMqtt() +{ + _device->disableMqtt(); + _mqttEnabled = false; +} diff --git a/Network.h b/Network.h index c30cc8b..0a81a1a 100644 --- a/Network.h +++ b/Network.h @@ -27,6 +27,7 @@ public: void reconfigureDevice(); void setMqttPresencePath(char* path); void disableAutoRestarts(); // disable on OTA start + void disableMqtt(); void subscribe(const char* prefix, const char* path); void initTopic(const char* prefix, const char* path, const char* value); @@ -115,6 +116,7 @@ private: unsigned long _lastConnectedTs = 0; unsigned long _lastMaintenanceTs = 0; unsigned long _lastRssiTs = 0; + bool _mqttEnabled = true; static unsigned long _ignoreSubscriptionsTs; long _rssiPublishInterval = 0; std::function _keepAliveCallback = nullptr; diff --git a/NukiOpenerWrapper.cpp b/NukiOpenerWrapper.cpp index cda5e59..36acc7b 100644 --- a/NukiOpenerWrapper.cpp +++ b/NukiOpenerWrapper.cpp @@ -681,3 +681,8 @@ std::string NukiOpenerWrapper::hardwareVersion() const { return _hardwareVersion; } + +void NukiOpenerWrapper::disableWatchdog() +{ + _restartBeaconTimeout = -1; +} diff --git a/NukiOpenerWrapper.h b/NukiOpenerWrapper.h index c5821d0..51dd574 100644 --- a/NukiOpenerWrapper.h +++ b/NukiOpenerWrapper.h @@ -22,6 +22,8 @@ public: void disableHASS(); + void disableWatchdog(); + const NukiOpener::OpenerState& keyTurnerState(); const bool isPaired(); const bool hasKeypad(); diff --git a/NukiWrapper.cpp b/NukiWrapper.cpp index b057bf1..b988aeb 100644 --- a/NukiWrapper.cpp +++ b/NukiWrapper.cpp @@ -709,3 +709,8 @@ std::string NukiWrapper::hardwareVersion() const { return _hardwareVersion; } + +void NukiWrapper::disableWatchdog() +{ + _restartBeaconTimeout = -1; +} diff --git a/NukiWrapper.h b/NukiWrapper.h index 9912d49..9ac1080 100644 --- a/NukiWrapper.h +++ b/NukiWrapper.h @@ -25,6 +25,8 @@ public: void disableHASS(); + void disableWatchdog(); + const NukiLock::KeyTurnerState& keyTurnerState(); const bool isPaired(); const bool hasKeypad(); diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 39c7b56..4a43b5f 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -1071,6 +1071,15 @@ void WebCfgServer::handleOtaUpload() _otaStartTs = millis(); esp_task_wdt_init(30, false); _network->disableAutoRestarts(); + _network->disableMqtt(); + if(_nuki != nullptr) + { + _nuki->disableWatchdog(); + } + if(_nukiOpener != nullptr) + { + _nukiOpener->disableWatchdog(); + } Log->print("handleFileUpload Name: "); Log->println(filename); } else if (upload.status == UPLOAD_FILE_WRITE) diff --git a/networkDevices/EthLan8720Device.cpp b/networkDevices/EthLan8720Device.cpp index ddcd960..d586d84 100644 --- a/networkDevices/EthLan8720Device.cpp +++ b/networkDevices/EthLan8720Device.cpp @@ -130,13 +130,15 @@ ReconnectStatus EthLan8720Device::reconnect() void EthLan8720Device::update() { - if(_useEncryption) + if(_mqttEnabled) { - _mqttClientSecure->loop(); - } - else - { - _mqttClient->loop(); + if (_useEncryption) + { + _mqttClientSecure->loop(); + } else + { + _mqttClient->loop(); + } } } @@ -310,3 +312,16 @@ uint16_t EthLan8720Device::mqttSubscribe(const char *topic, uint8_t qos) return _mqttClient->subscribe(topic, qos); } } + +void EthLan8720Device::disableMqtt() +{ + if (_useEncryption) + { + _mqttClientSecure->disconnect(); + } else + { + _mqttClient->disconnect(); + } + + _mqttEnabled = false; +} diff --git a/networkDevices/EthLan8720Device.h b/networkDevices/EthLan8720Device.h index c601a1d..7d39b48 100644 --- a/networkDevices/EthLan8720Device.h +++ b/networkDevices/EthLan8720Device.h @@ -62,6 +62,8 @@ public: uint16_t mqttSubscribe(const char *topic, uint8_t qos) override; + void disableMqtt() override; + private: void onDisconnected(); @@ -83,6 +85,7 @@ private: eth_phy_type_t _type; eth_clock_mode_t _clock_mode; bool _use_mac_from_efuse; + bool _mqttEnabled = true; char _ca[TLS_CA_MAX_SIZE] = {0}; char _cert[TLS_CERT_MAX_SIZE] = {0}; diff --git a/networkDevices/NetworkDevice.h b/networkDevices/NetworkDevice.h index 8fc800d..907e18e 100644 --- a/networkDevices/NetworkDevice.h +++ b/networkDevices/NetworkDevice.h @@ -42,6 +42,7 @@ public: virtual void mqttOnMessage(espMqttClientTypes::OnMessageCallback callback) = 0; virtual void mqttOnConnect(espMqttClientTypes::OnConnectCallback callback) = 0; virtual void mqttOnDisconnect(espMqttClientTypes::OnDisconnectCallback callback) = 0; + virtual void disableMqtt() = 0; virtual uint16_t mqttSubscribe(const char* topic, uint8_t qos) = 0; diff --git a/networkDevices/W5500Device.cpp b/networkDevices/W5500Device.cpp index 08eec47..06c0f62 100644 --- a/networkDevices/W5500Device.cpp +++ b/networkDevices/W5500Device.cpp @@ -207,7 +207,10 @@ void W5500Device::initializeMacAddress(byte *mac) void W5500Device::update() { _maintainResult = Ethernet.maintain(); - _mqttClient.loop(); + if(_mqttEnabled) + { + _mqttClient.loop(); + } } int8_t W5500Device::signalStrength() @@ -279,3 +282,9 @@ uint16_t W5500Device::mqttPublish(const char *topic, uint8_t qos, bool retain, c { return _mqttClient.publish(topic, qos, retain, payload, length); } + +void W5500Device::disableMqtt() +{ + _mqttClient.disconnect(); + _mqttEnabled = false; +} diff --git a/networkDevices/W5500Device.h b/networkDevices/W5500Device.h index 12a964d..14290d0 100644 --- a/networkDevices/W5500Device.h +++ b/networkDevices/W5500Device.h @@ -59,6 +59,8 @@ public: uint16_t mqttSubscribe(const char *topic, uint8_t qos) override; + void disableMqtt() override; + private: void resetDevice(); void initializeMacAddress(byte* mac); @@ -72,6 +74,7 @@ private: char* _path; W5500Variant _variant; bool _lastConnected = false; + bool _mqttEnabled = true; byte _mac[6]; }; \ No newline at end of file diff --git a/networkDevices/WifiDevice.cpp b/networkDevices/WifiDevice.cpp index 610b8a2..ce906d0 100644 --- a/networkDevices/WifiDevice.cpp +++ b/networkDevices/WifiDevice.cpp @@ -142,13 +142,15 @@ ReconnectStatus WifiDevice::reconnect() void WifiDevice::update() { - if(_useEncryption) + if(_mqttEnabled) { - _mqttClientSecure->loop(); - } - else - { - _mqttClient->loop(); + if (_useEncryption) + { + _mqttClientSecure->loop(); + } else + { + _mqttClient->loop(); + } } } @@ -327,3 +329,16 @@ uint16_t WifiDevice::mqttSubscribe(const char *topic, uint8_t qos) return _mqttClient->subscribe(topic, qos); } } + +void WifiDevice::disableMqtt() +{ + if (_useEncryption) + { + _mqttClientSecure->disconnect(); + } else + { + _mqttClient->disconnect(); + } + + _mqttEnabled = false; +} diff --git a/networkDevices/WifiDevice.h b/networkDevices/WifiDevice.h index 8d972cb..e787703 100644 --- a/networkDevices/WifiDevice.h +++ b/networkDevices/WifiDevice.h @@ -52,6 +52,8 @@ public: uint16_t mqttSubscribe(const char *topic, uint8_t qos) override; + void disableMqtt() override; + private: static void clearRtcInitVar(WiFiManager*); @@ -65,6 +67,7 @@ private: bool _startAp = false; char* _path; bool _useEncryption = false; + bool _mqttEnabled = true; char _ca[TLS_CA_MAX_SIZE] = {0}; char _cert[TLS_CERT_MAX_SIZE] = {0}; diff --git a/webflash/nuki_hub.bin b/webflash/nuki_hub.bin index 642ba38..d6ca379 100644 Binary files a/webflash/nuki_hub.bin and b/webflash/nuki_hub.bin differ