diff --git a/CMakeLists.txt b/CMakeLists.txt index a824e99..fc1d2e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,12 +17,13 @@ set(LOG_LEVEL ARDUHAL_LOG_LEVEL_NONE) #add_compile_definitions(DEBUG_NUKI_READABLE_DATA) # Length of char arrays to store certificates for MQTTS -add_compile_definitions(TLS_CA_MAX_SIZE=1500) +add_compile_definitions(TLS_CA_MAX_SIZE=2200) add_compile_definitions(TLS_CERT_MAX_SIZE=1500) add_compile_definitions(TLS_KEY_MAX_SIZE=1800) add_compile_definitions(TX_PAYLOAD_BUFFER_SIZE=6144) add_compile_definitions(ESP_PLATFORM) add_compile_definitions(ESP32) +add_compile_definitions(ARDUINO_ARCH_ESP32) include_directories(${PROJECT_NAME} PRIVATE @@ -31,10 +32,11 @@ include_directories(${PROJECT_NAME} lib/BleScanner/src lib/nuki_ble/src lib/WiFiManager - lib/ArduinoMqttClient/src lib/WebServer/src lib/Ethernet/src lib/MqttLogger/src + lib/espMqttClient/src + lib/AsyncTCP/src ) file(GLOB SRCFILES @@ -47,6 +49,8 @@ file(GLOB SRCFILES networkDevices/NetworkDevice.h networkDevices/WifiDevice.cpp networkDevices/W5500Device.cpp + networkDevices/ClientSyncEthernet.cpp + networkDevices/espMqttClientEthernet.cpp NukiWrapper.cpp NukiOpenerWrapper.cpp MqttTopics.h @@ -75,9 +79,8 @@ file(GLOB SRCFILES lib/nuki_ble/src/NukiOpenerUtils.cpp lib/BleScanner/src/BleInterfaces.h lib/BleScanner/src/BleScanner.cpp - lib/ArduinoMqttClient/src/MqttClient.cpp - lib/ArduinoMqttClient/src/ArduinoMqttClient.h lib/MqttLogger/src/MqttLogger.cpp + lib/AsyncTCP/src/AsyncTCP.cpp ) file(GLOB_RECURSE SRCFILESREC @@ -88,6 +91,12 @@ file(GLOB_RECURSE SRCFILESREC lib/WebServer/src/*.h lib/Ethernet/src/*.cpp lib/Ethernet/src/*.h + lib/espMqttClient/src/*.cpp + lib/espMqttClient/src/*.h + lib/espMqttClient/src/Packets/*.cpp + lib/espMqttClient/src/Packets/*.h + lib/espMqttClient/src/Transport/*.cpp + lib/espMqttClient/src/Transport/*.h ) add_executable(${PROJECT_NAME} diff --git a/Config.h b/Config.h index c37ec86..ea8781c 100644 --- a/Config.h +++ b/Config.h @@ -1,6 +1,6 @@ #pragma once -#define NUKI_HUB_VERSION "7.3" +#define NUKI_HUB_VERSION "7.3-esp-mqtt-7" #define MQTT_QOS_LEVEL 1 #define MQTT_CLEAN_SESSIONS false \ No newline at end of file diff --git a/Network.cpp b/Network.cpp index 01a044d..703a380 100644 --- a/Network.cpp +++ b/Network.cpp @@ -81,7 +81,9 @@ void Network::setupDevice() void Network::initialize() { _restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect); - _rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval); + _rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000; + + _hostname = _preferences->getString(preference_hostname); if(_hostname == "") { @@ -93,6 +95,7 @@ void Network::initialize() _rssiPublishInterval = -1; _preferences->putInt(preference_rssi_publish_interval, _rssiPublishInterval); } + strcpy(_hostnameArr, _hostname.c_str()); _device->initialize(); Log->print(F("Host name: ")); @@ -133,8 +136,8 @@ void Network::initialize() Log->print(F(":")); Log->println(port); - _device->mqttClient()->setId(_preferences->getString(preference_hostname)); - _device->mqttClient()->setCleanSession(MQTT_CLEAN_SESSIONS); + _device->mqttSetClientId(_hostnameArr); + _device->mqttSetCleanSession(MQTT_CLEAN_SESSIONS); _networkTimeout = _preferences->getInt(preference_network_timeout); if(_networkTimeout == 0) @@ -179,7 +182,7 @@ bool Network::update() } - if(!_device->mqttClient()->connected()) + if(!_device->mqttConnected()) { if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000) && ts > 60000) { @@ -227,7 +230,6 @@ bool Network::update() _lastMaintenanceTs = ts; } - _device->mqttClient()->poll(); return true; } @@ -236,56 +238,68 @@ bool Network::reconnect() _mqttConnectionState = 0; int port = _preferences->getInt(preference_mqtt_broker_port); - while (!_device->mqttClient()->connected() && millis() > _nextReconnect) + while (!_device->mqttConnected() && millis() > _nextReconnect) { + if(strcmp(_mqttBrokerAddr, "") == 0) + { + Log->println(F("MQTT Broker not configured, aborting connection attempt.")); + _nextReconnect = millis() + 5000; + return false; + } + Log->println(F("Attempting MQTT connection")); - bool success = false; if(strlen(_mqttUser) == 0) { Log->println(F("MQTT: Connecting without credentials")); - success = _device->mqttClient()->connect(_mqttBrokerAddr, port); + _device->mqttSetServer(_mqttBrokerAddr, port); + _device->mqttConnect(); } else { Log->print(F("MQTT: Connecting with user: ")); Log->println(_mqttUser); - _device->mqttClient()->setUsernamePassword(_mqttUser, _mqttPass); - success = _device->mqttClient()->connect(_mqttBrokerAddr, port); + _device->mqttSetCredentials(_mqttUser, _mqttPass); + _device->mqttSetServer(_mqttBrokerAddr, port); + _device->mqttConnect(); } - if (success) + bool connected = _device->mqttConnected(); + unsigned long timeout = millis() + 3000; + + while(!connected && millis() < timeout) + { + connected = _device->mqttConnected(); + delay(200); + } + + if (connected) { Log->println(F("MQTT connected")); _mqttConnectionState = 1; delay(100); - _device->mqttClient()->onMessage(Network::onMqttDataReceivedCallback); + + // TODO + _device->mqttOnMessage(Network::onMqttDataReceivedCallback); for(const String& topic : _subscribedTopics) { - _device->mqttClient()->subscribe(topic.c_str(), MQTT_QOS_LEVEL); + _device->mqttSubscribe(topic.c_str(), MQTT_QOS_LEVEL); } if(_firstConnect) { _firstConnect = false; for(const auto& it : _initTopics) { - _device->mqttClient()->beginMessage(it.first, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(it.second); - _device->mqttClient()->endMessage(); + _device->mqttPublish(it.first.c_str(), MQTT_QOS_LEVEL, true, it.second.c_str()); } } - for(int i=0; i<10; i++) - { - _device->mqttClient()->poll(); - delay(100); - } + delay(1000); _mqttConnectionState = 2; } else { Log->print(F("MQTT connect failed, rc=")); - Log->println(_device->mqttClient()->connectError()); +// Log->println(_device->mqttClient()->connectError()); _device->printError(); - _device->mqttClient()->stop(); _mqttConnectionState = 0; _nextReconnect = millis() + 5000; } @@ -336,37 +350,27 @@ void Network::registerMqttReceiver(MqttReceiver* receiver) _mqttReceivers.push_back(receiver); } -void Network::onMqttDataReceivedCallback(int messageSize) +void Network::onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) { - _inst->onMqttDataReceived(messageSize); -} + uint8_t value[50] = {0}; + size_t l = min(len, sizeof(value)-1); -void Network::onMqttDataReceived(int) -{ - MqttClient* mqttClient = _device->mqttClient(); - String topic = mqttClient->messageTopic(); - - byte payload[500]; - memset(payload, 0, sizeof(payload)); - - int index = 0; - while (mqttClient->available() && index < sizeof(payload)) + for(int i=0; iread(); - ++index; + value[i] = payload[i]; } + _inst->onMqttDataReceived(properties, topic, value, len, index, total); +} + +void Network::onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) +{ for(auto receiver : _mqttReceivers) { - receiver->onMqttDataReceived(topic.c_str(), payload, index); + receiver->onMqttDataReceived(topic, (byte*)payload, index); } } -MqttClient *Network::mqttClient() -{ - return _device->mqttClient(); -} - void Network::reconfigureDevice() { _device->reconfigure(); @@ -389,6 +393,10 @@ int Network::mqttConnectionState() return _mqttConnectionState; } +bool Network::encryptionSupported() +{ + return _device->supportsEncryption(); +} void Network::publishFloat(const char* prefix, const char* topic, const float value, const uint8_t precision) { @@ -396,9 +404,7 @@ void Network::publishFloat(const char* prefix, const char* topic, const float va dtostrf(value, 0, precision, str); char path[200] = {0}; buildMqttPath(prefix, topic, path); - _device->mqttClient()->beginMessage(path, true); - _device->mqttClient()->print(str); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path, MQTT_QOS_LEVEL, true, str); } void Network::publishInt(const char* prefix, const char *topic, const int value) @@ -407,9 +413,7 @@ void Network::publishInt(const char* prefix, const char *topic, const int value) itoa(value, str, 10); char path[200] = {0}; buildMqttPath(prefix, topic, path); - _device->mqttClient()->beginMessage(path, true); - _device->mqttClient()->print(str); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path, MQTT_QOS_LEVEL, true, str); } void Network::publishUInt(const char* prefix, const char *topic, const unsigned int value) @@ -418,9 +422,7 @@ void Network::publishUInt(const char* prefix, const char *topic, const unsigned utoa(value, str, 10); char path[200] = {0}; buildMqttPath(prefix, topic, path); - _device->mqttClient()->beginMessage(path, true); - _device->mqttClient()->print(str); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path, MQTT_QOS_LEVEL, true, str); } void Network::publishULong(const char* prefix, const char *topic, const unsigned long value) @@ -429,9 +431,7 @@ void Network::publishULong(const char* prefix, const char *topic, const unsigned utoa(value, str, 10); char path[200] = {0}; buildMqttPath(prefix, topic, path); - _device->mqttClient()->beginMessage(path, true); - _device->mqttClient()->print(str); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path, MQTT_QOS_LEVEL, true, str); } void Network::publishBool(const char* prefix, const char *topic, const bool value) @@ -440,19 +440,14 @@ void Network::publishBool(const char* prefix, const char *topic, const bool valu str[0] = value ? '1' : '0'; char path[200] = {0}; buildMqttPath(prefix, topic, path); - _device->mqttClient()->beginMessage(path, true); - _device->mqttClient()->print(str); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path, MQTT_QOS_LEVEL, true, str); } bool Network::publishString(const char* prefix, const char *topic, const char *value) { char path[200] = {0}; buildMqttPath(prefix, topic, path); - _device->mqttClient()->beginMessage(path, true); - _device->mqttClient()->print(value); - bool success = _device->mqttClient()->endMessage() > 0; - return success; + return _device->mqttPublish(path, MQTT_QOS_LEVEL, true, value) > 0; } void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState) @@ -494,9 +489,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n path.concat(uidString); path.concat("/smartlock/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); // Battery critical configJSON = "{\"dev\":{\"ids\":[\"nuki_"; @@ -520,9 +513,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n path.concat(uidString); path.concat("/battery_low/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); // Keypad battery critical configJSON = "{\"dev\":{\"ids\":[\"nuki_"; @@ -546,9 +537,8 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n path.concat(uidString); path.concat("/keypad_battery_low/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); + // Battery voltage configJSON = "{\"dev\":{\"ids\":[\"nuki_"; configJSON.concat(uidString); @@ -573,9 +563,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n path.concat(uidString); path.concat("/battery_voltage/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); // Trigger configJSON = "{\"dev\":{\"ids\":[\"nuki_"; @@ -600,9 +588,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n path.concat(uidString); path.concat("/trigger/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); } } @@ -638,9 +624,7 @@ void Network::publishHASSConfigBatLevel(char *deviceType, const char *baseTopic, path.concat(uidString); path.concat("/battery_level/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); } } @@ -675,9 +659,7 @@ void Network::publishHASSConfigDoorSensor(char *deviceType, const char *baseTopi path.concat(uidString); path.concat("/door_sensor/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); } } @@ -711,9 +693,7 @@ void Network::publishHASSConfigRingDetect(char *deviceType, const char *baseTopi path.concat(uidString); path.concat("/ring/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); } } @@ -751,9 +731,7 @@ void Network::publishHASSWifiRssiConfig(char *deviceType, const char *baseTopic, path.concat(uidString); path.concat("/wifi_signal_strength/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); } } @@ -785,9 +763,7 @@ void Network::publishHASSBleRssiConfig(char *deviceType, const char *baseTopic, path.concat(uidString); path.concat("/bluetooth_signal_strength/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(configJSON); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, configJSON.c_str()); } } @@ -801,73 +777,55 @@ void Network::removeHASSConfig(char* uidString) path.concat("/lock/"); path.concat(uidString); path.concat("/smartlock/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/binary_sensor/"); path.concat(uidString); path.concat("/battery_low/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/sensor/"); path.concat(uidString); path.concat("/battery_voltage/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/sensor/"); path.concat(uidString); path.concat("/trigger/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/sensor/"); path.concat(uidString); path.concat("/battery_level/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/binary_sensor/"); path.concat(uidString); path.concat("/door_sensor/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/binary_sensor/"); path.concat(uidString); path.concat("/ring/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/sensor/"); path.concat(uidString); path.concat("/wifi_signal_strength/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/sensor/"); path.concat(uidString); path.concat("/bluetooth_signal_strength/config"); - _device->mqttClient()->beginMessage(path, true, MQTT_QOS_LEVEL); - _device->mqttClient()->print(""); - _device->mqttClient()->endMessage(); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); } } @@ -880,3 +838,8 @@ const NetworkDeviceType Network::networkDeviceType() { return _networkDeviceType; } + +uint16_t Network::subscribe(const char *topic, uint8_t qos) +{ + return _device->mqttSubscribe(topic, qos); +} diff --git a/Network.h b/Network.h index 23813bc..6375b39 100644 --- a/Network.h +++ b/Network.h @@ -43,14 +43,16 @@ public: void publishPresenceDetection(char* csv); - MqttClient* mqttClient(); int mqttConnectionState(); // 0 = not connected; 1 = connected; 2 = connected and mqtt processed + bool encryptionSupported(); const NetworkDeviceType networkDeviceType(); + uint16_t subscribe(const char* topic, uint8_t qos); + private: - static void onMqttDataReceivedCallback(int); - void onMqttDataReceived(int messageSize); + static void onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total); + void onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total); void setupDevice(); bool reconnect(); @@ -59,6 +61,7 @@ private: static Network* _inst; Preferences* _preferences; String _hostname; + char _hostnameArr[101] = {0}; NetworkDevice* _device = nullptr; int _mqttConnectionState = 0; diff --git a/NetworkLock.cpp b/NetworkLock.cpp index d9a4109..6466a19 100644 --- a/NetworkLock.cpp +++ b/NetworkLock.cpp @@ -73,13 +73,7 @@ void NetworkLock::initialize() void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) { - char value[50] = {0}; - size_t l = min(length, sizeof(value)-1); - - for(int i=0; imqttConnectionState() >= 2; diff --git a/NetworkOpener.cpp b/NetworkOpener.cpp index 534fc71..f55b07c 100644 --- a/NetworkOpener.cpp +++ b/NetworkOpener.cpp @@ -1,10 +1,9 @@ #include "NetworkOpener.h" -#include // https://github.com/tzapu/WiFiManager #include "Arduino.h" #include "MqttTopics.h" #include "PreferencesKeys.h" -#include "Pins.h" #include "Logger.h" +#include "Config.h" NetworkOpener::NetworkOpener(Network* network, Preferences* preferences) : _preferences(preferences), @@ -59,19 +58,13 @@ void NetworkOpener::update() void NetworkOpener::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) { - char value[50] = {0}; - size_t l = min(length, sizeof(value)-1); - - for(int i=0; imqttConnectionState() >= 2; if(processActions && comparePrefixedPath(topic, mqtt_topic_lock_action)) { - if(strcmp(value, "") == 0 || strcmp(value, "--") == 0 || strcmp(value, "ack") == 0 || strcmp(value, "unknown_action") == 0) return; + if(strcmp((char*)payload, "") == 0 || strcmp(value, "--") == 0 || strcmp(value, "ack") == 0 || strcmp(value, "unknown_action") == 0) return; Log->print(F("Opener lock action received: ")); Log->println(value); @@ -483,12 +476,13 @@ void NetworkOpener::subscribe(const char *path) { char prefixedPath[500]; buildMqttPath(path, prefixedPath); - _network->mqttClient()->subscribe(prefixedPath); + _network->subscribe(prefixedPath, MQTT_QOS_LEVEL); } bool NetworkOpener::comparePrefixedPath(const char *fullPath, const char *subPath) { char prefixedPath[500]; buildMqttPath(subPath, prefixedPath); + return strcmp(fullPath, prefixedPath) == 0; } diff --git a/NukiOpenerWrapper.cpp b/NukiOpenerWrapper.cpp index 75908c4..7ba2685 100644 --- a/NukiOpenerWrapper.cpp +++ b/NukiOpenerWrapper.cpp @@ -45,7 +45,7 @@ void NukiOpenerWrapper::initialize() _hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != ""; _nrOfRetries = _preferences->getInt(preference_command_nr_of_retries); _retryDelay = _preferences->getInt(preference_command_retry_delay); - _rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval); + _rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000; if(_intervalLockstate == 0) { diff --git a/NukiWrapper.cpp b/NukiWrapper.cpp index 727383f..12dec2f 100644 --- a/NukiWrapper.cpp +++ b/NukiWrapper.cpp @@ -50,7 +50,7 @@ void NukiWrapper::initialize(const bool& firstStart) _hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != ""; _nrOfRetries = _preferences->getInt(preference_command_nr_of_retries); _retryDelay = _preferences->getInt(preference_command_retry_delay); - _rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval); + _rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000; if(firstStart) { diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 9912242..d161cb5 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -568,7 +568,7 @@ void WebCfgServer::buildOtaHtml(String &response) response.concat("
Choose the updated nuki_hub.bin file to upload:
"); response.concat("
"); - response.concat("
Initiating Over-the-air update. This will take about a minute, please be patient.
You will be forwarded automatically when the update is complete.
"); + response.concat("
Initiating Over-the-air update. This will take about two minutes, please be patient.
You will be forwarded automatically when the update is complete.
"); response.concat(""); @@ -599,11 +599,11 @@ void WebCfgServer::buildMqttConfigHtml(String &response) response.concat("

Advanced MQTT and Network Configuration

"); response.concat(""); printInputField(response, "HASSDISCOVERY", "Home Assistant discovery topic (empty to disable; usually homeassistant)", _preferences->getString(preference_mqtt_hass_discovery).c_str(), 30); - printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE); - printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE); - printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE); + printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE, _network->encryptionSupported()); + printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE, _network->encryptionSupported()); + printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported()); printDropDown(response, "NWHWDT", "Network hardware detection", String(_preferences->getInt(preference_network_hardware_detect)), getNetworkDetectionOptions()); - printInputField(response, "RSSI", "RSSI Publish interval (milliseconds; -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); printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect)); printInputField(response, "RSTTMR", "Restart timer (minutes; -1 to disable)", _preferences->getInt(preference_restart_timer), 10); @@ -795,7 +795,8 @@ void WebCfgServer::printTextarea(String& response, const char *token, const char *description, const char *value, - const size_t maxLength) + const size_t maxLength, + const bool enabled) { char maxLengthStr[20]; @@ -804,7 +805,12 @@ void WebCfgServer::printTextarea(String& response, response.concat("
"); response.concat(description); response.concat(""); - response.concat("