From ec91b25703ef4054d9bbe14d17898c3d70c8bc0d Mon Sep 17 00:00:00 2001 From: iranl Date: Fri, 29 Mar 2024 10:51:56 +0100 Subject: [PATCH] Separate config --- CMakeLists.txt | 1 + ConfigUpdateResult.h | 9 + MqttTopics.h | 3 + NetworkLock.cpp | 117 +++++++-- NetworkLock.h | 8 +- NetworkOpener.cpp | 106 ++++++-- NetworkOpener.h | 10 +- NukiOpenerWrapper.cpp | 78 +++--- NukiOpenerWrapper.h | 3 +- NukiWrapper.cpp | 91 ++++--- NukiWrapper.h | 5 +- PreferencesKeys.h | 10 +- WebCfgServer.cpp | 557 +++++++++++++++++++++++++++++++++++++++++- main.cpp | 52 +++- 14 files changed, 910 insertions(+), 140 deletions(-) create mode 100644 ConfigUpdateResult.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ae3a59..f0e919b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ set(SRCFILES networkDevices/ClientSyncW5500.cpp networkDevices/espMqttClientW5500.cpp networkDevices/IPConfiguration.cpp + ConfigUpdateResult.h LockActionResult.h QueryCommand.h NukiWrapper.cpp diff --git a/ConfigUpdateResult.h b/ConfigUpdateResult.h new file mode 100644 index 0000000..3b07596 --- /dev/null +++ b/ConfigUpdateResult.h @@ -0,0 +1,9 @@ +#pragma once + +enum class ConfigUpdateResult +{ + Success, + UnknownAction, + AccessDenied, + Failed +}; \ No newline at end of file diff --git a/MqttTopics.h b/MqttTopics.h index 903042a..a91a762 100644 --- a/MqttTopics.h +++ b/MqttTopics.h @@ -20,6 +20,9 @@ #define mqtt_topic_lock_address "/lock/address" #define mqtt_topic_lock_retry "/lock/retry" +#define mqtt_topic_config_action "/configuration/action" +#define mqtt_topic_config_basic_json "/configuration/basicJson" +#define mqtt_topic_config_advanced_json "/configuration/advancedJson" #define mqtt_topic_config_button_enabled "/configuration/buttonEnabled" #define mqtt_topic_config_led_enabled "/configuration/ledEnabled" #define mqtt_topic_config_led_brightness "/configuration/ledBrightness" diff --git a/NetworkLock.cpp b/NetworkLock.cpp index f6faf69..6bdf10d 100644 --- a/NetworkLock.cpp +++ b/NetworkLock.cpp @@ -13,14 +13,6 @@ NetworkLock::NetworkLock(Network* network, Preferences* preferences, char* buffe _buffer(buffer), _bufferSize(bufferSize) { - _configTopics.reserve(5); - _configTopics.push_back(mqtt_topic_config_button_enabled); - _configTopics.push_back(mqtt_topic_config_led_enabled); - _configTopics.push_back(mqtt_topic_config_led_brightness); - _configTopics.push_back(mqtt_topic_config_auto_unlock); - _configTopics.push_back(mqtt_topic_config_auto_lock); - _configTopics.push_back(mqtt_topic_config_single_lock); - _network->registerMqttReceiver(this); } @@ -51,10 +43,9 @@ void NetworkLock::initialize() _network->initTopic(_mqttPath, mqtt_topic_lock_action, "--"); _network->subscribe(_mqttPath, mqtt_topic_lock_action); - for(const auto& topic : _configTopics) - { - _network->subscribe(_mqttPath, topic); - } + + _network->initTopic(_mqttPath, mqtt_topic_config_action, "--"); + _network->subscribe(_mqttPath, mqtt_topic_config_action); _network->subscribe(_mqttPath, mqtt_topic_reset); _network->initTopic(_mqttPath, mqtt_topic_reset, "0"); @@ -194,14 +185,37 @@ void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const uns publishString(mqtt_topic_query_battery, "0"); } - for(auto configTopic : _configTopics) + if(comparePrefixedPath(topic, mqtt_topic_config_action)) { - if(comparePrefixedPath(topic, configTopic)) + if(strcmp(value, "") == 0 || + strcmp(value, "--") == 0 || + strcmp(value, "ack") == 0 || + strcmp(value, "unknown_action") == 0 || + strcmp(value, "denied") == 0 || + strcmp(value, "error") == 0) return; + + Log->print(F("Config action received: ")); + Log->println(value); + ConfigUpdateResult configUpdateResult = ConfigUpdateResult::Failed; + if(_configUpdateReceivedCallback != NULL) { - if(_configUpdateReceivedCallback != nullptr) - { - _configUpdateReceivedCallback(configTopic, value); - } + configUpdateResult = _configUpdateReceivedCallback(value); + } + + switch(configUpdateResult) + { + case ConfigUpdateResult::Success: + publishString(mqtt_topic_config_action, "ack"); + break; + case ConfigUpdateResult::UnknownAction: + publishString(mqtt_topic_config_action, "unknown_action"); + break; + case ConfigUpdateResult::AccessDenied: + publishString(mqtt_topic_config_action, "denied"); + break; + case ConfigUpdateResult::Failed: + publishString(mqtt_topic_config_action, "error"); + break; } } } @@ -461,6 +475,38 @@ void NetworkLock::publishBatteryReport(const NukiLock::BatteryReport& batteryRep void NetworkLock::publishConfig(const NukiLock::Config &config) { + DynamicJsonDocument json(_bufferSize); + + char uidString[20]; + itoa(config.nukiId, uidString, 16); + json["nukiID"] = uidString; + json["name"] = config.name; + json["latitude"] = config.latitide; + json["autoUnlatch"] = config.autoUnlatch; + json["longitude"] = config.longitude; + json["pairingEnabled"] = config.pairingEnabled; + json["buttonEnabled"] = config.buttonEnabled; + json["ledEnabled"] = config.ledEnabled; + json["ledBrightness"] = config.ledBrightness; + json["currentTime"] = std::to_string(config.currentTimeYear) + "-" + std::to_string(config.currentTimeMonth) + "-" + std::to_string(config.currentTimeDay) + " " + std::to_string(config.currentTimeHour) + ":" + std::to_string(config.currentTimeMinute) + ":" + std::to_string(config.currentTimeSecond); + json["timeZoneOffset"] = config.timeZoneOffset; + json["dstMode"] = config.dstMode; + json["hasFob"] = config.hasFob; + json["fobAction1"] = config.fobAction1; + json["fobAction2"] = config.fobAction2; + json["fobAction3"] = config.fobAction3; + json["singleLock"] = config.singleLock; + json["advertisingMode"] = (int)config.advertisingMode; + json["hasKeypad"] = config.hasKeypad; + json["hasKeypadV2"] = config.hasKeypadV2; + json["firmwareVersion"] = std::to_string(config.firmwareVersion[0]) + "." + std::to_string(config.firmwareVersion[1]) + "." + std::to_string(config.firmwareVersion[2]); + json["hardwareRevision"] = std::to_string(config.hardwareRevision[0]) + "." + std::to_string(config.hardwareRevision[1]); + json["homeKitStatus"] = config.homeKitStatus; + json["timeZoneId"] = (int)config.timeZoneId; + + serializeJson(json, _buffer, _bufferSize); + publishString(mqtt_topic_config_basic_json, _buffer); + publishBool(mqtt_topic_config_button_enabled, config.buttonEnabled == 1); publishBool(mqtt_topic_config_led_enabled, config.ledEnabled == 1); publishInt(mqtt_topic_config_led_brightness, config.ledBrightness); @@ -471,6 +517,35 @@ void NetworkLock::publishConfig(const NukiLock::Config &config) void NetworkLock::publishAdvancedConfig(const NukiLock::AdvancedConfig &config) { + DynamicJsonDocument json(_bufferSize); + + json["totalDegrees"] = config.totalDegrees; + json["unlockedPositionOffsetDegrees"] = config.unlockedPositionOffsetDegrees; + json["lockedPositionOffsetDegrees"] = config.lockedPositionOffsetDegrees; + json["singleLockedPositionOffsetDegrees"] = config.singleLockedPositionOffsetDegrees; + json["unlockedToLockedTransitionOffsetDegrees"] = config.unlockedToLockedTransitionOffsetDegrees; + json["lockNgoTimeout"] = config.lockNgoTimeout; + json["singleButtonPressAction"] = (int)config.singleButtonPressAction; + json["doubleButtonPressAction"] = (int)config.doubleButtonPressAction; + json["detachedCylinder"] = config.detachedCylinder; + json["batteryType"] = (int)config.batteryType; + json["automaticBatteryTypeDetection"] = config.automaticBatteryTypeDetection; + json["unlatchDuration"] = config.unlatchDuration; + json["autoLockTimeOut"] = config.autoLockTimeOut; + json["autoUnLockDisabled"] = config.autoUnLockDisabled; + json["nightModeEnabled"] = config.nightModeEnabled; + json["nightModeStartTime"] = std::to_string(config.nightModeStartTime[0]) + ":" + std::to_string(config.nightModeStartTime[1]); + json["nightModeEndTime"] = std::to_string(config.nightModeEndTime[0]) + ":" + std::to_string(config.nightModeEndTime[1]); + json["nightModeAutoLockEnabled"] = config.nightModeAutoLockEnabled; + json["nightModeAutoUnlockDisabled"] = config.nightModeAutoUnlockDisabled; + json["nightModeImmediateLockOnStart"] = config.nightModeImmediateLockOnStart; + json["autoLockEnabled"] = config.autoLockEnabled; + json["immediateAutoLockEnabled"] = config.immediateAutoLockEnabled; + json["autoUpdateEnabled"] = config.autoUpdateEnabled; + + serializeJson(json, _buffer, _bufferSize); + publishString(mqtt_topic_config_advanced_json, _buffer); + publishBool(mqtt_topic_config_auto_unlock, config.autoUnLockDisabled == 0); publishBool(mqtt_topic_config_auto_lock, config.autoLockEnabled == 1); } @@ -502,7 +577,7 @@ void NetworkLock::publishKeypad(const std::list& entries, basePath.concat("/code_"); basePath.concat(std::to_string(index).c_str()); publishKeypadEntry(basePath, entry); - + auto jsonEntry = json.add(); jsonEntry["id"] = entry.codeId; @@ -515,7 +590,7 @@ void NetworkLock::publishKeypad(const std::list& entries, jsonEntry["createdMin"] = entry.dateCreatedMin; jsonEntry["createdSec"] = entry.dateCreatedSec; jsonEntry["lockCount"] = entry.lockCount; - + ++index; } @@ -545,7 +620,7 @@ void NetworkLock::setLockActionReceivedCallback(LockActionResult (*lockActionRec _lockActionReceivedCallback = lockActionReceivedCallback; } -void NetworkLock::setConfigUpdateReceivedCallback(void (*configUpdateReceivedCallback)(const char *, const char *)) +void NetworkLock::setConfigUpdateReceivedCallback(ConfigUpdateResult (*configUpdateReceivedCallback)(const char *)) { _configUpdateReceivedCallback = configUpdateReceivedCallback; } diff --git a/NetworkLock.h b/NetworkLock.h index 977aaba..c411a99 100644 --- a/NetworkLock.h +++ b/NetworkLock.h @@ -11,6 +11,7 @@ #include "Network.h" #include "QueryCommand.h" #include "LockActionResult.h" +#include "ConfigUpdateResult.h" #define LOCK_LOG_JSON_BUFFER_SIZE 2048 @@ -40,7 +41,7 @@ public: void publishKeypadCommandResult(const char* result); void setLockActionReceivedCallback(LockActionResult (*lockActionReceivedCallback)(const char* value)); - void setConfigUpdateReceivedCallback(void (*configUpdateReceivedCallback)(const char* path, const char* value)); + void setConfigUpdateReceivedCallback(ConfigUpdateResult (*configUpdateReceivedCallback)(const char* value)); void setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled)); void onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) override; @@ -68,7 +69,6 @@ private: Network* _network; Preferences* _preferences; - std::vector _configTopics; char _mqttPath[181] = {0}; bool _firstTunerStatePublish = true; @@ -80,7 +80,7 @@ private: String _keypadCommandCode = ""; uint _keypadCommandId = 0; int _keypadCommandEnabled = 1; - uint8_t _queryCommands = 0; + uint8_t _queryCommands = 0; uint32_t authId = 0; char authName[33]; @@ -88,6 +88,6 @@ private: size_t _bufferSize; LockActionResult (*_lockActionReceivedCallback)(const char* value) = nullptr; - void (*_configUpdateReceivedCallback)(const char* path, const char* value) = nullptr; + ConfigUpdateResult (*_configUpdateReceivedCallback)(const char* value) = nullptr; void (*_keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled) = nullptr; }; diff --git a/NetworkOpener.cpp b/NetworkOpener.cpp index 04817be..a714599 100644 --- a/NetworkOpener.cpp +++ b/NetworkOpener.cpp @@ -12,11 +12,6 @@ NetworkOpener::NetworkOpener(Network* network, Preferences* preferences, char* b _buffer(buffer), _bufferSize(bufferSize) { - _configTopics.reserve(5); - _configTopics.push_back(mqtt_topic_config_button_enabled); - _configTopics.push_back(mqtt_topic_config_led_enabled); - _configTopics.push_back(mqtt_topic_config_sound_level); - _network->registerMqttReceiver(this); } @@ -41,10 +36,9 @@ void NetworkOpener::initialize() _network->initTopic(_mqttPath, mqtt_topic_lock_action, "--"); _network->subscribe(_mqttPath, mqtt_topic_lock_action); - for(const auto& topic : _configTopics) - { - _network->subscribe(_mqttPath, topic); - } + + _network->initTopic(_mqttPath, mqtt_topic_config_action, "--"); + _network->subscribe(_mqttPath, mqtt_topic_config_action); _network->initTopic(_mqttPath, mqtt_topic_query_config, "0"); _network->initTopic(_mqttPath, mqtt_topic_query_lockstate, "0"); @@ -183,14 +177,37 @@ void NetworkOpener::onMqttDataReceived(const char* topic, byte* payload, const u publishString(mqtt_topic_query_battery, "0"); } - for(auto configTopic : _configTopics) + if(comparePrefixedPath(topic, mqtt_topic_config_action)) { - if(comparePrefixedPath(topic, configTopic)) + if(strcmp(value, "") == 0 || + strcmp(value, "--") == 0 || + strcmp(value, "ack") == 0 || + strcmp(value, "unknown_action") == 0 || + strcmp(value, "denied") == 0 || + strcmp(value, "error") == 0) return; + + Log->print(F("Config action received: ")); + Log->println(value); + ConfigUpdateResult configUpdateResult = ConfigUpdateResult::Failed; + if(_configUpdateReceivedCallback != NULL) { - if(_configUpdateReceivedCallback != nullptr) - { - _configUpdateReceivedCallback(configTopic, value); - } + configUpdateResult = _configUpdateReceivedCallback(value); + } + + switch(configUpdateResult) + { + case ConfigUpdateResult::Success: + publishString(mqtt_topic_config_action, "ack"); + break; + case ConfigUpdateResult::UnknownAction: + publishString(mqtt_topic_config_action, "unknown_action"); + break; + case ConfigUpdateResult::AccessDenied: + publishString(mqtt_topic_config_action, "denied"); + break; + case ConfigUpdateResult::Failed: + publishString(mqtt_topic_config_action, "error"); + break; } } } @@ -282,7 +299,7 @@ void NetworkOpener::publishRing(const bool locked) { publishString(mqtt_topic_lock_ring, "ring"); } - + publishString(mqtt_topic_lock_binary_ring, "ring"); _resetRingStateTs = millis() + 2000; } @@ -503,6 +520,35 @@ void NetworkOpener::publishBatteryReport(const NukiOpener::BatteryReport& batter void NetworkOpener::publishConfig(const NukiOpener::Config &config) { + DynamicJsonDocument json(_bufferSize); + + char uidString[20]; + itoa(config.nukiId, uidString, 16); + json["nukiID"] = uidString; + json["name"] = config.name; + json["latitude"] = config.latitide; + json["longitude"] = config.longitude; + json["capabilities"] = config.capabilities; + json["pairingEnabled"] = config.pairingEnabled; + json["buttonEnabled"] = config.buttonEnabled; + json["currentTime"] = std::to_string(config.currentTimeYear) + "-" + std::to_string(config.currentTimeMonth) + "-" + std::to_string(config.currentTimeDay) + " " + std::to_string(config.currentTimeHour) + ":" + std::to_string(config.currentTimeMinute) + ":" + std::to_string(config.currentTimeSecond); + json["timeZoneOffset"] = config.timeZoneOffset; + json["dstMode"] = config.dstMode; + json["hasFob"] = config.hasFob; + json["fobAction1"] = config.fobAction1; + json["fobAction2"] = config.fobAction2; + json["fobAction3"] = config.fobAction3; + json["operatingMode"] = config.operatingMode; + json["advertisingMode"] = (int)config.advertisingMode; + json["hasKeypad"] = config.hasKeypad; + json["hasKeypadV2"] = config.hasKeypadV2; + json["firmwareVersion"] = std::to_string(config.firmwareVersion[0]) + "." + std::to_string(config.firmwareVersion[1]) + "." + std::to_string(config.firmwareVersion[2]); + json["hardwareRevision"] = std::to_string(config.hardwareRevision[0]) + "." + std::to_string(config.hardwareRevision[1]); + json["timeZoneId"] = (int)config.timeZoneId; + + serializeJson(json, _buffer, _bufferSize); + publishString(mqtt_topic_config_basic_json, _buffer); + publishBool(mqtt_topic_config_button_enabled, config.buttonEnabled == 1); publishBool(mqtt_topic_config_led_enabled, config.ledFlashEnabled == 1); publishString(mqtt_topic_info_firmware_version, std::to_string(config.firmwareVersion[0]) + "." + std::to_string(config.firmwareVersion[1]) + "." + std::to_string(config.firmwareVersion[2])); @@ -511,6 +557,32 @@ void NetworkOpener::publishConfig(const NukiOpener::Config &config) void NetworkOpener::publishAdvancedConfig(const NukiOpener::AdvancedConfig &config) { + DynamicJsonDocument json(_bufferSize); + + json["intercomID"] = config.intercomID; + json["busModeSwitch"] = config.busModeSwitch; + json["shortCircuitDaration"] = config.shortCircuitDaration; + json["electricStrikeDelay"] = config.electricStrikeDelay; + json["randomElectricStrikeDelay"] = config.randomElectricStrikeDelay; + json["electricStrikeDuration"] = config.electricStrikeDuration; + json["disableRtoAfterRing"] = config.disableRtoAfterRing; + json["rtoTimeout"] = config.rtoTimeout; + json["doorbellSuppression"] = config.doorbellSuppression; + json["doorbellSuppressionDuration"] = config.doorbellSuppressionDuration; + json["soundRing"] = config.soundRing; + json["soundOpen"] = config.soundOpen; + json["soundRto"] = config.soundRto; + json["soundCm"] = config.soundCm; + json["soundConfirmation"] = config.soundConfirmation; + json["soundLevel"] = config.soundLevel; + json["singleButtonPressAction"] = (int)config.singleButtonPressAction; + json["doubleButtonPressAction"] = (int)config.doubleButtonPressAction; + json["batteryType"] = (int)config.batteryType; + json["automaticBatteryTypeDetection"] = config.automaticBatteryTypeDetection; + + serializeJson(json, _buffer, _bufferSize); + publishString(mqtt_topic_config_advanced_json, _buffer); + publishUInt(mqtt_topic_config_sound_level, config.soundLevel); } @@ -601,7 +673,7 @@ void NetworkOpener::setLockActionReceivedCallback(LockActionResult (*lockActionR _lockActionReceivedCallback = lockActionReceivedCallback; } -void NetworkOpener::setConfigUpdateReceivedCallback(void (*configUpdateReceivedCallback)(const char *, const char *)) +void NetworkOpener::setConfigUpdateReceivedCallback(ConfigUpdateResult (*configUpdateReceivedCallback)(const char *)) { _configUpdateReceivedCallback = configUpdateReceivedCallback; } diff --git a/NetworkOpener.h b/NetworkOpener.h index ec84dc7..3c03886 100644 --- a/NetworkOpener.h +++ b/NetworkOpener.h @@ -37,7 +37,7 @@ public: void publishKeypadCommandResult(const char* result); void setLockActionReceivedCallback(LockActionResult (*lockActionReceivedCallback)(const char* value)); - void setConfigUpdateReceivedCallback(void (*configUpdateReceivedCallback)(const char* path, const char* value)); + void setConfigUpdateReceivedCallback(ConfigUpdateResult (*configUpdateReceivedCallback)(const char* value)); void setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled)); void onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) override; @@ -70,8 +70,6 @@ private: char _mqttPath[181] = {0}; bool _isConnected = false; - std::vector _configTopics; - bool _firstTunerStatePublish = true; bool _haEnabled= false; bool _reconnected = false; @@ -83,14 +81,14 @@ private: unsigned long _resetRingStateTs = 0; uint8_t _queryCommands = 0; uint32_t authId = 0; - char authName[33]; - + char authName[33]; + NukiOpener::LockState _currentLockState = NukiOpener::LockState::Undefined; char* _buffer; const size_t _bufferSize; LockActionResult (*_lockActionReceivedCallback)(const char* value) = nullptr; - void (*_configUpdateReceivedCallback)(const char* path, const char* value) = nullptr; + ConfigUpdateResult (*_configUpdateReceivedCallback)(const char* value) = nullptr; void (*_keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled) = nullptr; }; diff --git a/NukiOpenerWrapper.cpp b/NukiOpenerWrapper.cpp index b1f5aa5..ec2eab9 100644 --- a/NukiOpenerWrapper.cpp +++ b/NukiOpenerWrapper.cpp @@ -547,9 +547,56 @@ LockActionResult NukiOpenerWrapper::onLockActionReceivedCallback(const char *val return LockActionResult::AccessDenied; } -void NukiOpenerWrapper::onConfigUpdateReceivedCallback(const char *topic, const char *value) +ConfigUpdateResult NukiOpenerWrapper::onConfigUpdateReceivedCallback(const char *value) { - nukiOpenerInst->onConfigUpdateReceived(topic, value); + nukiOpenerPreferences = new Preferences(); + nukiOpenerPreferences->begin("nukihub", true); + uint32_t basicOpenerConfigAclPrefs[16]; + nukiOpenerPreferences->getBytes(preference_conf_opener_basic_acl, &basicOpenerConfigAclPrefs, sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[22]; + nukiOpenerPreferences->getBytes(preference_conf_opener_advanced_acl, &advancedOpenerConfigAclPrefs, sizeof(advancedOpenerConfigAclPrefs)); + + /* + if(!nukiOpenerPreferences->getBool(preference_admin_enabled)) + { + nukiOpenerPreferences->end(); + return ConfigUpdateResult::AccessDenied; + } + + if((action == NukiOpener::LockAction::ActivateRTO && (int)aclPrefs[9] == 1) || (action == NukiOpener::LockAction::DeactivateRTO && (int)aclPrefs[10] == 1) || (action == NukiOpener::LockAction::ElectricStrikeActuation && (int)aclPrefs[11] == 1) || (action == NukiOpener::LockAction::ActivateCM && (int)aclPrefs[12] == 1) || (action == NukiOpener::LockAction::DeactivateCM && (int)aclPrefs[13] == 1) || (action == NukiOpener::LockAction::FobAction1 && (int)aclPrefs[14] == 1) || (action == NukiOpener::LockAction::FobAction2 && (int)aclPrefs[15] == 1) || (action == NukiOpener::LockAction::FobAction3 && (int)aclPrefs[16] == 1)) + { + nukiOpenerPreferences->end(); + nukiOpenerInst->_nextLockAction = action; + return ConfigUpdateResult::Success; + } + + if((int)action == 0xff) + { + return ConfigUpdateResult::UnknownAction; + } + + if(strcmp(topic, mqtt_topic_config_button_enabled) == 0) + { + bool newValue = atoi(value) > 0; + if(!_nukiConfigValid || _nukiConfig.buttonEnabled == newValue) return; + _nukiOpener.enableButton(newValue); + _nextConfigUpdateTs = millis() + 300; + } + if(strcmp(topic, mqtt_topic_config_led_enabled) == 0) + { + bool newValue = atoi(value) > 0; + if(!_nukiConfigValid || _nukiConfig.ledFlashEnabled == newValue) return; + _nukiOpener.enableLedFlash(newValue); + _nextConfigUpdateTs = millis() + 300; + } + if(strcmp(topic, mqtt_topic_config_sound_level) == 0) + { + uint8_t newValue = atoi(value); + if(!_nukiAdvancedConfigValid || _nukiAdvancedConfig.soundLevel == newValue) return; + _nukiOpener.setSoundLevel(newValue); + _nextConfigUpdateTs = millis() + 300; + } + */ } void NukiOpenerWrapper::onKeypadCommandReceivedCallback(const char *command, const uint &id, const String &name, const String &code, const int& enabled) @@ -582,33 +629,6 @@ void NukiOpenerWrapper::gpioActionCallback(const GpioAction &action, const int& } } -void NukiOpenerWrapper::onConfigUpdateReceived(const char *topic, const char *value) -{ - if(!_preferences->getBool(preference_admin_enabled)) return; - - if(strcmp(topic, mqtt_topic_config_button_enabled) == 0) - { - bool newValue = atoi(value) > 0; - if(!_nukiConfigValid || _nukiConfig.buttonEnabled == newValue) return; - _nukiOpener.enableButton(newValue); - _nextConfigUpdateTs = millis() + 300; - } - if(strcmp(topic, mqtt_topic_config_led_enabled) == 0) - { - bool newValue = atoi(value) > 0; - if(!_nukiConfigValid || _nukiConfig.ledFlashEnabled == newValue) return; - _nukiOpener.enableLedFlash(newValue); - _nextConfigUpdateTs = millis() + 300; - } - if(strcmp(topic, mqtt_topic_config_sound_level) == 0) - { - uint8_t newValue = atoi(value); - if(!_nukiAdvancedConfigValid || _nukiAdvancedConfig.soundLevel == newValue) return; - _nukiOpener.setSoundLevel(newValue); - _nextConfigUpdateTs = millis() + 300; - } -} - void NukiOpenerWrapper::onKeypadCommandReceived(const char *command, const uint &id, const String &name, const String &code, const int& enabled) { if(!_preferences->getBool(preference_keypad_control_enabled)) diff --git a/NukiOpenerWrapper.h b/NukiOpenerWrapper.h index 657fe2b..ba29a65 100644 --- a/NukiOpenerWrapper.h +++ b/NukiOpenerWrapper.h @@ -47,10 +47,9 @@ public: private: static LockActionResult onLockActionReceivedCallback(const char* value); - static void onConfigUpdateReceivedCallback(const char* topic, const char* value); + static ConfigUpdateResult onConfigUpdateReceivedCallback(const char* value); static void onKeypadCommandReceivedCallback(const char* command, const uint& id, const String& name, const String& code, const int& enabled); static void gpioActionCallback(const GpioAction& action, const int& pin); - void onConfigUpdateReceived(const char* topic, const char* value); void onKeypadCommandReceived(const char* command, const uint& id, const String& name, const String& code, const int& enabled); void updateKeyTurnerState(); diff --git a/NukiWrapper.cpp b/NukiWrapper.cpp index 35a4c3f..e76f2f9 100644 --- a/NukiWrapper.cpp +++ b/NukiWrapper.cpp @@ -67,9 +67,16 @@ void NukiWrapper::initialize(const bool& firstStart) _preferences->putInt(preference_command_nr_of_retries, 3); _preferences->putInt(preference_command_retry_delay, 1000); _preferences->putInt(preference_restart_ble_beacon_lost, 60); - _preferences->putBool(preference_admin_enabled, true); uint32_t aclPrefs[17] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; _preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + uint32_t basicLockConfigAclPrefs[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + _preferences->putBytes(preference_conf_lock_basic_acl, (byte*)(&basicLockConfigAclPrefs), sizeof(basicLockConfigAclPrefs)); + uint32_t basicOpenerConfigAclPrefs[14] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + _preferences->putBytes(preference_conf_opener_basic_acl, (byte*)(&basicOpenerConfigAclPrefs), sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + _preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[20] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + _preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs)); } if(_retryDelay <= 100) @@ -515,41 +522,33 @@ LockActionResult NukiWrapper::onLockActionReceivedCallback(const char *value) return LockActionResult::AccessDenied; } -void NukiWrapper::onConfigUpdateReceivedCallback(const char *topic, const char *value) +ConfigUpdateResult NukiWrapper::onConfigUpdateReceivedCallback(const char *value) { - nukiInst->onConfigUpdateReceived(topic, value); -} - -void NukiWrapper::onKeypadCommandReceivedCallback(const char *command, const uint &id, const String &name, const String &code, const int& enabled) -{ - nukiInst->onKeypadCommandReceived(command, id, name, code, enabled); -} - -void NukiWrapper::gpioActionCallback(const GpioAction &action, const int& pin) -{ - switch(action) + nukiLockPreferences = new Preferences(); + nukiLockPreferences->begin("nukihub", true); + uint32_t basicLockConfigAclPrefs[16]; + nukiLockPreferences->getBytes(preference_conf_lock_basic_acl, &basicLockConfigAclPrefs, sizeof(basicLockConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22]; + nukiLockPreferences->getBytes(preference_conf_lock_advanced_acl, &advancedLockConfigAclPrefs, sizeof(advancedLockConfigAclPrefs)); + + /* + if(!nukiLockPreferences->getBool(preference_admin_enabled)) { - case GpioAction::Lock: - nukiInst->lock(); - break; - case GpioAction::Unlock: - nukiInst->unlock(); - break; - case GpioAction::Unlatch: - nukiInst->unlatch(); - break; - case GpioAction::LockNgo: - nukiInst->lockngo(); - break; - case GpioAction::LockNgoUnlatch: - nukiInst->lockngounlatch(); - break; + nukiLockPreferences->end(); + return ConfigUpdateResult::AccessDenied; } -} -void NukiWrapper::onConfigUpdateReceived(const char *topic, const char *value) -{ - if(!_preferences->getBool(preference_admin_enabled)) return; + if((int)action == 0xff) + { + return LockActionResult::UnknownAction; + } + + if((action == NukiLock::LockAction::Lock && (int)aclPrefs[0] == 1) || (action == NukiLock::LockAction::Unlock && (int)aclPrefs[1] == 1) || (action == NukiLock::LockAction::Unlatch && (int)aclPrefs[2] == 1) || (action == NukiLock::LockAction::LockNgo && (int)aclPrefs[3] == 1) || (action == NukiLock::LockAction::LockNgoUnlatch && (int)aclPrefs[4] == 1) || (action == NukiLock::LockAction::FullLock && (int)aclPrefs[5] == 1) || (action == NukiLock::LockAction::FobAction1 && (int)aclPrefs[6] == 1) || (action == NukiLock::LockAction::FobAction2 && (int)aclPrefs[7] == 1) || (action == NukiLock::LockAction::FobAction3 && (int)aclPrefs[8] == 1)) + { + nukiLockPreferences->end(); + nukiInst->_nextLockAction = action; + return LockActionResult::Success; + } if(strcmp(topic, mqtt_topic_config_button_enabled) == 0) { @@ -593,6 +592,34 @@ void NukiWrapper::onConfigUpdateReceived(const char *topic, const char *value) _nukiLock.enableAutoLock(newValue); _nextConfigUpdateTs = millis() + 300; } + */ +} + +void NukiWrapper::onKeypadCommandReceivedCallback(const char *command, const uint &id, const String &name, const String &code, const int& enabled) +{ + nukiInst->onKeypadCommandReceived(command, id, name, code, enabled); +} + +void NukiWrapper::gpioActionCallback(const GpioAction &action, const int& pin) +{ + switch(action) + { + case GpioAction::Lock: + nukiInst->lock(); + break; + case GpioAction::Unlock: + nukiInst->unlock(); + break; + case GpioAction::Unlatch: + nukiInst->unlatch(); + break; + case GpioAction::LockNgo: + nukiInst->lockngo(); + break; + case GpioAction::LockNgoUnlatch: + nukiInst->lockngounlatch(); + break; + } } void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, const String &name, const String &code, const int& enabled) diff --git a/NukiWrapper.h b/NukiWrapper.h index 2f68988..705ee2f 100644 --- a/NukiWrapper.h +++ b/NukiWrapper.h @@ -7,6 +7,7 @@ #include "NukiLock.h" #include "Gpio.h" #include "LockActionResult.h" +#include "ConfigUpdateResult.h" #include "NukiDeviceId.h" class NukiWrapper : public Nuki::SmartlockEventHandler @@ -45,11 +46,9 @@ public: private: static LockActionResult onLockActionReceivedCallback(const char* value); - static void onConfigUpdateReceivedCallback(const char* topic, const char* value); + static ConfigUpdateResult onConfigUpdateReceivedCallback(const char* value); static void onKeypadCommandReceivedCallback(const char* command, const uint& id, const String& name, const String& code, const int& enabled); static void gpioActionCallback(const GpioAction& action, const int& pin); - - void onConfigUpdateReceived(const char* topic, const char* value); void onKeypadCommandReceived(const char* command, const uint& id, const String& name, const String& code, const int& enabled); void updateKeyTurnerState(); diff --git a/PreferencesKeys.h b/PreferencesKeys.h index 18edb41..4462068 100644 --- a/PreferencesKeys.h +++ b/PreferencesKeys.h @@ -45,11 +45,14 @@ #define preference_query_interval_battery "batInterval" #define preference_query_interval_keypad "kpInterval" #define preference_access_level "accLvl" -#define preference_admin_enabled "aclConfig" #define preference_keypad_info_enabled "kpInfoEnabled" #define preference_keypad_control_enabled "kpCntrlEnabled" #define preference_publish_authdata "pubAuth" #define preference_acl "aclLckOpn" +#define preference_conf_lock_basic_acl "confLckBasAcl" +#define preference_conf_lock_advanced_acl "confLckAdvAcl" +#define preference_conf_opener_basic_acl "confOpnBasAcl" +#define preference_conf_opener_advanced_acl "confOpnAdvAcl" #define preference_register_as_app "regAsApp" // true = register as hub; false = register as app #define preference_command_nr_of_retries "nrRetry" #define preference_command_retry_delay "rtryDelay" @@ -79,7 +82,8 @@ private: 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, + preference_keypad_control_enabled, preference_keypad_info_enabled, preference_acl, + preference_conf_lock_basic_acl, preference_conf_lock_advanced_acl, preference_conf_opener_basic_acl, preference_conf_opener_advanced_acl, preference_access_level, preference_register_as_app, preference_command_nr_of_retries, preference_command_retry_delay, preference_cred_user, preference_cred_password, preference_publish_authdata, preference_publish_debug_info, preference_presence_detection_timeout, @@ -95,7 +99,7 @@ private: std::vector _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_restart_on_disconnect, preference_keypad_control_enabled, preference_keypad_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 }; diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index c7c5389..537f8b3 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -263,6 +263,10 @@ bool WebCfgServer::processArgs(String& message) bool clearMqttCredentials = false; bool clearCredentials = false; uint32_t aclPrefs[17] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + uint32_t basicLockConfigAclPrefs[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + uint32_t basicOpenerConfigAclPrefs[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + uint32_t advancedLockConfigAclPrefs[22] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + uint32_t advancedOpenerConfigAclPrefs[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int count = _server.args(); @@ -465,11 +469,6 @@ bool WebCfgServer::processArgs(String& message) { aclLvlChanged = true; } - else if(key == "ACLCNF") - { - _preferences->putBool(preference_admin_enabled, (value == "1")); - configChanged = true; - } else if(key == "KPPUB") { _preferences->putBool(preference_keypad_info_enabled, (value == "1")); @@ -553,6 +552,294 @@ bool WebCfgServer::processArgs(String& message) { aclPrefs[16] = ((value == "1") ? 1 : 0); } + else if(key == "CONFLCKNAME") + { + basicLockConfigAclPrefs[0] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKLAT") + { + basicLockConfigAclPrefs[1] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKLONG") + { + basicLockConfigAclPrefs[2] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKAUNL") + { + basicLockConfigAclPrefs[3] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKPRENA") + { + basicLockConfigAclPrefs[4] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKBTENA") + { + basicLockConfigAclPrefs[5] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKLEDENA") + { + basicLockConfigAclPrefs[6] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKLEDBR") + { + basicLockConfigAclPrefs[7] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKTZOFF") + { + basicLockConfigAclPrefs[8] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKDSTM") + { + basicLockConfigAclPrefs[9] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKFOB1") + { + basicLockConfigAclPrefs[10] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKFOB2") + { + basicLockConfigAclPrefs[11] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKFOB3") + { + basicLockConfigAclPrefs[12] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKSGLLCK") + { + basicLockConfigAclPrefs[13] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKADVM") + { + basicLockConfigAclPrefs[14] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKTZID") + { + basicLockConfigAclPrefs[15] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKUPOD") + { + advancedLockConfigAclPrefs[0] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKLPOD") + { + advancedLockConfigAclPrefs[1] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKSLPOD") + { + advancedLockConfigAclPrefs[2] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKUTLTOD") + { + advancedLockConfigAclPrefs[3] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKLNGT") + { + advancedLockConfigAclPrefs[4] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKSBPA") + { + advancedLockConfigAclPrefs[5] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKDBPA") + { + advancedLockConfigAclPrefs[6] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKDC") + { + advancedLockConfigAclPrefs[7] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKBATT") + { + advancedLockConfigAclPrefs[8] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKABTD") + { + advancedLockConfigAclPrefs[9] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKUNLD") + { + advancedLockConfigAclPrefs[10] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKALT") + { + advancedLockConfigAclPrefs[11] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKAUNLD") + { + advancedLockConfigAclPrefs[12] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKNMENA") + { + advancedLockConfigAclPrefs[13] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKNMST") + { + advancedLockConfigAclPrefs[14] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKNMET") + { + advancedLockConfigAclPrefs[15] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKNMALENA") + { + advancedLockConfigAclPrefs[16] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKNMAULD") + { + advancedLockConfigAclPrefs[17] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKNMLOS") + { + advancedLockConfigAclPrefs[18] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKALENA") + { + advancedLockConfigAclPrefs[19] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKIALENA") + { + advancedLockConfigAclPrefs[20] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFLCKAUENA") + { + advancedLockConfigAclPrefs[21] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNNAME") + { + basicOpenerConfigAclPrefs[0] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNLAT") + { + basicOpenerConfigAclPrefs[1] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNLONG") + { + basicOpenerConfigAclPrefs[2] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNPRENA") + { + basicOpenerConfigAclPrefs[3] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNBTENA") + { + basicOpenerConfigAclPrefs[4] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNLEDENA") + { + basicOpenerConfigAclPrefs[5] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNTZOFF") + { + basicOpenerConfigAclPrefs[6] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNDSTM") + { + basicOpenerConfigAclPrefs[7] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNFOB1") + { + basicOpenerConfigAclPrefs[8] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNFOB2") + { + basicOpenerConfigAclPrefs[9] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNFOB3") + { + basicOpenerConfigAclPrefs[10] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNOPM") + { + basicOpenerConfigAclPrefs[11] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNADVM") + { + basicOpenerConfigAclPrefs[12] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNTZID") + { + basicOpenerConfigAclPrefs[13] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNICID") + { + advancedOpenerConfigAclPrefs[0] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNBUSMS") + { + advancedOpenerConfigAclPrefs[1] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNSCDUR") + { + advancedOpenerConfigAclPrefs[2] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNESD") + { + advancedOpenerConfigAclPrefs[3] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNRESD") + { + advancedOpenerConfigAclPrefs[4] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNESDUR") + { + advancedOpenerConfigAclPrefs[5] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNDRTOAR") + { + advancedOpenerConfigAclPrefs[6] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNRTOT") + { + advancedOpenerConfigAclPrefs[7] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNDRBSUP") + { + advancedOpenerConfigAclPrefs[8] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNDRBSUPDUR") + { + advancedOpenerConfigAclPrefs[9] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNSRING") + { + advancedOpenerConfigAclPrefs[10] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNSOPN") + { + advancedOpenerConfigAclPrefs[11] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNSRTO") + { + advancedOpenerConfigAclPrefs[12] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNSCM") + { + advancedOpenerConfigAclPrefs[13] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNSCFRM") + { + advancedOpenerConfigAclPrefs[14] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNSLVL") + { + advancedOpenerConfigAclPrefs[15] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNSBPA") + { + advancedOpenerConfigAclPrefs[16] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNDBPA") + { + advancedOpenerConfigAclPrefs[17] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNBATT") + { + advancedOpenerConfigAclPrefs[18] = ((value == "1") ? 1 : 0); + } + else if(key == "CONFOPNABTD") + { + advancedOpenerConfigAclPrefs[19] = ((value == "1") ? 1 : 0); + } else if(key == "REGAPP") { _preferences->putBool(preference_register_as_app, (value == "1")); @@ -639,6 +926,10 @@ bool WebCfgServer::processArgs(String& message) if(aclLvlChanged) { _preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + _preferences->putBytes(preference_conf_lock_basic_acl, (byte*)(&basicLockConfigAclPrefs), sizeof(basicLockConfigAclPrefs)); + _preferences->putBytes(preference_conf_opener_basic_acl, (byte*)(&basicOpenerConfigAclPrefs), sizeof(basicOpenerConfigAclPrefs)); + _preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs)); + _preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs)); configChanged = true; } @@ -728,12 +1019,7 @@ void WebCfgServer::buildHtml(String& response) } printParameter(response, "Firmware", version.c_str(), "/info"); - if(_preferences->getBool(preference_check_updates)) - { - //if(atof(_latestVersion) > atof(NUKI_HUB_VERSION) || (atof(_latestVersion) == atof(NUKI_HUB_VERSION) && _latestVersion != NUKI_HUB_VERSION)) { - printParameter(response, "Latest Firmware", _preferences->getString(preference_latest_version).c_str(), "/ota"); - //} - } + if(_preferences->getBool(preference_check_updates)) printParameter(response, "Latest Firmware", _preferences->getString(preference_latest_version).c_str(), "/ota"); response.concat("
"); response.concat("

MQTT and Network Configuration

"); @@ -938,7 +1224,6 @@ void WebCfgServer::buildAccLvlHtml(String &response) response.concat(""); response.concat("

Nuki General Access Control

"); response.concat(""); - printCheckBox(response, "ACLCNF", "Change Nuki configuration", _preferences->getBool(preference_admin_enabled)); if((_nuki != nullptr && _nuki->hasKeypad()) || (_nukiOpener != nullptr && _nukiOpener->hasKeypad())) { printCheckBox(response, "KPPUB", "Publish keypad codes information", _preferences->getBool(preference_keypad_info_enabled)); @@ -948,6 +1233,11 @@ void WebCfgServer::buildAccLvlHtml(String &response) response.concat("
SettingEnabled

"); if(_nuki != nullptr) { + uint32_t basicLockConfigAclPrefs[16]; + _preferences->getBytes(preference_conf_lock_basic_acl, &basicLockConfigAclPrefs, sizeof(basicLockConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22]; + _preferences->getBytes(preference_conf_lock_advanced_acl, &advancedLockConfigAclPrefs, sizeof(advancedLockConfigAclPrefs)); + response.concat("

Nuki Lock Access Control

"); response.concat(""); @@ -961,9 +1251,58 @@ void WebCfgServer::buildAccLvlHtml(String &response) printCheckBox(response, "ACLLCKFOB2", "Fob Action 2", ((int)aclPrefs[7] == 1)); printCheckBox(response, "ACLLCKFOB3", "Fob Action 3", ((int)aclPrefs[8] == 1)); response.concat("
ActionAllowed

"); + + response.concat("

Nuki Lock Config Control (Requires PIN to be set)

"); + response.concat(""); + + printCheckBox(response, "CONFLCKNAME", "Name", ((int)basicLockConfigAclPrefs[0] == 1)); + printCheckBox(response, "CONFLCKLAT", "Latitude", ((int)basicLockConfigAclPrefs[1] == 1)); + printCheckBox(response, "CONFLCKLONG", "Longitude", ((int)basicLockConfigAclPrefs[2] == 1)); + printCheckBox(response, "CONFLCKAUNL", "Auto unlatch", ((int)basicLockConfigAclPrefs[3] == 1)); + printCheckBox(response, "CONFLCKPRENA", "Pairing enabled", ((int)basicLockConfigAclPrefs[4] == 1)); + printCheckBox(response, "CONFLCKBTENA", "Button enabled", ((int)basicLockConfigAclPrefs[5] == 1)); + printCheckBox(response, "CONFLCKLEDENA", "LED flash enabled", ((int)basicLockConfigAclPrefs[6] == 1)); + printCheckBox(response, "CONFLCKLEDBR", "LED brightness", ((int)basicLockConfigAclPrefs[7] == 1)); + printCheckBox(response, "CONFLCKTZOFF", "Timezone offset", ((int)basicLockConfigAclPrefs[8] == 1)); + printCheckBox(response, "CONFLCKDSTM", "DST mode", ((int)basicLockConfigAclPrefs[9] == 1)); + printCheckBox(response, "CONFLCKFOB1", "Fob Action 1", ((int)basicLockConfigAclPrefs[10] == 1)); + printCheckBox(response, "CONFLCKFOB2", "Fob Action 2", ((int)basicLockConfigAclPrefs[11] == 1)); + printCheckBox(response, "CONFLCKFOB3", "Fob Action 3", ((int)basicLockConfigAclPrefs[12] == 1)); + printCheckBox(response, "CONFLCKSGLLCK", "Single Lock", ((int)basicLockConfigAclPrefs[13] == 1)); + printCheckBox(response, "CONFLCKADVM", "Advertising Mode", ((int)basicLockConfigAclPrefs[14] == 1)); + printCheckBox(response, "CONFLCKTZID", "Timezone ID", ((int)basicLockConfigAclPrefs[15] == 1)); + + printCheckBox(response, "CONFLCKUPOD", "Unlocked Position Offset Degrees", ((int)advancedLockConfigAclPrefs[0] == 1)); + printCheckBox(response, "CONFLCKLPOD", "Locked Position Offset Degrees", ((int)advancedLockConfigAclPrefs[1] == 1)); + printCheckBox(response, "CONFLCKSLPOD", "Single Locked Position Offset Degrees", ((int)advancedLockConfigAclPrefs[2] == 1)); + printCheckBox(response, "CONFLCKUTLTOD", "Unlocked To Locked Transition Offset Degrees", ((int)advancedLockConfigAclPrefs[3] == 1)); + printCheckBox(response, "CONFLCKLNGT", "Lock n Go timeout", ((int)advancedLockConfigAclPrefs[4] == 1)); + printCheckBox(response, "CONFLCKSBPA", "Single button press action", ((int)advancedLockConfigAclPrefs[5] == 1)); + printCheckBox(response, "CONFLCKDBPA", "Double button press action", ((int)advancedLockConfigAclPrefs[6] == 1)); + printCheckBox(response, "CONFLCKDC", "Detached cylinder", ((int)advancedLockConfigAclPrefs[7] == 1)); + printCheckBox(response, "CONFLCKBATT", "Battery type", ((int)advancedLockConfigAclPrefs[8] == 1)); + printCheckBox(response, "CONFLCKABTD", "Automatic battery type detection", ((int)advancedLockConfigAclPrefs[9] == 1)); + printCheckBox(response, "CONFLCKUNLD", "Unlatch duration", ((int)advancedLockConfigAclPrefs[10] == 1)); + printCheckBox(response, "CONFLCKALT", "Auto lock timeout", ((int)advancedLockConfigAclPrefs[11] == 1)); + printCheckBox(response, "CONFLCKAUNLD", "Auto unlock disabled", ((int)advancedLockConfigAclPrefs[12] == 1)); + printCheckBox(response, "CONFLCKNMENA", "Nightmode enabled", ((int)advancedLockConfigAclPrefs[13] == 1)); + printCheckBox(response, "CONFLCKNMST", "Nightmode start time", ((int)advancedLockConfigAclPrefs[14] == 1)); + printCheckBox(response, "CONFLCKNMET", "Nightmode end time", ((int)advancedLockConfigAclPrefs[15] == 1)); + printCheckBox(response, "CONFLCKNMALENA", "Nightmode auto lock enabled", ((int)advancedLockConfigAclPrefs[16] == 1)); + printCheckBox(response, "CONFLCKNMAULD", "Nightmode auto unlock disabled", ((int)advancedLockConfigAclPrefs[17] == 1)); + printCheckBox(response, "CONFLCKNMLOS", "Nightmode immediate lock on start", ((int)advancedLockConfigAclPrefs[18] == 1)); + printCheckBox(response, "CONFLCKALENA", "Auto lock enabled", ((int)advancedLockConfigAclPrefs[19] == 1)); + printCheckBox(response, "CONFLCKIALENA", "Immediate auto lock enabled", ((int)advancedLockConfigAclPrefs[20] == 1)); + printCheckBox(response, "CONFLCKAUENA", "Auto update enabled", ((int)advancedLockConfigAclPrefs[21] == 1)); + response.concat("
ChangeAllowed

"); } if(_nukiOpener != nullptr) { + uint32_t basicOpenerConfigAclPrefs[16]; + _preferences->getBytes(preference_conf_opener_basic_acl, &basicOpenerConfigAclPrefs, sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[22]; + _preferences->getBytes(preference_conf_opener_advanced_acl, &advancedOpenerConfigAclPrefs, sizeof(advancedOpenerConfigAclPrefs)); + response.concat("

Nuki Opener Access Control

"); response.concat(""); @@ -976,6 +1315,46 @@ void WebCfgServer::buildAccLvlHtml(String &response) printCheckBox(response, "ACLOPNFOB2", "Fob Action 2", ((int)aclPrefs[15] == 1)); printCheckBox(response, "ACLOPNFOB3", "Fob Action 3", ((int)aclPrefs[16] == 1)); response.concat("
ActionAllowed

"); + + response.concat("

Nuki Opener Config Control (Requires PIN to be set)

"); + response.concat(""); + + printCheckBox(response, "CONFOPNNAME", "Name", ((int)basicOpenerConfigAclPrefs[0] == 1)); + printCheckBox(response, "CONFOPNLAT", "Latitude", ((int)basicOpenerConfigAclPrefs[1] == 1)); + printCheckBox(response, "CONFOPNLONG", "Longitude", ((int)basicOpenerConfigAclPrefs[2] == 1)); + printCheckBox(response, "CONFOPNPRENA", "Pairing enabled", ((int)basicOpenerConfigAclPrefs[3] == 1)); + printCheckBox(response, "CONFOPNBTENA", "Button enabled", ((int)basicOpenerConfigAclPrefs[4] == 1)); + printCheckBox(response, "CONFOPNLEDENA", "LED flash enabled", ((int)basicOpenerConfigAclPrefs[5] == 1)); + printCheckBox(response, "CONFOPNTZOFF", "Timezone offset", ((int)basicOpenerConfigAclPrefs[6] == 1)); + printCheckBox(response, "CONFOPNDSTM", "DST mode", ((int)basicOpenerConfigAclPrefs[7] == 1)); + printCheckBox(response, "CONFOPNFOB1", "Fob Action 1", ((int)basicOpenerConfigAclPrefs[8] == 1)); + printCheckBox(response, "CONFOPNFOB2", "Fob Action 2", ((int)basicOpenerConfigAclPrefs[9] == 1)); + printCheckBox(response, "CONFOPNFOB3", "Fob Action 3", ((int)basicOpenerConfigAclPrefs[10] == 1)); + printCheckBox(response, "CONFOPNOPM", "Operation Mode", ((int)basicOpenerConfigAclPrefs[11] == 1)); + printCheckBox(response, "CONFOPNADVM", "Advertising Mode", ((int)basicOpenerConfigAclPrefs[12] == 1)); + printCheckBox(response, "CONFOPNTZID", "Timezone ID", ((int)basicOpenerConfigAclPrefs[13] == 1)); + + printCheckBox(response, "CONFOPNICID", "Intercom ID", ((int)advancedOpenerConfigAclPrefs[0] == 1)); + printCheckBox(response, "CONFOPNBUSMS", "BUS mode Switch", ((int)advancedOpenerConfigAclPrefs[1] == 1)); + printCheckBox(response, "CONFOPNSCDUR", "Short Circuit Duration", ((int)advancedOpenerConfigAclPrefs[2] == 1)); + printCheckBox(response, "CONFOPNESD", "Eletric Strike Delay", ((int)advancedOpenerConfigAclPrefs[3] == 1)); + printCheckBox(response, "CONFOPNRESD", "Random Electric Strike Delay", ((int)advancedOpenerConfigAclPrefs[4] == 1)); + printCheckBox(response, "CONFOPNESDUR", "Electric Strike Duration", ((int)advancedOpenerConfigAclPrefs[5] == 1)); + printCheckBox(response, "CONFOPNDRTOAR", "disable RTO after ring", ((int)advancedOpenerConfigAclPrefs[6] == 1)); + printCheckBox(response, "CONFOPNRTOT", "RTO timeout", ((int)advancedOpenerConfigAclPrefs[7] == 1)); + printCheckBox(response, "CONFOPNDRBSUP", "Doorbell suppression", ((int)advancedOpenerConfigAclPrefs[8] == 1)); + printCheckBox(response, "CONFOPNDRBSUPDUR", "Doorbell suppression duration", ((int)advancedOpenerConfigAclPrefs[9] == 1)); + printCheckBox(response, "CONFOPNSRING", "Sound Ring", ((int)advancedOpenerConfigAclPrefs[10] == 1)); + printCheckBox(response, "CONFOPNSOPN", "Sound Open", ((int)advancedOpenerConfigAclPrefs[11] == 1)); + printCheckBox(response, "CONFOPNSRTO", "Sound RTO", ((int)advancedOpenerConfigAclPrefs[12] == 1)); + printCheckBox(response, "CONFOPNSCM", "Sound CM", ((int)advancedOpenerConfigAclPrefs[13] == 1)); + printCheckBox(response, "CONFOPNSCFRM", "Sound confirmation", ((int)advancedOpenerConfigAclPrefs[14] == 1)); + printCheckBox(response, "CONFOPNSLVL", "Sound level", ((int)advancedOpenerConfigAclPrefs[15] == 1)); + printCheckBox(response, "CONFOPNSBPA", "Single button press action", ((int)advancedOpenerConfigAclPrefs[16] == 1)); + printCheckBox(response, "CONFOPNDBPA", "Double button press action", ((int)advancedOpenerConfigAclPrefs[17] == 1)); + printCheckBox(response, "CONFOPNBATT", "Battery type", ((int)advancedOpenerConfigAclPrefs[18] == 1)); + printCheckBox(response, "CONFOPNABTD", "Automatic battery type detection", ((int)advancedOpenerConfigAclPrefs[19] == 1)); + response.concat("
ChangeAllowed

"); } response.concat("
"); response.concat(""); @@ -1094,6 +1473,11 @@ void WebCfgServer::buildInfoHtml(String &response) if(_nuki != nullptr) { + uint32_t basicLockConfigAclPrefs[16]; + _preferences->getBytes(preference_conf_lock_basic_acl, &basicLockConfigAclPrefs, sizeof(basicLockConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22]; + _preferences->getBytes(preference_conf_lock_advanced_acl, &advancedLockConfigAclPrefs, sizeof(advancedLockConfigAclPrefs)); + response.concat("Lock firmware version: "); response.concat(_nuki->firmwareVersion().c_str()); response.concat("\nLock hardware version: "); @@ -1124,10 +1508,91 @@ void WebCfgServer::buildInfoHtml(String &response) response.concat((int)aclPrefs[7] ? "Allowed\n" : "Disallowed\n"); response.concat("Lock ACL (Fob Action 3): "); response.concat((int)aclPrefs[8] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Name): "); + response.concat((int)basicLockConfigAclPrefs[0] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Latitude): "); + response.concat((int)basicLockConfigAclPrefs[1] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Longitude): "); + response.concat((int)basicLockConfigAclPrefs[2] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Auto Unlatch): "); + response.concat((int)basicLockConfigAclPrefs[3] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Pairing enabled): "); + response.concat((int)basicLockConfigAclPrefs[4] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Button enabled): "); + response.concat((int)basicLockConfigAclPrefs[5] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (LED flash enabled): "); + response.concat((int)basicLockConfigAclPrefs[6] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (LED brightness): "); + response.concat((int)basicLockConfigAclPrefs[7] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Timezone offset): "); + response.concat((int)basicLockConfigAclPrefs[8] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (DST mode): "); + response.concat((int)basicLockConfigAclPrefs[9] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Fob Action 1): "); + response.concat((int)basicLockConfigAclPrefs[10] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Fob Action 2): "); + response.concat((int)basicLockConfigAclPrefs[11] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Fob Action 3): "); + response.concat((int)basicLockConfigAclPrefs[12] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Single Lock): "); + response.concat((int)basicLockConfigAclPrefs[13] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Advertising Mode): "); + response.concat((int)basicLockConfigAclPrefs[14] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Timezone ID): "); + response.concat((int)basicLockConfigAclPrefs[15] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Unlocked Position Offset Degrees): "); + response.concat((int)advancedLockConfigAclPrefs[0] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Locked Position Offset Degrees): "); + response.concat((int)advancedLockConfigAclPrefs[1] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Single Locked Position Offset Degrees): "); + response.concat((int)advancedLockConfigAclPrefs[2] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Unlocked To Locked Transition Offset Degrees): "); + response.concat((int)advancedLockConfigAclPrefs[3] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Lock ā€˜n’ Go timeout): "); + response.concat((int)advancedLockConfigAclPrefs[4] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Single button press action): "); + response.concat((int)advancedLockConfigAclPrefs[5] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Double button press action): "); + response.concat((int)advancedLockConfigAclPrefs[6] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Detached cylinder): "); + response.concat((int)advancedLockConfigAclPrefs[7] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Battery type): "); + response.concat((int)advancedLockConfigAclPrefs[8] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Automatic battery type detection): "); + response.concat((int)advancedLockConfigAclPrefs[9] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Unlatch duration): "); + response.concat((int)advancedLockConfigAclPrefs[10] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Auto lock timeout): "); + response.concat((int)advancedLockConfigAclPrefs[11] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Auto unlock disabled): "); + response.concat((int)advancedLockConfigAclPrefs[12] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Nightmode enabled): "); + response.concat((int)advancedLockConfigAclPrefs[13] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Nightmode start time): "); + response.concat((int)advancedLockConfigAclPrefs[14] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Nightmode end time): "); + response.concat((int)advancedLockConfigAclPrefs[15] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Nightmode auto lock enabled): "); + response.concat((int)advancedLockConfigAclPrefs[16] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Nightmode auto unlock disabled): "); + response.concat((int)advancedLockConfigAclPrefs[17] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Nightmode immediate lock on start): "); + response.concat((int)advancedLockConfigAclPrefs[18] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Auto lock enabled): "); + response.concat((int)advancedLockConfigAclPrefs[19] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Immediate auto lock enabled): "); + response.concat((int)advancedLockConfigAclPrefs[20] ? "Allowed\n" : "Disallowed\n"); + response.concat("Lock config ACL (Auto update enabled): "); + response.concat((int)advancedLockConfigAclPrefs[21] ? "Allowed\n" : "Disallowed\n"); } if(_nukiOpener != nullptr) { + uint32_t basicOpenerConfigAclPrefs[16]; + _preferences->getBytes(preference_conf_opener_basic_acl, &basicOpenerConfigAclPrefs, sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[22]; + _preferences->getBytes(preference_conf_opener_advanced_acl, &advancedOpenerConfigAclPrefs, sizeof(advancedOpenerConfigAclPrefs)); + response.concat("Opener firmware version: "); response.concat(_nukiOpener->firmwareVersion().c_str()); response.concat("\nOpener hardware version: "); @@ -1153,6 +1618,74 @@ void WebCfgServer::buildInfoHtml(String &response) response.concat((int)aclPrefs[15] ? "Allowed\n" : "Disallowed\n"); response.concat("Opener ACL (Fob Action 3): "); response.concat((int)aclPrefs[16] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Name): "); + response.concat((int)basicOpenerConfigAclPrefs[0] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Latitude): "); + response.concat((int)basicOpenerConfigAclPrefs[1] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Longitude): "); + response.concat((int)basicOpenerConfigAclPrefs[2] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Pairing enabled): "); + response.concat((int)basicOpenerConfigAclPrefs[3] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Button enabled): "); + response.concat((int)basicOpenerConfigAclPrefs[4] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (LED flash enabled): "); + response.concat((int)basicOpenerConfigAclPrefs[5] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Timezone offset): "); + response.concat((int)basicOpenerConfigAclPrefs[6] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (DST mode): "); + response.concat((int)basicOpenerConfigAclPrefs[7] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Fob Action 1): "); + response.concat((int)basicOpenerConfigAclPrefs[8] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Fob Action 2): "); + response.concat((int)basicOpenerConfigAclPrefs[9] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Fob Action 3): "); + response.concat((int)basicOpenerConfigAclPrefs[10] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Operation Mode): "); + response.concat((int)basicOpenerConfigAclPrefs[11] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Advertising Mode): "); + response.concat((int)basicOpenerConfigAclPrefs[12] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Timezone ID): "); + response.concat((int)basicOpenerConfigAclPrefs[13] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Intercom ID): "); + response.concat((int)advancedOpenerConfigAclPrefs[0] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (BUS mode Switch): "); + response.concat((int)advancedOpenerConfigAclPrefs[1] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Short Circuit Duration): "); + response.concat((int)advancedOpenerConfigAclPrefs[2] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Eletric Strike Delay): "); + response.concat((int)advancedOpenerConfigAclPrefs[3] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Random Electric Strike Delay): "); + response.concat((int)advancedOpenerConfigAclPrefs[4] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Electric Strike Duration): "); + response.concat((int)advancedOpenerConfigAclPrefs[5] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (disable RTO after ring): "); + response.concat((int)advancedOpenerConfigAclPrefs[6] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (RTO timeout): "); + response.concat((int)advancedOpenerConfigAclPrefs[7] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Doorbell suppression): "); + response.concat((int)advancedOpenerConfigAclPrefs[8] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Doorbell suppression duration): "); + response.concat((int)advancedOpenerConfigAclPrefs[9] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Sound Ring): "); + response.concat((int)advancedOpenerConfigAclPrefs[10] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Sound Open): "); + response.concat((int)advancedOpenerConfigAclPrefs[11] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Sound RTO): "); + response.concat((int)advancedOpenerConfigAclPrefs[12] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Sound CM): "); + response.concat((int)advancedOpenerConfigAclPrefs[13] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Sound confirmation): "); + response.concat((int)advancedOpenerConfigAclPrefs[14] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Sound level): "); + response.concat((int)advancedOpenerConfigAclPrefs[15] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Single button press action): "); + response.concat((int)advancedOpenerConfigAclPrefs[16] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Double button press action): "); + response.concat((int)advancedOpenerConfigAclPrefs[17] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Battery type): "); + response.concat((int)advancedOpenerConfigAclPrefs[18] ? "Allowed\n" : "Disallowed\n"); + response.concat("Opener config ACL (Automatic battery type detection): "); + response.concat((int)advancedOpenerConfigAclPrefs[19] ? "Allowed\n" : "Disallowed\n"); } response.concat("Network device: "); diff --git a/main.cpp b/main.cpp index 6be9e57..a529d4c 100644 --- a/main.cpp +++ b/main.cpp @@ -146,10 +146,16 @@ bool initPreferences() { preferences->putBool(preference_started_before, true); preferences->putBool(preference_lock_enabled, true); - preferences->putBool(preference_admin_enabled, true); - uint32_t aclPrefs[17] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + uint32_t basicLockConfigAclPrefs[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + preferences->putBytes(preference_conf_lock_basic_acl, (byte*)(&basicLockConfigAclPrefs), sizeof(basicLockConfigAclPrefs)); + uint32_t basicOpenerConfigAclPrefs[14] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + preferences->putBytes(preference_conf_opener_basic_acl, (byte*)(&basicOpenerConfigAclPrefs), sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[20] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs)); } else { @@ -173,40 +179,64 @@ bool initPreferences() case 0: { preferences->putBool(preference_keypad_control_enabled, true); - preferences->putBool(preference_admin_enabled, true); - uint32_t aclPrefs[17] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + uint32_t basicLockConfigAclPrefs[16] = {0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0}; + preferences->putBytes(preference_conf_lock_basic_acl, (byte*)(&basicLockConfigAclPrefs), sizeof(basicLockConfigAclPrefs)); + uint32_t basicOpenerConfigAclPrefs[14] = {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_opener_basic_acl, (byte*)(&basicOpenerConfigAclPrefs), sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0}; + preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs)); break; } case 1: { preferences->putBool(preference_keypad_control_enabled, false); - preferences->putBool(preference_admin_enabled, false); - uint32_t aclPrefs[17] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0}; preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + uint32_t basicLockConfigAclPrefs[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_lock_basic_acl, (byte*)(&basicLockConfigAclPrefs), sizeof(basicLockConfigAclPrefs)); + uint32_t basicOpenerConfigAclPrefs[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_opener_basic_acl, (byte*)(&basicOpenerConfigAclPrefs), sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs)); break; } case 2: { preferences->putBool(preference_keypad_control_enabled, false); - preferences->putBool(preference_admin_enabled, false); - uint32_t aclPrefs[17] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + uint32_t basicLockConfigAclPrefs[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_lock_basic_acl, (byte*)(&basicLockConfigAclPrefs), sizeof(basicLockConfigAclPrefs)); + uint32_t basicOpenerConfigAclPrefs[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_opener_basic_acl, (byte*)(&basicOpenerConfigAclPrefs), sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs)); break; } case 3: { preferences->putBool(preference_keypad_control_enabled, false); - preferences->putBool(preference_admin_enabled, false); - uint32_t aclPrefs[17] = {1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0}; preferences->putBytes(preference_acl, (byte*)(&aclPrefs), sizeof(aclPrefs)); + uint32_t basicLockConfigAclPrefs[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_lock_basic_acl, (byte*)(&basicLockConfigAclPrefs), sizeof(basicLockConfigAclPrefs)); + uint32_t basicOpenerConfigAclPrefs[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_opener_basic_acl, (byte*)(&basicOpenerConfigAclPrefs), sizeof(basicOpenerConfigAclPrefs)); + uint32_t advancedLockConfigAclPrefs[22] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_lock_advanced_acl, (byte*)(&advancedLockConfigAclPrefs), sizeof(advancedLockConfigAclPrefs)); + uint32_t advancedOpenerConfigAclPrefs[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs)); break; } - } + } } preferences->putInt(preference_config_version, atof(NUKI_HUB_VERSION) * 100);