Fixes (#460)
This commit is contained in:
@@ -40,8 +40,8 @@ NukiNetwork::NukiNetwork(Preferences *preferences)
|
||||
}
|
||||
|
||||
_inst = this;
|
||||
_hostname = _preferences->getString(preference_hostname);
|
||||
_webEnabled = _preferences->getBool(preference_webserver_enabled, true);
|
||||
_updateFromMQTT = _preferences->getBool(preference_update_from_mqtt, false);
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
memset(_maintenancePathPrefix, 0, sizeof(_maintenancePathPrefix));
|
||||
@@ -197,24 +197,22 @@ bool NukiNetwork::update()
|
||||
#else
|
||||
void NukiNetwork::initialize()
|
||||
{
|
||||
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect, false);
|
||||
_checkUpdates = _preferences->getBool(preference_check_updates, false);
|
||||
_reconnectNetworkOnMqttDisconnect = _preferences->getBool(preference_recon_netw_on_mqtt_discon, false);
|
||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval, 0) * 1000;
|
||||
_hostname = _preferences->getString(preference_hostname, "");
|
||||
_discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery, "");
|
||||
_mqttPort = _preferences->getInt(preference_mqtt_broker_port, 1883);
|
||||
|
||||
if(_hostname == "")
|
||||
{
|
||||
_hostname = "nukihub";
|
||||
_preferences->putString(preference_hostname, _hostname);
|
||||
}
|
||||
if(_rssiPublishInterval == 0)
|
||||
|
||||
_mqttPort = _preferences->getInt(preference_mqtt_broker_port, 0);
|
||||
|
||||
if(_mqttPort == 0)
|
||||
{
|
||||
_rssiPublishInterval = 60000;
|
||||
_preferences->putInt(preference_rssi_publish_interval, 60);
|
||||
_mqttPort = 1883;
|
||||
_preferences->putInt(preference_mqtt_broker_port, _mqttPort);
|
||||
}
|
||||
|
||||
strcpy(_hostnameArr, _hostname.c_str());
|
||||
_device->initialize();
|
||||
|
||||
@@ -224,13 +222,6 @@ void NukiNetwork::initialize()
|
||||
String brokerAddr = _preferences->getString(preference_mqtt_broker);
|
||||
strcpy(_mqttBrokerAddr, brokerAddr.c_str());
|
||||
|
||||
int port = _preferences->getInt(preference_mqtt_broker_port, 0);
|
||||
if(port == 0)
|
||||
{
|
||||
port = 1883;
|
||||
_preferences->putInt(preference_mqtt_broker_port, port);
|
||||
}
|
||||
|
||||
String mqttUser = _preferences->getString(preference_mqtt_user);
|
||||
if(mqttUser.length() > 0)
|
||||
{
|
||||
@@ -254,21 +245,12 @@ void NukiNetwork::initialize()
|
||||
Log->print(F("MQTT Broker: "));
|
||||
Log->print(_mqttBrokerAddr);
|
||||
Log->print(F(":"));
|
||||
Log->println(port);
|
||||
Log->println(_mqttPort);
|
||||
|
||||
_device->mqttSetClientId(_hostnameArr);
|
||||
_device->mqttSetCleanSession(MQTT_CLEAN_SESSIONS);
|
||||
_device->mqttSetKeepAlive(MQTT_KEEP_ALIVE);
|
||||
|
||||
_networkTimeout = _preferences->getInt(preference_network_timeout, 0);
|
||||
if(_networkTimeout == 0)
|
||||
{
|
||||
_networkTimeout = -1;
|
||||
_preferences->putInt(preference_network_timeout, _networkTimeout);
|
||||
}
|
||||
|
||||
_publishDebugInfo = _preferences->getBool(preference_publish_debug_info, false);
|
||||
|
||||
char gpioPath[250];
|
||||
bool rebGpio = rebuildGpio();
|
||||
|
||||
@@ -309,6 +291,33 @@ void NukiNetwork::initialize()
|
||||
{
|
||||
gpioActionCallback(action, pin);
|
||||
});
|
||||
|
||||
_discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery, "");
|
||||
_offEnabled = _preferences->getBool(preference_official_hybrid, false);
|
||||
readSettings();
|
||||
}
|
||||
|
||||
void NukiNetwork::readSettings()
|
||||
{
|
||||
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect, false);
|
||||
_checkUpdates = _preferences->getBool(preference_check_updates, false);
|
||||
_reconnectNetworkOnMqttDisconnect = _preferences->getBool(preference_recon_netw_on_mqtt_discon, false);
|
||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval, 0) * 1000;
|
||||
|
||||
if(_rssiPublishInterval == 0)
|
||||
{
|
||||
_rssiPublishInterval = 60000;
|
||||
_preferences->putInt(preference_rssi_publish_interval, 60);
|
||||
}
|
||||
|
||||
_networkTimeout = _preferences->getInt(preference_network_timeout, 0);
|
||||
if(_networkTimeout == 0)
|
||||
{
|
||||
_networkTimeout = -1;
|
||||
_preferences->putInt(preference_network_timeout, _networkTimeout);
|
||||
}
|
||||
|
||||
_publishDebugInfo = _preferences->getBool(preference_publish_debug_info, false);
|
||||
}
|
||||
|
||||
bool NukiNetwork::update()
|
||||
@@ -1055,7 +1064,7 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
removeHassTopic((char*)"sensor", (char*)"mqtt_log", uidString);
|
||||
}
|
||||
|
||||
if(_preferences->getBool(preference_official_hybrid, false))
|
||||
if(_offEnabled)
|
||||
{
|
||||
// Hybrid connected
|
||||
publishHassTopic("binary_sensor",
|
||||
@@ -1180,7 +1189,7 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
"",
|
||||
{ { (char*)"en", (char*)"true" }});
|
||||
|
||||
if(_preferences->getBool(preference_check_updates))
|
||||
if(_checkUpdates)
|
||||
{
|
||||
// NUKI Hub latest
|
||||
publishHassTopic("sensor",
|
||||
@@ -1204,7 +1213,7 @@ void NukiNetwork::publishHASSConfig(char* deviceType, const char* baseTopic, cha
|
||||
_lockPath.toCharArray(latest_version_topic,_lockPath.length() + 1);
|
||||
strcat(latest_version_topic, mqtt_topic_info_nuki_hub_latest);
|
||||
|
||||
if(!_preferences->getBool(preference_update_from_mqtt, false))
|
||||
if(!_updateFromMQTT)
|
||||
{
|
||||
publishHassTopic("update",
|
||||
"nuki_hub_update",
|
||||
|
||||
@@ -22,6 +22,7 @@ class NukiNetwork
|
||||
{
|
||||
public:
|
||||
void initialize();
|
||||
void readSettings();
|
||||
bool update();
|
||||
void reconfigureDevice();
|
||||
void clearWifiFallback();
|
||||
@@ -112,6 +113,8 @@ private:
|
||||
NetworkDeviceType _networkDeviceType = (NetworkDeviceType)-1;
|
||||
bool _firstBootAfterDeviceChange = false;
|
||||
bool _webEnabled = true;
|
||||
bool _updateFromMQTT = false;
|
||||
bool _offEnabled = false;
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
static void onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
|
||||
|
||||
@@ -204,7 +204,7 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const
|
||||
else if(comparePrefixedPath(topic, mqtt_topic_update) && strcmp(value, "1") == 0 && _preferences->getBool(preference_update_from_mqtt, false))
|
||||
{
|
||||
Log->println(F("Update requested via MQTT."));
|
||||
|
||||
|
||||
bool otaManifestSuccess = false;
|
||||
JsonDocument doc;
|
||||
|
||||
@@ -235,7 +235,7 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const
|
||||
{
|
||||
String currentVersion = NUKI_HUB_VERSION;
|
||||
|
||||
if(atof(doc["release"]["version"]) >= atof(currentVersion.c_str()))
|
||||
if(atof(doc["release"]["version"]) >= atof(currentVersion.c_str()))
|
||||
{
|
||||
if(strcmp(NUKI_HUB_VERSION, doc["release"]["fullversion"].as<const char*>()) == 0 && strcmp(NUKI_HUB_BUILD, doc["release"]["build"].as<const char*>()) == 0 && strcmp(NUKI_HUB_DATE, doc["release"]["time"].as<const char*>()) == 0)
|
||||
{
|
||||
@@ -294,7 +294,7 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const
|
||||
delay(200);
|
||||
restartEsp(RestartReason::OTAReboot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -702,6 +702,12 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
_authId = log.authId;
|
||||
memset(_authName, 0, sizeof(_authName));
|
||||
memcpy(_authName, authName, sizeof(authName));
|
||||
|
||||
if(authName[sizeName - 1] != '\0' && _authEntries.count(_authId) > 0)
|
||||
{
|
||||
memset(_authName, 0, sizeof(_authName));
|
||||
memcpy(_authName, _authEntries[_authId].c_str(), sizeof(_authEntries[_authId].c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,6 +716,12 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
entry["index"] = log.index;
|
||||
entry["authorizationId"] = log.authId;
|
||||
entry["authorizationName"] = authName;
|
||||
|
||||
if(entry["authorizationName"].as<String>().length() == 0 && _authEntries.count(log.authId) > 0)
|
||||
{
|
||||
entry["authorizationName"] = _authEntries[log.authId];
|
||||
}
|
||||
|
||||
entry["timeYear"] = log.timeStampYear;
|
||||
entry["timeMonth"] = log.timeStampMonth;
|
||||
entry["timeDay"] = log.timeStampDay;
|
||||
@@ -1368,6 +1380,7 @@ void NukiNetworkLock::publishAuth(const std::list<NukiLock::AuthorizationEntry>&
|
||||
jsonEntry["idType"] = entry.idType; //CONSIDER INT TO STRING
|
||||
jsonEntry["enabled"] = entry.enabled;
|
||||
jsonEntry["name"] = entry.name;
|
||||
_authEntries[jsonEntry["authId"]] = jsonEntry["name"].as<String>();
|
||||
jsonEntry["remoteAllowed"] = entry.remoteAllowed;
|
||||
char createdDT[20];
|
||||
sprintf(createdDT, "%04d-%02d-%02d %02d:%02d:%02d", entry.createdYear, entry.createdMonth, entry.createdDay, entry.createdHour, entry.createdMinute, entry.createdSecond);
|
||||
@@ -1612,7 +1625,7 @@ void NukiNetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic,
|
||||
{
|
||||
_network->removeHASSConfigTopic((char*)"binary_sensor", (char*)"door_sensor", uidString);
|
||||
}
|
||||
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
_network->publishHASSWifiRssiConfig(deviceType, baseTopic, name, uidString);
|
||||
#endif
|
||||
|
||||
@@ -105,6 +105,7 @@ private:
|
||||
NukiNetwork* _network;
|
||||
Preferences* _preferences;
|
||||
|
||||
std::map<uint32_t, String> _authEntries;
|
||||
std::vector<char*> _offTopics;
|
||||
char _mqttPath[181] = {0};
|
||||
char _offMqttPath[181] = {0};
|
||||
|
||||
@@ -481,6 +481,12 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
||||
_authId = log.authId;
|
||||
memset(_authName, 0, sizeof(_authName));
|
||||
memcpy(_authName, authName, sizeof(authName));
|
||||
|
||||
if(authName[sizeName - 1] != '\0' && _authEntries.count(_authId) > 0)
|
||||
{
|
||||
memset(_authName, 0, sizeof(_authName));
|
||||
memcpy(_authName, _authEntries[_authId].c_str(), sizeof(_authEntries[_authId].c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,6 +495,12 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
||||
entry["index"] = log.index;
|
||||
entry["authorizationId"] = log.authId;
|
||||
entry["authorizationName"] = _authName;
|
||||
|
||||
if(entry["authorizationName"].as<String>().length() == 0 && _authEntries.count(log.authId) > 0)
|
||||
{
|
||||
entry["authorizationName"] = _authEntries[log.authId];
|
||||
}
|
||||
|
||||
entry["timeYear"] = log.timeStampYear;
|
||||
entry["timeMonth"] = log.timeStampMonth;
|
||||
entry["timeDay"] = log.timeStampDay;
|
||||
@@ -1176,6 +1188,7 @@ void NukiNetworkOpener::publishAuth(const std::list<NukiOpener::AuthorizationEnt
|
||||
jsonEntry["idType"] = entry.idType; //CONSIDER INT TO STRING
|
||||
jsonEntry["enabled"] = entry.enabled;
|
||||
jsonEntry["name"] = entry.name;
|
||||
_authEntries[jsonEntry["authId"]] = jsonEntry["name"].as<String>();
|
||||
jsonEntry["remoteAllowed"] = entry.remoteAllowed;
|
||||
char createdDT[20];
|
||||
sprintf(createdDT, "%04d-%02d-%02d %02d:%02d:%02d", entry.createdYear, entry.createdMonth, entry.createdDay, entry.createdHour, entry.createdMinute, entry.createdSecond);
|
||||
|
||||
@@ -80,6 +80,7 @@ private:
|
||||
|
||||
NukiNetwork* _network = nullptr;
|
||||
|
||||
std::map<uint32_t, String> _authEntries;
|
||||
char _mqttPath[181] = {0};
|
||||
bool _isConnected = false;
|
||||
bool _firstTunerStatePublish = true;
|
||||
|
||||
@@ -31,7 +31,7 @@ NukiOpenerWrapper::NukiOpenerWrapper(const std::string& deviceName, NukiDeviceId
|
||||
|
||||
network->setLockActionReceivedCallback(nukiOpenerInst->onLockActionReceivedCallback);
|
||||
network->setConfigUpdateReceivedCallback(nukiOpenerInst->onConfigUpdateReceivedCallback);
|
||||
if(_preferences->getBool(preference_disable_non_json, false)) network->setKeypadCommandReceivedCallback(nukiOpenerInst->onKeypadCommandReceivedCallback);
|
||||
network->setKeypadCommandReceivedCallback(nukiOpenerInst->onKeypadCommandReceivedCallback);
|
||||
network->setKeypadJsonCommandReceivedCallback(nukiOpenerInst->onKeypadJsonCommandReceivedCallback);
|
||||
network->setTimeControlCommandReceivedCallback(nukiOpenerInst->onTimeControlCommandReceivedCallback);
|
||||
network->setAuthCommandReceivedCallback(nukiOpenerInst->onAuthCommandReceivedCallback);
|
||||
@@ -49,7 +49,17 @@ NukiOpenerWrapper::~NukiOpenerWrapper()
|
||||
void NukiOpenerWrapper::initialize()
|
||||
{
|
||||
_nukiOpener.initialize();
|
||||
_nukiOpener.registerBleScanner(_bleScanner);
|
||||
_nukiOpener.setEventHandler(this);
|
||||
_nukiOpener.setConnectTimeout(3);
|
||||
_nukiOpener.setDisconnectTimeout(5000);
|
||||
|
||||
_hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
|
||||
readSettings();
|
||||
}
|
||||
|
||||
void NukiOpenerWrapper::readSettings()
|
||||
{
|
||||
esp_power_level_t powerLevel;
|
||||
|
||||
int pwrLvl = _preferences->getInt(preference_ble_tx_power, 9);
|
||||
@@ -64,7 +74,6 @@ void NukiOpenerWrapper::initialize()
|
||||
else if(pwrLvl >= -12) powerLevel = ESP_PWR_LVL_N12;
|
||||
|
||||
_nukiOpener.setPower(powerLevel);
|
||||
_nukiOpener.registerBleScanner(_bleScanner);
|
||||
|
||||
_intervalLockstate = _preferences->getInt(preference_query_interval_lockstate);
|
||||
_intervalConfig = _preferences->getInt(preference_query_interval_configuration);
|
||||
@@ -76,10 +85,10 @@ void NukiOpenerWrapper::initialize()
|
||||
_maxTimeControlEntryCount = _preferences->getUInt(preference_opener_max_timecontrol_entry_count);
|
||||
_maxAuthEntryCount = _preferences->getUInt(preference_opener_max_auth_entry_count);
|
||||
_restartBeaconTimeout = _preferences->getInt(preference_restart_ble_beacon_lost);
|
||||
_hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
|
||||
_nrOfRetries = _preferences->getInt(preference_command_nr_of_retries, 200);
|
||||
_retryDelay = _preferences->getInt(preference_command_retry_delay);
|
||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000;
|
||||
_disableNonJSON = _preferences->getBool(preference_disable_non_json, false);
|
||||
_preferences->getBytes(preference_conf_opener_basic_acl, &_basicOpenerConfigAclPrefs, sizeof(_basicOpenerConfigAclPrefs));
|
||||
_preferences->getBytes(preference_conf_opener_advanced_acl, &_advancedOpenerConfigAclPrefs, sizeof(_advancedOpenerConfigAclPrefs));
|
||||
|
||||
@@ -126,10 +135,6 @@ void NukiOpenerWrapper::initialize()
|
||||
_preferences->putInt(preference_restart_ble_beacon_lost, _restartBeaconTimeout);
|
||||
}
|
||||
|
||||
_nukiOpener.setEventHandler(this);
|
||||
_nukiOpener.setConnectTimeout(3);
|
||||
_nukiOpener.setDisconnectTimeout(5000);
|
||||
|
||||
Log->print(F("Opener state interval: "));
|
||||
Log->print(_intervalLockstate);
|
||||
Log->print(F(" | Battery interval: "));
|
||||
@@ -1584,7 +1589,7 @@ void NukiOpenerWrapper::gpioActionCallback(const GpioAction &action, const int&
|
||||
|
||||
void NukiOpenerWrapper::onKeypadCommandReceived(const char *command, const uint &id, const String &name, const String &code, const int& enabled)
|
||||
{
|
||||
if(_preferences->getBool(preference_disable_non_json, false)) return;
|
||||
if(_disableNonJSON) return;
|
||||
|
||||
if(!_preferences->getBool(preference_keypad_control_enabled, false))
|
||||
{
|
||||
@@ -2625,13 +2630,13 @@ void NukiOpenerWrapper::onAuthCommandReceived(const char *value)
|
||||
memcpy(&entry.name, name.c_str(), nameLen > 32 ? 32 : nameLen);
|
||||
/*
|
||||
memcpy(&entry.sharedKey, secretKeyK, 32);
|
||||
|
||||
|
||||
if(idType != 1)
|
||||
{
|
||||
_network->publishAuthCommandResult("invalidIdType");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
entry.idType = idType;
|
||||
*/
|
||||
entry.remoteAllowed = remoteAllowed == 1 ? 1 : 0;
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
virtual ~NukiOpenerWrapper();
|
||||
|
||||
void initialize();
|
||||
void readSettings();
|
||||
void update();
|
||||
|
||||
void electricStrikeActuation();
|
||||
@@ -104,6 +105,7 @@ private:
|
||||
int _restartBeaconTimeout = 0; // seconds
|
||||
bool _publishAuthData = false;
|
||||
bool _clearAuthData = false;
|
||||
bool _disableNonJSON = false;
|
||||
int _nrOfRetries = 0;
|
||||
int _retryDelay = 0;
|
||||
int _retryCount = 0;
|
||||
|
||||
@@ -34,7 +34,7 @@ NukiWrapper::NukiWrapper(const std::string& deviceName, NukiDeviceId* deviceId,
|
||||
network->setLockActionReceivedCallback(nukiInst->onLockActionReceivedCallback);
|
||||
network->setOfficialUpdateReceivedCallback(nukiInst->onOfficialUpdateReceivedCallback);
|
||||
network->setConfigUpdateReceivedCallback(nukiInst->onConfigUpdateReceivedCallback);
|
||||
if(_disableNonJSON) network->setKeypadCommandReceivedCallback(nukiInst->onKeypadCommandReceivedCallback);
|
||||
network->setKeypadCommandReceivedCallback(nukiInst->onKeypadCommandReceivedCallback);
|
||||
network->setKeypadJsonCommandReceivedCallback(nukiInst->onKeypadJsonCommandReceivedCallback);
|
||||
network->setTimeControlCommandReceivedCallback(nukiInst->onTimeControlCommandReceivedCallback);
|
||||
network->setAuthCommandReceivedCallback(nukiInst->onAuthCommandReceivedCallback);
|
||||
@@ -51,45 +51,11 @@ NukiWrapper::~NukiWrapper()
|
||||
|
||||
void NukiWrapper::initialize(const bool& firstStart)
|
||||
{
|
||||
_preferences->remove(preference_presence_detection_timeout);
|
||||
|
||||
_nukiLock.initialize();
|
||||
|
||||
esp_power_level_t powerLevel;
|
||||
int pwrLvl = _preferences->getInt(preference_ble_tx_power, 9);
|
||||
|
||||
if(pwrLvl >= 9) powerLevel = ESP_PWR_LVL_P9;
|
||||
else if(pwrLvl >= 6) powerLevel = ESP_PWR_LVL_P6;
|
||||
else if(pwrLvl >= 3) powerLevel = ESP_PWR_LVL_P6;
|
||||
else if(pwrLvl >= 0) powerLevel = ESP_PWR_LVL_P3;
|
||||
else if(pwrLvl >= -3) powerLevel = ESP_PWR_LVL_N3;
|
||||
else if(pwrLvl >= -6) powerLevel = ESP_PWR_LVL_N6;
|
||||
else if(pwrLvl >= -9) powerLevel = ESP_PWR_LVL_N9;
|
||||
else if(pwrLvl >= -12) powerLevel = ESP_PWR_LVL_N12;
|
||||
|
||||
_nukiLock.setPower(powerLevel);
|
||||
_nukiLock.registerBleScanner(_bleScanner);
|
||||
|
||||
_intervalLockstate = _preferences->getInt(preference_query_interval_lockstate);
|
||||
_intervalHybridLockstate = _preferences->getInt(preference_query_interval_hybrid_lockstate);
|
||||
_intervalConfig = _preferences->getInt(preference_query_interval_configuration);
|
||||
_intervalBattery = _preferences->getInt(preference_query_interval_battery);
|
||||
_intervalKeypad = _preferences->getInt(preference_query_interval_keypad);
|
||||
_keypadEnabled = _preferences->getBool(preference_keypad_info_enabled);
|
||||
_publishAuthData = _preferences->getBool(preference_publish_authdata);
|
||||
_maxKeypadCodeCount = _preferences->getUInt(preference_lock_max_keypad_code_count);
|
||||
_maxTimeControlEntryCount = _preferences->getUInt(preference_lock_max_timecontrol_entry_count);
|
||||
_maxAuthEntryCount = _preferences->getUInt(preference_lock_max_auth_entry_count);
|
||||
_restartBeaconTimeout = _preferences->getInt(preference_restart_ble_beacon_lost);
|
||||
_hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
|
||||
_nrOfRetries = _preferences->getInt(preference_command_nr_of_retries, 200);
|
||||
_retryDelay = _preferences->getInt(preference_command_retry_delay);
|
||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000;
|
||||
_offEnabled = _preferences->getBool(preference_official_hybrid, false);
|
||||
_disableNonJSON = _preferences->getBool(preference_disable_non_json, false);
|
||||
|
||||
_preferences->getBytes(preference_conf_lock_basic_acl, &_basicLockConfigaclPrefs, sizeof(_basicLockConfigaclPrefs));
|
||||
_preferences->getBytes(preference_conf_lock_advanced_acl, &_advancedLockConfigaclPrefs, sizeof(_advancedLockConfigaclPrefs));
|
||||
_nukiLock.setEventHandler(this);
|
||||
_nukiLock.setConnectTimeout(3);
|
||||
_nukiLock.setDisconnectTimeout(5000);
|
||||
|
||||
if(firstStart)
|
||||
{
|
||||
@@ -138,6 +104,46 @@ void NukiWrapper::initialize(const bool& firstStart)
|
||||
_preferences->putInt(preference_query_interval_keypad, 1800);
|
||||
}
|
||||
|
||||
_hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
|
||||
_offEnabled = _preferences->getBool(preference_official_hybrid, false);
|
||||
readSettings();
|
||||
}
|
||||
|
||||
void NukiWrapper::readSettings()
|
||||
{
|
||||
esp_power_level_t powerLevel;
|
||||
int pwrLvl = _preferences->getInt(preference_ble_tx_power, 9);
|
||||
|
||||
if(pwrLvl >= 9) powerLevel = ESP_PWR_LVL_P9;
|
||||
else if(pwrLvl >= 6) powerLevel = ESP_PWR_LVL_P6;
|
||||
else if(pwrLvl >= 3) powerLevel = ESP_PWR_LVL_P6;
|
||||
else if(pwrLvl >= 0) powerLevel = ESP_PWR_LVL_P3;
|
||||
else if(pwrLvl >= -3) powerLevel = ESP_PWR_LVL_N3;
|
||||
else if(pwrLvl >= -6) powerLevel = ESP_PWR_LVL_N6;
|
||||
else if(pwrLvl >= -9) powerLevel = ESP_PWR_LVL_N9;
|
||||
else if(pwrLvl >= -12) powerLevel = ESP_PWR_LVL_N12;
|
||||
|
||||
_nukiLock.setPower(powerLevel);
|
||||
|
||||
_intervalLockstate = _preferences->getInt(preference_query_interval_lockstate);
|
||||
_intervalHybridLockstate = _preferences->getInt(preference_query_interval_hybrid_lockstate);
|
||||
_intervalConfig = _preferences->getInt(preference_query_interval_configuration);
|
||||
_intervalBattery = _preferences->getInt(preference_query_interval_battery);
|
||||
_intervalKeypad = _preferences->getInt(preference_query_interval_keypad);
|
||||
_keypadEnabled = _preferences->getBool(preference_keypad_info_enabled);
|
||||
_publishAuthData = _preferences->getBool(preference_publish_authdata);
|
||||
_maxKeypadCodeCount = _preferences->getUInt(preference_lock_max_keypad_code_count);
|
||||
_maxTimeControlEntryCount = _preferences->getUInt(preference_lock_max_timecontrol_entry_count);
|
||||
_maxAuthEntryCount = _preferences->getUInt(preference_lock_max_auth_entry_count);
|
||||
_restartBeaconTimeout = _preferences->getInt(preference_restart_ble_beacon_lost);
|
||||
_nrOfRetries = _preferences->getInt(preference_command_nr_of_retries, 200);
|
||||
_retryDelay = _preferences->getInt(preference_command_retry_delay);
|
||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval) * 1000;
|
||||
_disableNonJSON = _preferences->getBool(preference_disable_non_json, false);
|
||||
|
||||
_preferences->getBytes(preference_conf_lock_basic_acl, &_basicLockConfigaclPrefs, sizeof(_basicLockConfigaclPrefs));
|
||||
_preferences->getBytes(preference_conf_lock_advanced_acl, &_advancedLockConfigaclPrefs, sizeof(_advancedLockConfigaclPrefs));
|
||||
|
||||
if(_nrOfRetries < 0 || _nrOfRetries == 200)
|
||||
{
|
||||
Log->println("Invalid nrOfRetries, revert to default (3)");
|
||||
@@ -187,10 +193,6 @@ void NukiWrapper::initialize(const bool& firstStart)
|
||||
_preferences->putInt(preference_restart_ble_beacon_lost, _restartBeaconTimeout);
|
||||
}
|
||||
|
||||
_nukiLock.setEventHandler(this);
|
||||
_nukiLock.setConnectTimeout(3);
|
||||
_nukiLock.setDisconnectTimeout(5000);
|
||||
|
||||
Log->print(F("Lock state interval: "));
|
||||
Log->print(_intervalLockstate);
|
||||
Log->print(F(" | Battery interval: "));
|
||||
@@ -2758,7 +2760,7 @@ void NukiWrapper::onAuthCommandReceived(const char *value)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if(sharedKey.length() != 64)
|
||||
{
|
||||
@@ -2883,20 +2885,20 @@ void NukiWrapper::onAuthCommandReceived(const char *value)
|
||||
{
|
||||
_network->publishAuthCommandResult("addActionNotSupported");
|
||||
return;
|
||||
|
||||
|
||||
NukiLock::NewAuthorizationEntry entry;
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
size_t nameLen = name.length();
|
||||
memcpy(&entry.name, name.c_str(), nameLen > 32 ? 32 : nameLen);
|
||||
/*
|
||||
memcpy(&entry.sharedKey, secretKeyK, 32);
|
||||
|
||||
|
||||
if(idType != 1)
|
||||
{
|
||||
_network->publishAuthCommandResult("invalidIdType");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
entry.idType = idType;
|
||||
*/
|
||||
entry.remoteAllowed = remoteAllowed == 1 ? 1 : 0;
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
virtual ~NukiWrapper();
|
||||
|
||||
void initialize(const bool& firstStart);
|
||||
void readSettings();
|
||||
void update();
|
||||
|
||||
void lock();
|
||||
|
||||
@@ -3,105 +3,27 @@
|
||||
#include <vector>
|
||||
#include "Config.h"
|
||||
|
||||
#define preference_started_before (char*)"run"
|
||||
#define preference_config_version (char*)"confVersion"
|
||||
#define preference_device_id_lock (char*)"deviceId"
|
||||
#define preference_device_id_opener (char*)"deviceIdOp"
|
||||
#define preference_nuki_id_lock (char*)"nukiId"
|
||||
#define preference_nuki_id_opener (char*)"nukidOp"
|
||||
//CHANGE REQUIRES REBOOT TO TAKE EFFECT
|
||||
#define preference_ip_dhcp_enabled (char*)"dhcpena"
|
||||
#define preference_ip_address (char*)"ipaddr"
|
||||
#define preference_ip_subnet (char*)"ipsub"
|
||||
#define preference_ip_gateway (char*)"ipgtw"
|
||||
#define preference_ip_dns_server (char*)"dnssrv"
|
||||
#define preference_mqtt_broker (char*)"mqttbroker"
|
||||
#define preference_mqtt_broker_port (char*)"mqttport"
|
||||
#define preference_mqtt_user (char*)"mqttuser"
|
||||
#define preference_mqtt_password (char*)"mqttpass"
|
||||
#define preference_mqtt_log_enabled (char*)"mqttlog"
|
||||
#define preference_webserial_enabled (char*)"weblog"
|
||||
#define preference_webserver_enabled (char*)"websrvena"
|
||||
#define preference_lock_enabled (char*)"lockena"
|
||||
#define preference_lock_pin_status (char*)"lockpin"
|
||||
#define preference_mqtt_lock_path (char*)"mqttpath"
|
||||
#define preference_opener_enabled (char*)"openerena"
|
||||
#define preference_opener_pin_status (char*)"openerpin"
|
||||
#define preference_opener_continuous_mode (char*)"openercont"
|
||||
#define preference_mqtt_opener_path (char*)"mqttoppath"
|
||||
#define preference_check_updates (char*)"checkupdates"
|
||||
#define preference_lock_max_keypad_code_count (char*)"maxkpad"
|
||||
#define preference_opener_max_keypad_code_count (char*)"opmaxkpad"
|
||||
#define preference_lock_max_timecontrol_entry_count (char*)"maxtc"
|
||||
#define preference_opener_max_timecontrol_entry_count (char*)"opmaxtc"
|
||||
#define preference_mqtt_ca (char*)"mqttca"
|
||||
#define preference_mqtt_crt (char*)"mqttcrt"
|
||||
#define preference_mqtt_key (char*)"mqttkey"
|
||||
#define preference_mqtt_hass_discovery (char*)"hassdiscovery"
|
||||
#define preference_mqtt_hass_cu_url (char*)"hassConfigUrl"
|
||||
#define preference_ip_dhcp_enabled (char*)"dhcpena"
|
||||
#define preference_ip_address (char*)"ipaddr"
|
||||
#define preference_ip_subnet (char*)"ipsub"
|
||||
#define preference_ip_gateway (char*)"ipgtw"
|
||||
#define preference_ip_dns_server (char*)"dnssrv"
|
||||
#define preference_network_hardware (char*)"nwhw"
|
||||
#define preference_network_hardware_gpio (char*)"nwhwdt" // obsolete
|
||||
#define preference_network_wifi_fallback_disabled (char*)"nwwififb"
|
||||
#define preference_find_best_rssi (char*)"nwbestrssi"
|
||||
#define preference_rssi_publish_interval (char*)"rssipb"
|
||||
#define preference_hostname (char*)"hostname"
|
||||
#define preference_network_timeout (char*)"nettmout"
|
||||
#define preference_restart_on_disconnect (char*)"restdisc"
|
||||
#define preference_restart_ble_beacon_lost (char*)"rstbcn"
|
||||
#define preference_query_interval_lockstate (char*)"lockStInterval"
|
||||
#define preference_query_interval_configuration (char*)"configInterval"
|
||||
#define preference_query_interval_battery (char*)"batInterval"
|
||||
#define preference_query_interval_keypad (char*)"kpInterval"
|
||||
#define preference_access_level (char*)"accLvl"
|
||||
#define preference_keypad_info_enabled (char*)"kpInfoEnabled"
|
||||
#define preference_keypad_topic_per_entry (char*)"kpPerEntry"
|
||||
#define preference_keypad_control_enabled (char*)"kpCntrlEnabled"
|
||||
#define preference_keypad_publish_code (char*)"kpPubCode"
|
||||
#define preference_timecontrol_control_enabled (char*)"tcCntrlEnabled"
|
||||
#define preference_timecontrol_topic_per_entry (char*)"tcPerEntry"
|
||||
#define preference_timecontrol_info_enabled (char*)"tcInfoEnabled"
|
||||
#define preference_publish_authdata (char*)"pubAuth"
|
||||
#define preference_acl (char*)"aclLckOpn"
|
||||
#define preference_conf_info_enabled (char*)"cnfInfoEnabled"
|
||||
#define preference_conf_lock_basic_acl (char*)"confLckBasAcl"
|
||||
#define preference_conf_lock_advanced_acl (char*)"confLckAdvAcl"
|
||||
#define preference_conf_opener_basic_acl (char*)"confOpnBasAcl"
|
||||
#define preference_conf_opener_advanced_acl (char*)"confOpnAdvAcl"
|
||||
#define preference_register_as_app (char*)"regAsApp" // true = register as hub; false = register as app
|
||||
#define preference_register_opener_as_app (char*)"regOpnAsApp"
|
||||
#define preference_command_nr_of_retries (char*)"nrRetry"
|
||||
#define preference_command_retry_delay (char*)"rtryDelay"
|
||||
#define preference_cred_user (char*)"crdusr"
|
||||
#define preference_cred_password (char*)"crdpass"
|
||||
#define preference_gpio_locking_enabled (char*)"gpiolck" // obsolete
|
||||
#define preference_gpio_configuration (char*)"gpiocfg"
|
||||
#define preference_publish_debug_info (char*)"pubdbg"
|
||||
#define preference_presence_detection_timeout (char*)"prdtimeout"
|
||||
#define preference_latest_version (char*)"latest"
|
||||
#define preference_task_size_network (char*)"tsksznetw"
|
||||
#define preference_task_size_nuki (char*)"tsksznuki"
|
||||
#define preference_authlog_max_entries (char*)"authmaxentry"
|
||||
#define preference_keypad_max_entries (char*)"kpmaxentry"
|
||||
#define preference_timecontrol_max_entries (char*)"tcmaxentry"
|
||||
#define preference_bootloop_counter (char*)"btlpcounter"
|
||||
#define preference_enable_bootloop_reset (char*)"enabtlprst"
|
||||
#define preference_buffer_size (char*)"buffsize"
|
||||
#define preference_disable_non_json (char*)"disnonjson"
|
||||
#define preference_official_hybrid (char*)"offHybrid"
|
||||
#define preference_official_hybrid_actions (char*)"hybridAct"
|
||||
#define preference_official_hybrid_retry (char*)"hybridRtry"
|
||||
#define preference_query_interval_hybrid_lockstate (char*)"hybridTimer"
|
||||
#define preference_ota_main_url (char*)"otaMainUrl"
|
||||
#define preference_ota_updater_url (char*)"otaUpdUrl"
|
||||
#define preference_update_from_mqtt (char*)"updMqtt"
|
||||
#define preference_show_secrets (char*)"showSecr"
|
||||
#define preference_ble_tx_power (char*)"bleTxPwr"
|
||||
#define preference_recon_netw_on_mqtt_discon (char*)"recNtwMqttDis"
|
||||
#define preference_lock_max_auth_entry_count (char*)"maxauth"
|
||||
#define preference_opener_max_auth_entry_count (char*)"opmaxauth"
|
||||
#define preference_auth_control_enabled (char*)"authCtrlEna"
|
||||
#define preference_auth_topic_per_entry (char*)"authPerEntry"
|
||||
#define preference_auth_info_enabled (char*)"authInfoEna"
|
||||
#define preference_auth_max_entries (char*)"authmaxentry"
|
||||
#define preference_network_custom_phy (char*)"ntwPHY"
|
||||
#define preference_network_custom_addr (char*)"ntwADDR"
|
||||
#define preference_network_custom_irq (char*)"ntwIRQ"
|
||||
@@ -114,10 +36,94 @@
|
||||
#define preference_network_custom_mdio (char*)"ntwMDIO"
|
||||
#define preference_network_custom_mdc (char*)"ntwMDC"
|
||||
#define preference_network_custom_clk (char*)"ntwCLK"
|
||||
#define preference_auth_control_enabled (char*)"authCtrlEna"
|
||||
#define preference_keypad_control_enabled (char*)"kpCntrlEnabled"
|
||||
#define preference_timecontrol_control_enabled (char*)"tcCntrlEnabled"
|
||||
#define preference_ota_main_url (char*)"otaMainUrl"
|
||||
#define preference_ota_updater_url (char*)"otaUpdUrl"
|
||||
#define preference_task_size_network (char*)"tsksznetw"
|
||||
#define preference_task_size_nuki (char*)"tsksznuki"
|
||||
#define preference_buffer_size (char*)"buffsize"
|
||||
#define preference_cred_user (char*)"crdusr"
|
||||
#define preference_cred_password (char*)"crdpass"
|
||||
#define preference_gpio_configuration (char*)"gpiocfg"
|
||||
#define preference_mqtt_hass_discovery (char*)"hassdiscovery"
|
||||
#define preference_webserver_enabled (char*)"websrvena"
|
||||
#define preference_update_from_mqtt (char*)"updMqtt"
|
||||
#define preference_disable_non_json (char*)"disnonjson"
|
||||
#define preference_official_hybrid (char*)"offHybrid"
|
||||
|
||||
// CHANGE DOES NOT REQUIRE REBOOT TO TAKE EFFECT
|
||||
#define preference_find_best_rssi (char*)"nwbestrssi"
|
||||
#define preference_ntw_reconfigure (char*)"ntwRECONF"
|
||||
#define preference_auth_max_entries (char*)"authmaxentry"
|
||||
#define preference_auth_info_enabled (char*)"authInfoEna"
|
||||
#define preference_auth_topic_per_entry (char*)"authPerEntry"
|
||||
#define preference_authlog_max_entries (char*)"authmaxentry"
|
||||
#define preference_keypad_max_entries (char*)"kpmaxentry"
|
||||
#define preference_timecontrol_max_entries (char*)"tcmaxentry"
|
||||
#define preference_register_as_app (char*)"regAsApp" // true = register as hub; false = register as app
|
||||
#define preference_register_opener_as_app (char*)"regOpnAsApp"
|
||||
#define preference_acl (char*)"aclLckOpn"
|
||||
#define preference_conf_lock_basic_acl (char*)"confLckBasAcl"
|
||||
#define preference_conf_lock_advanced_acl (char*)"confLckAdvAcl"
|
||||
#define preference_conf_opener_basic_acl (char*)"confOpnBasAcl"
|
||||
#define preference_conf_opener_advanced_acl (char*)"confOpnAdvAcl"
|
||||
#define preference_ble_tx_power (char*)"bleTxPwr"
|
||||
#define preference_show_secrets (char*)"showSecr"
|
||||
#define preference_enable_bootloop_reset (char*)"enabtlprst"
|
||||
#define preference_keypad_info_enabled (char*)"kpInfoEnabled"
|
||||
#define preference_keypad_topic_per_entry (char*)"kpPerEntry"
|
||||
#define preference_keypad_publish_code (char*)"kpPubCode"
|
||||
#define preference_timecontrol_topic_per_entry (char*)"tcPerEntry"
|
||||
#define preference_timecontrol_info_enabled (char*)"tcInfoEnabled"
|
||||
#define preference_publish_authdata (char*)"pubAuth"
|
||||
#define preference_conf_info_enabled (char*)"cnfInfoEnabled"
|
||||
#define preference_restart_ble_beacon_lost (char*)"rstbcn"
|
||||
#define preference_query_interval_lockstate (char*)"lockStInterval"
|
||||
#define preference_query_interval_configuration (char*)"configInterval"
|
||||
#define preference_query_interval_battery (char*)"batInterval"
|
||||
#define preference_query_interval_keypad (char*)"kpInterval"
|
||||
#define preference_command_nr_of_retries (char*)"nrRetry"
|
||||
#define preference_command_retry_delay (char*)"rtryDelay"
|
||||
#define preference_query_interval_hybrid_lockstate (char*)"hybridTimer"
|
||||
#define preference_mqtt_hass_cu_url (char*)"hassConfigUrl"
|
||||
#define preference_network_wifi_fallback_disabled (char*)"nwwififb"
|
||||
#define preference_check_updates (char*)"checkupdates"
|
||||
#define preference_opener_continuous_mode (char*)"openercont"
|
||||
#define preference_rssi_publish_interval (char*)"rssipb"
|
||||
#define preference_network_timeout (char*)"nettmout"
|
||||
#define preference_restart_on_disconnect (char*)"restdisc"
|
||||
#define preference_publish_debug_info (char*)"pubdbg"
|
||||
#define preference_recon_netw_on_mqtt_discon (char*)"recNtwMqttDis"
|
||||
#define preference_official_hybrid_actions (char*)"hybridAct"
|
||||
#define preference_official_hybrid_retry (char*)"hybridRtry"
|
||||
|
||||
//NOT USER CHANGABLE
|
||||
#define preference_updater_version (char*)"updVer"
|
||||
#define preference_updater_build (char*)"updBuild"
|
||||
#define preference_updater_date (char*)"updDate"
|
||||
#define preference_lock_max_auth_entry_count (char*)"maxauth"
|
||||
#define preference_opener_max_auth_entry_count (char*)"opmaxauth"
|
||||
#define preference_started_before (char*)"run"
|
||||
#define preference_config_version (char*)"confVersion"
|
||||
#define preference_device_id_lock (char*)"deviceId"
|
||||
#define preference_device_id_opener (char*)"deviceIdOp"
|
||||
#define preference_nuki_id_lock (char*)"nukiId"
|
||||
#define preference_nuki_id_opener (char*)"nukidOp"
|
||||
#define preference_lock_pin_status (char*)"lockpin"
|
||||
#define preference_opener_pin_status (char*)"openerpin"
|
||||
#define preference_lock_max_keypad_code_count (char*)"maxkpad"
|
||||
#define preference_opener_max_keypad_code_count (char*)"opmaxkpad"
|
||||
#define preference_lock_max_timecontrol_entry_count (char*)"maxtc"
|
||||
#define preference_opener_max_timecontrol_entry_count (char*)"opmaxtc"
|
||||
#define preference_latest_version (char*)"latest"
|
||||
|
||||
//OBSOLETE
|
||||
#define preference_access_level (char*)"accLvl"
|
||||
#define preference_gpio_locking_enabled (char*)"gpiolck"
|
||||
#define preference_network_hardware_gpio (char*)"nwhwdt"
|
||||
#define preference_presence_detection_timeout (char*)"prdtimeout"
|
||||
|
||||
inline bool initPreferences(Preferences* preferences)
|
||||
{
|
||||
@@ -128,8 +134,6 @@ inline bool initPreferences(Preferences* preferences)
|
||||
bool firstStart = !preferences->getBool(preference_started_before);
|
||||
#endif
|
||||
|
||||
preferences->remove(preference_bootloop_counter);
|
||||
|
||||
if(firstStart)
|
||||
{
|
||||
preferences->putBool(preference_started_before, true);
|
||||
@@ -273,8 +277,8 @@ private:
|
||||
preference_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad, preference_keypad_control_enabled,
|
||||
preference_keypad_info_enabled, preference_keypad_publish_code, preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_conf_info_enabled,
|
||||
preference_register_as_app, preference_register_opener_as_app, preference_command_nr_of_retries, preference_command_retry_delay, preference_cred_user,
|
||||
preference_cred_password, preference_disable_non_json, preference_publish_authdata, preference_publish_debug_info, preference_presence_detection_timeout,
|
||||
preference_official_hybrid, preference_query_interval_hybrid_lockstate, preference_official_hybrid_actions, preference_official_hybrid_retry, preference_latest_version,
|
||||
preference_cred_password, preference_disable_non_json, preference_publish_authdata, preference_publish_debug_info,
|
||||
preference_official_hybrid, preference_query_interval_hybrid_lockstate, preference_official_hybrid_actions, preference_official_hybrid_retry,
|
||||
preference_task_size_network, preference_task_size_nuki, preference_authlog_max_entries, preference_keypad_max_entries, preference_timecontrol_max_entries,
|
||||
preference_update_from_mqtt, preference_show_secrets, preference_ble_tx_power, preference_recon_netw_on_mqtt_discon, preference_webserial_enabled,
|
||||
preference_network_custom_mdc, preference_network_custom_clk, preference_network_custom_phy, preference_network_custom_addr, preference_network_custom_irq,
|
||||
@@ -310,7 +314,7 @@ private:
|
||||
preference_lock_max_timecontrol_entry_count, preference_opener_max_timecontrol_entry_count, preference_buffer_size, preference_network_hardware,
|
||||
preference_rssi_publish_interval, preference_network_timeout, preference_restart_ble_beacon_lost, preference_query_interval_lockstate,
|
||||
preference_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad, preference_command_nr_of_retries,
|
||||
preference_command_retry_delay, preference_presence_detection_timeout, preference_query_interval_hybrid_lockstate, preference_latest_version,
|
||||
preference_command_retry_delay, preference_query_interval_hybrid_lockstate,
|
||||
preference_task_size_network, preference_task_size_nuki, preference_authlog_max_entries, preference_keypad_max_entries, preference_timecontrol_max_entries,
|
||||
preference_ble_tx_power, preference_network_custom_mdc, preference_network_custom_clk, preference_network_custom_phy, preference_network_custom_addr,
|
||||
preference_network_custom_irq, preference_network_custom_rst, preference_network_custom_cs, preference_network_custom_sck, preference_network_custom_miso,
|
||||
|
||||
2403
src/WebCfgServer.cpp
2403
src/WebCfgServer.cpp
File diff suppressed because it is too large
Load Diff
@@ -52,7 +52,7 @@ private:
|
||||
bool processImport(AsyncWebServerRequest *request, String& message);
|
||||
void processGpioArgs(AsyncWebServerRequest *request);
|
||||
void buildHtml(AsyncWebServerRequest *request);
|
||||
void buildAccLvlHtml(AsyncWebServerRequest *request, int aclPart = 0);
|
||||
void buildAccLvlHtml(AsyncWebServerRequest *request);
|
||||
void buildCredHtml(AsyncWebServerRequest *request);
|
||||
void buildImportExportHtml(AsyncWebServerRequest *request);
|
||||
void buildMqttConfigHtml(AsyncWebServerRequest *request);
|
||||
@@ -68,15 +68,13 @@ private:
|
||||
void processUnpair(AsyncWebServerRequest *request, bool opener);
|
||||
void processUpdate(AsyncWebServerRequest *request);
|
||||
void processFactoryReset(AsyncWebServerRequest *request);
|
||||
void printInputField(AsyncResponseStream *response, const char* token, const char* description, const char* value, const size_t& maxLength, const char* args, const bool& isPassword = false, const bool& showLengthRestriction = false);
|
||||
void printInputField(AsyncResponseStream *response, const char* token, const char* description, const int value, size_t maxLength, const char* args);
|
||||
void printCheckBox(AsyncResponseStream *response, const char* token, const char* description, const bool value, const char* htmlClass);
|
||||
void printCheckBox(String &partString, const char* token, const char* description, const bool value, const char* htmlClass);
|
||||
void printTextarea(AsyncResponseStream *response, const char *token, const char *description, const char *value, const size_t& maxLength, const bool& enabled = true, const bool& showLengthRestriction = false);
|
||||
void printDropDown(AsyncResponseStream *response, const char *token, const char *description, const String preselectedValue, std::vector<std::pair<String, String>> options, const String className);
|
||||
void buildNavigationButton(AsyncResponseStream *response, const char* caption, const char* targetPath, const char* labelText = "");
|
||||
void buildNavigationMenuEntry(AsyncResponseStream *response, const char *title, const char *targetPath, const char* warningMessage = "");
|
||||
void partAccLvlHtml(String &partString, int aclPart);
|
||||
void printInputField(const char* token, const char* description, const char* value, const size_t& maxLength, const char* args, const bool& isPassword = false, const bool& showLengthRestriction = false);
|
||||
void printInputField(const char* token, const char* description, const int value, size_t maxLength, const char* args);
|
||||
void printCheckBox(const char* token, const char* description, const bool value, const char* htmlClass);
|
||||
void printTextarea(const char *token, const char *description, const char *value, const size_t& maxLength, const bool& enabled = true, const bool& showLengthRestriction = false);
|
||||
void printDropDown(const char *token, const char *description, const String preselectedValue, std::vector<std::pair<String, String>> options, const String className);
|
||||
void buildNavigationButton(const char* caption, const char* targetPath, const char* labelText = "");
|
||||
void buildNavigationMenuEntry(const char *title, const char *targetPath, const char* warningMessage = "");
|
||||
|
||||
const std::vector<std::pair<String, String>> getNetworkDetectionOptions() const;
|
||||
const std::vector<std::pair<String, String>> getGpioOptions() const;
|
||||
@@ -88,7 +86,7 @@ private:
|
||||
String getPreselectionForGpio(const uint8_t& pin);
|
||||
String pinStateToString(uint8_t value);
|
||||
|
||||
void printParameter(AsyncResponseStream *response, const char* description, const char* value, const char *link = "", const char *id = "");
|
||||
void printParameter(const char* description, const char* value, const char *link = "", const char *id = "");
|
||||
|
||||
NukiWrapper* _nuki = nullptr;
|
||||
NukiOpenerWrapper* _nukiOpener = nullptr;
|
||||
@@ -98,6 +96,7 @@ private:
|
||||
bool _rebootRequired = false;
|
||||
#endif
|
||||
|
||||
String _response;
|
||||
String generateConfirmCode();
|
||||
String _confirmCode = "----";
|
||||
void buildConfirmHtml(AsyncWebServerRequest *request, const String &message, uint32_t redirectDelay = 5, bool redirect = false);
|
||||
@@ -105,10 +104,11 @@ private:
|
||||
void buildOtaCompletedHtml(AsyncWebServerRequest *request);
|
||||
void sendCss(AsyncWebServerRequest *request);
|
||||
void sendFavicon(AsyncWebServerRequest *request);
|
||||
void buildHtmlHeader(AsyncResponseStream *response, String additionalHeader = "");
|
||||
void buildHtmlHeader(String additionalHeader = "");
|
||||
void waitAndProcess(const bool blocking, const uint32_t duration);
|
||||
void handleOtaUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||
void printProgress(size_t prg, size_t sz);
|
||||
void sendResponse(AsyncWebServerRequest *request);
|
||||
|
||||
AsyncWebServer* _asyncServer = nullptr;
|
||||
NukiNetwork* _network = nullptr;
|
||||
|
||||
@@ -115,15 +115,16 @@ void setReroute(){
|
||||
void networkTask(void *pvParameters)
|
||||
{
|
||||
int64_t networkLoopTs = 0;
|
||||
bool secrets = preferences->getBool(preference_show_secrets, false);
|
||||
bool reroute = true;
|
||||
|
||||
if(preferences->getBool(preference_show_secrets, false))
|
||||
{
|
||||
preferences->putBool(preference_show_secrets, false);
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
int64_t ts = (esp_timer_get_time() / 1000);
|
||||
if(ts > 120000 && ts < 125000)
|
||||
{
|
||||
if(secrets) preferences->putBool(preference_show_secrets, false);
|
||||
if(bootloopCounter > 0)
|
||||
{
|
||||
bootloopCounter = (int8_t)0;
|
||||
|
||||
@@ -52,8 +52,6 @@ EthernetDevice::EthernetDevice(const String &hostname,
|
||||
|
||||
void EthernetDevice::init()
|
||||
{
|
||||
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect);
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
size_t caLength = _preferences->getString(preference_mqtt_ca, _ca, TLS_CA_MAX_SIZE);
|
||||
size_t crtLength = _preferences->getString(preference_mqtt_crt, _cert, TLS_CERT_MAX_SIZE);
|
||||
@@ -253,7 +251,7 @@ ReconnectStatus EthernetDevice::reconnect(bool force)
|
||||
|
||||
void EthernetDevice::onDisconnected()
|
||||
{
|
||||
if(_restartOnDisconnect && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
reconnect();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,6 @@ private:
|
||||
void onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info);
|
||||
|
||||
bool _connected = false;
|
||||
bool _restartOnDisconnect = false;
|
||||
char* _path;
|
||||
bool _hardwareInitialized = false;
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const I
|
||||
_startAp = strcmp(WiFiDevice_reconfdetect, "reconfigure_wifi") == 0;
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
_restartOnDisconnect = preferences->getBool(preference_restart_on_disconnect, false);
|
||||
|
||||
size_t caLength = preferences->getString(preference_mqtt_ca, _ca, TLS_CA_MAX_SIZE);
|
||||
size_t crtLength = preferences->getString(preference_mqtt_crt, _cert, TLS_CERT_MAX_SIZE);
|
||||
size_t keyLength = preferences->getString(preference_mqtt_key, _key, TLS_KEY_MAX_SIZE);
|
||||
@@ -49,11 +47,11 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const I
|
||||
if(preferences->getBool(preference_mqtt_log_enabled, false) || preferences->getBool(preference_webserial_enabled, false))
|
||||
{
|
||||
MqttLoggerMode mode;
|
||||
|
||||
|
||||
if(preferences->getBool(preference_mqtt_log_enabled, false) && preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb;
|
||||
else if (preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb;
|
||||
else mode = MqttLoggerMode::MqttAndSerial;
|
||||
|
||||
|
||||
_path = new char[200];
|
||||
memset(_path, 0, sizeof(_path));
|
||||
|
||||
@@ -72,15 +70,14 @@ const String WifiDevice::deviceName() const
|
||||
|
||||
void WifiDevice::initialize()
|
||||
{
|
||||
_wifiFallbackDisabled = _preferences->getBool(preference_network_wifi_fallback_disabled, false);
|
||||
std::vector<const char *> wm_menu;
|
||||
wm_menu.push_back("wifi");
|
||||
wm_menu.push_back("exit");
|
||||
_wm.setEnableConfigPortal(_startAp || !_wifiFallbackDisabled);
|
||||
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled, false));
|
||||
// reduced timeout if ESP is set to restart on disconnect
|
||||
_wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi));
|
||||
_wm.setConnectTimeout(20);
|
||||
_wm.setConfigPortalTimeout(_restartOnDisconnect ? 60 * 3 : 60 * 30);
|
||||
_wm.setConfigPortalTimeout(_preferences->getBool(preference_restart_on_disconnect, false) ? 60 * 3 : 60 * 30);
|
||||
_wm.setShowInfoUpdate(false);
|
||||
_wm.setMenu(wm_menu);
|
||||
_wm.setHostname(_hostname);
|
||||
@@ -94,7 +91,7 @@ void WifiDevice::initialize()
|
||||
|
||||
bool res = false;
|
||||
bool connectedFromPortal = false;
|
||||
|
||||
|
||||
if(_startAp)
|
||||
{
|
||||
Log->println(F("Opening Wi-Fi configuration portal."));
|
||||
@@ -119,7 +116,7 @@ void WifiDevice::initialize()
|
||||
else {
|
||||
Log->print(F("Wi-Fi connected: "));
|
||||
Log->println(WiFi.localIP().toString());
|
||||
|
||||
|
||||
if(connectedFromPortal)
|
||||
{
|
||||
Log->println(F("Connected using WifiManager portal. Wait for ESP restart."));
|
||||
@@ -160,37 +157,39 @@ bool WifiDevice::isConnected()
|
||||
|
||||
ReconnectStatus WifiDevice::reconnect(bool force)
|
||||
{
|
||||
_wm.setFindBestRSSI(_preferences->getBool(preference_find_best_rssi));
|
||||
|
||||
if((!isConnected() || force) && !_isReconnecting)
|
||||
{
|
||||
_isReconnecting = true;
|
||||
WiFi.disconnect();
|
||||
int loop = 0;
|
||||
|
||||
|
||||
while(isConnected() && loop <20)
|
||||
{
|
||||
delay(100);
|
||||
loop++;
|
||||
}
|
||||
|
||||
|
||||
_wm.resetScan();
|
||||
_wm.autoConnect();
|
||||
_isReconnecting = false;
|
||||
}
|
||||
|
||||
if(!isConnected() && _disconnectTs > (esp_timer_get_time() / 1000) - 120000) _wm.setEnableConfigPortal(_startAp || !_wifiFallbackDisabled);
|
||||
if(!isConnected() && _disconnectTs > (esp_timer_get_time() / 1000) - 120000) _wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled, false));
|
||||
return isConnected() ? ReconnectStatus::Success : ReconnectStatus::Failure;
|
||||
}
|
||||
|
||||
void WifiDevice::onConnected()
|
||||
{
|
||||
_isReconnecting = false;
|
||||
_wm.setEnableConfigPortal(_startAp || !_wifiFallbackDisabled);
|
||||
_wm.setEnableConfigPortal(_startAp || !_preferences->getBool(preference_network_wifi_fallback_disabled, false));
|
||||
}
|
||||
|
||||
void WifiDevice::onDisconnected()
|
||||
{
|
||||
_disconnectTs = (esp_timer_get_time() / 1000);
|
||||
if(_restartOnDisconnect && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
_wm.setEnableConfigPortal(false);
|
||||
reconnect();
|
||||
}
|
||||
|
||||
@@ -38,10 +38,8 @@ private:
|
||||
WiFiManager _wm;
|
||||
Preferences* _preferences = nullptr;
|
||||
|
||||
bool _restartOnDisconnect = false;
|
||||
bool _startAp = false;
|
||||
bool _isReconnecting = false;
|
||||
bool _wifiFallbackDisabled = false;
|
||||
char* _path;
|
||||
int64_t _disconnectTs = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user