only instantiate NetworkOpener when opener is enabled

This commit is contained in:
technyon
2023-01-19 19:22:43 +01:00
parent 1bba3c88e8
commit b98be654cf
2 changed files with 15 additions and 8 deletions

View File

@@ -603,7 +603,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE);
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE);
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE);
printDropDown(response, "NWHWDT", "Network hardward detection", String(_preferences->getInt(preference_network_hardware_detect)), getNetworkDetectionOptions());
printDropDown(response, "NWHWDT", "Network hardware detection", String(_preferences->getInt(preference_network_hardware_detect)), getNetworkDetectionOptions());
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
printInputField(response, "RSTTMR", "Restart timer (minutes; -1 to disable)", _preferences->getInt(preference_restart_timer), 10);

View File

@@ -38,7 +38,10 @@ void networkTask(void *pvParameters)
// Network Device and MQTT is connected. Process all updates.
case 0:
case 1:
networkOpener->update();
if(openerEnabled)
{
networkOpener->update();
}
network->update();
webCfgServer->update();
break;
@@ -163,7 +166,6 @@ bool initPreferences()
void setup()
{
Serial.begin(115200);
Log = &Serial;
@@ -174,13 +176,20 @@ void setup()
restartTs = preferences->getInt(preference_restart_timer) * 60 * 1000;
}
lockEnabled = preferences->getBool(preference_lock_enabled);
openerEnabled = preferences->getBool(preference_opener_enabled);
const String mqttLockPath = preferences->getString(preference_mqtt_lock_path);
network = new Network(preferences, mqttLockPath);
network->initialize();
networkLock = new NetworkLock(network, preferences);
networkLock->initialize();
networkOpener = new NetworkOpener(network, preferences);
networkOpener->initialize();
if(openerEnabled)
{
networkOpener = new NetworkOpener(network, preferences);
networkOpener->initialize();
}
uint32_t deviceId = preferences->getUInt(preference_deviceId);
if(deviceId == 0)
@@ -193,9 +202,8 @@ void setup()
bleScanner = new BleScanner::Scanner();
bleScanner->initialize("NukiHub");
bleScanner->setScanDuration(10);
bleScanner->setScanDuration(3);
lockEnabled = preferences->getBool(preference_lock_enabled);
Log->println(lockEnabled ? F("NUKI Lock enabled") : F("NUKI Lock disabled"));
if(lockEnabled)
{
@@ -208,7 +216,6 @@ void setup()
}
}
openerEnabled = preferences->getBool(preference_opener_enabled);
Log->println(openerEnabled ? F("NUKI Opener enabled") : F("NUKI Opener disabled"));
if(openerEnabled)
{