apply astylerc
This commit is contained in:
@@ -5,10 +5,10 @@
|
|||||||
#include "MqttTopics.h"
|
#include "MqttTopics.h"
|
||||||
|
|
||||||
HomeAssistantDiscovery::HomeAssistantDiscovery(NetworkDevice* device, Preferences *preferences, char* buffer, size_t bufferSize)
|
HomeAssistantDiscovery::HomeAssistantDiscovery(NetworkDevice* device, Preferences *preferences, char* buffer, size_t bufferSize)
|
||||||
: _device(device),
|
: _device(device),
|
||||||
_preferences(preferences),
|
_preferences(preferences),
|
||||||
_buffer(buffer),
|
_buffer(buffer),
|
||||||
_bufferSize(bufferSize)
|
_bufferSize(bufferSize)
|
||||||
{
|
{
|
||||||
_discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery, "");
|
_discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery, "");
|
||||||
_baseTopic = _preferences->getString(preference_mqtt_lock_path);
|
_baseTopic = _preferences->getString(preference_mqtt_lock_path);
|
||||||
@@ -2905,20 +2905,20 @@ void HomeAssistantDiscovery::publishHASSConfigKeypad(char *deviceType, const cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HomeAssistantDiscovery::publishHassTopic(const String& mqttDeviceType,
|
void HomeAssistantDiscovery::publishHassTopic(const String& mqttDeviceType,
|
||||||
const String& mqttDeviceName,
|
const String& mqttDeviceName,
|
||||||
const String& uidString,
|
const String& uidString,
|
||||||
const String& uidStringPostfix,
|
const String& uidStringPostfix,
|
||||||
const String& displayName,
|
const String& displayName,
|
||||||
const String& name,
|
const String& name,
|
||||||
const String& baseTopic,
|
const String& baseTopic,
|
||||||
const String& stateTopic,
|
const String& stateTopic,
|
||||||
const String& deviceType,
|
const String& deviceType,
|
||||||
const String& deviceClass,
|
const String& deviceClass,
|
||||||
const String& stateClass,
|
const String& stateClass,
|
||||||
const String& entityCat,
|
const String& entityCat,
|
||||||
const String& commandTopic,
|
const String& commandTopic,
|
||||||
std::vector<std::pair<char*, char*>> additionalEntries
|
std::vector<std::pair<char*, char*>> additionalEntries
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (_discoveryTopic != "")
|
if (_discoveryTopic != "")
|
||||||
{
|
{
|
||||||
@@ -3056,18 +3056,18 @@ void HomeAssistantDiscovery::removeHASSConfigTopic(char *deviceType, char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonDocument HomeAssistantDiscovery::createHassJson(const String& uidString,
|
JsonDocument HomeAssistantDiscovery::createHassJson(const String& uidString,
|
||||||
const String& uidStringPostfix,
|
const String& uidStringPostfix,
|
||||||
const String& displayName,
|
const String& displayName,
|
||||||
const String& name,
|
const String& name,
|
||||||
const String& baseTopic,
|
const String& baseTopic,
|
||||||
const String& stateTopic,
|
const String& stateTopic,
|
||||||
const String& deviceType,
|
const String& deviceType,
|
||||||
const String& deviceClass,
|
const String& deviceClass,
|
||||||
const String& stateClass,
|
const String& stateClass,
|
||||||
const String& entityCat,
|
const String& entityCat,
|
||||||
const String& commandTopic,
|
const String& commandTopic,
|
||||||
std::vector<std::pair<char*, char*>> additionalEntries
|
std::vector<std::pair<char*, char*>> additionalEntries
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
JsonDocument json;
|
JsonDocument json;
|
||||||
json.clear();
|
json.clear();
|
||||||
|
|||||||
@@ -134,13 +134,13 @@ void NukiNetwork::setupDevice()
|
|||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
_device->mqttOnConnect([&](bool sessionPresent)
|
_device->mqttOnConnect([&](bool sessionPresent)
|
||||||
{
|
{
|
||||||
onMqttConnect(sessionPresent);
|
onMqttConnect(sessionPresent);
|
||||||
});
|
});
|
||||||
_device->mqttOnDisconnect([&](espMqttClientTypes::DisconnectReason reason)
|
_device->mqttOnDisconnect([&](espMqttClientTypes::DisconnectReason reason)
|
||||||
{
|
{
|
||||||
onMqttDisconnect(reason);
|
onMqttDisconnect(reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
_hadiscovery = new HomeAssistantDiscovery(_device, _preferences, _buffer, _bufferSize);
|
_hadiscovery = new HomeAssistantDiscovery(_device, _preferences, _buffer, _bufferSize);
|
||||||
#endif
|
#endif
|
||||||
@@ -199,7 +199,10 @@ bool NukiNetwork::wifiConnected()
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return _device->isConnected();
|
else
|
||||||
|
{
|
||||||
|
return _device->isConnected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NUKI_HUB_UPDATER
|
#ifdef NUKI_HUB_UPDATER
|
||||||
@@ -309,29 +312,29 @@ void NukiNetwork::initialize()
|
|||||||
{
|
{
|
||||||
switch (pinEntry.role)
|
switch (pinEntry.role)
|
||||||
{
|
{
|
||||||
case PinRole::GeneralInputPullDown:
|
case PinRole::GeneralInputPullDown:
|
||||||
case PinRole::GeneralInputPullUp:
|
case PinRole::GeneralInputPullUp:
|
||||||
if(rebGpio)
|
if(rebGpio)
|
||||||
{
|
{
|
||||||
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role});
|
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role});
|
||||||
publishString(_lockPath.c_str(), gpioPath, "input", false);
|
publishString(_lockPath.c_str(), gpioPath, "input", false);
|
||||||
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
|
|
||||||
publishString(_lockPath.c_str(), gpioPath, std::to_string(digitalRead(pinEntry.pin)).c_str(), false);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PinRole::GeneralOutput:
|
|
||||||
if(rebGpio)
|
|
||||||
{
|
|
||||||
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role});
|
|
||||||
publishString(_lockPath.c_str(), gpioPath, "output", false);
|
|
||||||
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
|
|
||||||
publishString(_lockPath.c_str(), gpioPath, "0", false);
|
|
||||||
}
|
|
||||||
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
|
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
|
||||||
subscribe(_lockPath.c_str(), gpioPath);
|
publishString(_lockPath.c_str(), gpioPath, std::to_string(digitalRead(pinEntry.pin)).c_str(), false);
|
||||||
break;
|
}
|
||||||
default:
|
break;
|
||||||
break;
|
case PinRole::GeneralOutput:
|
||||||
|
if(rebGpio)
|
||||||
|
{
|
||||||
|
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role});
|
||||||
|
publishString(_lockPath.c_str(), gpioPath, "output", false);
|
||||||
|
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
|
||||||
|
publishString(_lockPath.c_str(), gpioPath, "0", false);
|
||||||
|
}
|
||||||
|
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
|
||||||
|
subscribe(_lockPath.c_str(), gpioPath);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +379,8 @@ bool NukiNetwork::update()
|
|||||||
{
|
{
|
||||||
_mqttConnectCounter = 0;
|
_mqttConnectCounter = 0;
|
||||||
|
|
||||||
if(_firstDisconnected) {
|
if(_firstDisconnected)
|
||||||
|
{
|
||||||
_firstDisconnected = false;
|
_firstDisconnected = false;
|
||||||
_device->mqttDisconnect(true);
|
_device->mqttDisconnect(true);
|
||||||
}
|
}
|
||||||
@@ -421,7 +425,10 @@ bool NukiNetwork::update()
|
|||||||
delay(200);
|
delay(200);
|
||||||
restartEsp(RestartReason::ReconfigureWebServer);
|
restartEsp(RestartReason::ReconfigureWebServer);
|
||||||
}
|
}
|
||||||
else if(!_webEnabled) forceEnableWebServer = false;
|
else if(!_webEnabled)
|
||||||
|
{
|
||||||
|
forceEnableWebServer = false;
|
||||||
|
}
|
||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,7 +436,10 @@ bool NukiNetwork::update()
|
|||||||
{
|
{
|
||||||
if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000) && ts > 60000)
|
if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000) && ts > 60000)
|
||||||
{
|
{
|
||||||
if(!_webEnabled) forceEnableWebServer = true;
|
if(!_webEnabled)
|
||||||
|
{
|
||||||
|
forceEnableWebServer = true;
|
||||||
|
}
|
||||||
Log->println("Network timeout has been reached, restarting ...");
|
Log->println("Network timeout has been reached, restarting ...");
|
||||||
delay(200);
|
delay(200);
|
||||||
restartEsp(RestartReason::NetworkTimeoutWatchdog);
|
restartEsp(RestartReason::NetworkTimeoutWatchdog);
|
||||||
@@ -577,33 +587,33 @@ void NukiNetwork::onMqttDisconnect(const espMqttClientTypes::DisconnectReason &r
|
|||||||
Log->print("MQTT disconnected. Reason: ");
|
Log->print("MQTT disconnected. Reason: ");
|
||||||
switch(reason)
|
switch(reason)
|
||||||
{
|
{
|
||||||
case espMqttClientTypes::DisconnectReason::USER_OK:
|
case espMqttClientTypes::DisconnectReason::USER_OK:
|
||||||
Log->println(F("USER_OK"));
|
Log->println(F("USER_OK"));
|
||||||
break;
|
break;
|
||||||
case espMqttClientTypes::DisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION:
|
case espMqttClientTypes::DisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION:
|
||||||
Log->println(F("MQTT_UNACCEPTABLE_PROTOCOL_VERSION"));
|
Log->println(F("MQTT_UNACCEPTABLE_PROTOCOL_VERSION"));
|
||||||
break;
|
break;
|
||||||
case espMqttClientTypes::DisconnectReason::MQTT_IDENTIFIER_REJECTED:
|
case espMqttClientTypes::DisconnectReason::MQTT_IDENTIFIER_REJECTED:
|
||||||
Log->println(F("MQTT_IDENTIFIER_REJECTED"));
|
Log->println(F("MQTT_IDENTIFIER_REJECTED"));
|
||||||
break;
|
break;
|
||||||
case espMqttClientTypes::DisconnectReason::MQTT_SERVER_UNAVAILABLE:
|
case espMqttClientTypes::DisconnectReason::MQTT_SERVER_UNAVAILABLE:
|
||||||
Log->println(F("MQTT_SERVER_UNAVAILABLE"));
|
Log->println(F("MQTT_SERVER_UNAVAILABLE"));
|
||||||
break;
|
break;
|
||||||
case espMqttClientTypes::DisconnectReason::MQTT_MALFORMED_CREDENTIALS:
|
case espMqttClientTypes::DisconnectReason::MQTT_MALFORMED_CREDENTIALS:
|
||||||
Log->println(F("MQTT_MALFORMED_CREDENTIALS"));
|
Log->println(F("MQTT_MALFORMED_CREDENTIALS"));
|
||||||
break;
|
break;
|
||||||
case espMqttClientTypes::DisconnectReason::MQTT_NOT_AUTHORIZED:
|
case espMqttClientTypes::DisconnectReason::MQTT_NOT_AUTHORIZED:
|
||||||
Log->println(F("MQTT_NOT_AUTHORIZED"));
|
Log->println(F("MQTT_NOT_AUTHORIZED"));
|
||||||
break;
|
break;
|
||||||
case espMqttClientTypes::DisconnectReason::TLS_BAD_FINGERPRINT:
|
case espMqttClientTypes::DisconnectReason::TLS_BAD_FINGERPRINT:
|
||||||
Log->println(F("TLS_BAD_FINGERPRINT"));
|
Log->println(F("TLS_BAD_FINGERPRINT"));
|
||||||
break;
|
break;
|
||||||
case espMqttClientTypes::DisconnectReason::TCP_DISCONNECTED:
|
case espMqttClientTypes::DisconnectReason::TCP_DISCONNECTED:
|
||||||
Log->println(F("TCP_DISCONNECTED"));
|
Log->println(F("TCP_DISCONNECTED"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log->println(F("Unknown"));
|
Log->println(F("Unknown"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,7 +640,8 @@ bool NukiNetwork::reconnect()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log->print(F("MQTT: Connecting with user: ")); Log->println(_mqttUser);
|
Log->print(F("MQTT: Connecting with user: "));
|
||||||
|
Log->println(_mqttUser);
|
||||||
_device->mqttSetCredentials(_mqttUser, _mqttPass);
|
_device->mqttSetCredentials(_mqttUser, _mqttPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,7 +869,10 @@ void NukiNetwork::onMqttDataReceivedCallback(const espMqttClientTypes::MessagePr
|
|||||||
|
|
||||||
void NukiNetwork::onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t& len, size_t& index, size_t& total)
|
void NukiNetwork::onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t& len, size_t& index, size_t& total)
|
||||||
{
|
{
|
||||||
if(_mqttConnectedTs == -1 || (millis() - _mqttConnectedTs < 2000)) return;
|
if(_mqttConnectedTs == -1 || (millis() - _mqttConnectedTs < 2000))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
parseGpioTopics(properties, topic, payload, len, index, total);
|
parseGpioTopics(properties, topic, payload, len, index, total);
|
||||||
|
|
||||||
|
|||||||
@@ -118,9 +118,9 @@ void NukiNetworkOpener::initialize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_network->addReconnectedCallback([&]()
|
_network->addReconnectedCallback([&]()
|
||||||
{
|
{
|
||||||
_reconnected = true;
|
_reconnected = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkOpener::update()
|
void NukiNetworkOpener::update()
|
||||||
|
|||||||
@@ -2666,7 +2666,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end();
|
idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(action, "check") == 0) {
|
if(strcmp(action, "check") == 0)
|
||||||
|
{
|
||||||
if(!_preferences->getBool(preference_keypad_check_code_enabled, false))
|
if(!_preferences->getBool(preference_keypad_check_code_enabled, false))
|
||||||
{
|
{
|
||||||
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
|
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
|
||||||
@@ -2720,7 +2721,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
|
|
||||||
while(retryCount < _nrOfRetries + 1)
|
while(retryCount < _nrOfRetries + 1)
|
||||||
{
|
{
|
||||||
if(strcmp(action, "delete") == 0) {
|
if(strcmp(action, "delete") == 0)
|
||||||
|
{
|
||||||
if(idExists)
|
if(idExists)
|
||||||
{
|
{
|
||||||
result = _nukiOpener.deleteKeypadEntry(codeId);
|
result = _nukiOpener.deleteKeypadEntry(codeId);
|
||||||
@@ -2857,13 +2859,34 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(allowedWeekdays.indexOf("mon") >= 0) allowedWeekdaysInt += 64;
|
if(allowedWeekdays.indexOf("mon") >= 0)
|
||||||
if(allowedWeekdays.indexOf("tue") >= 0) allowedWeekdaysInt += 32;
|
{
|
||||||
if(allowedWeekdays.indexOf("wed") >= 0) allowedWeekdaysInt += 16;
|
allowedWeekdaysInt += 64;
|
||||||
if(allowedWeekdays.indexOf("thu") >= 0) allowedWeekdaysInt += 8;
|
}
|
||||||
if(allowedWeekdays.indexOf("fri") >= 0) allowedWeekdaysInt += 4;
|
if(allowedWeekdays.indexOf("tue") >= 0)
|
||||||
if(allowedWeekdays.indexOf("sat") >= 0) allowedWeekdaysInt += 2;
|
{
|
||||||
if(allowedWeekdays.indexOf("sun") >= 0) allowedWeekdaysInt += 1;
|
allowedWeekdaysInt += 32;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("wed") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 16;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("thu") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 8;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("fri") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 4;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("sat") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 2;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("sun") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(action, "add") == 0)
|
if(strcmp(action, "add") == 0)
|
||||||
@@ -2938,17 +2961,32 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
|
|
||||||
for(const auto& entry : entries)
|
for(const auto& entry : entries)
|
||||||
{
|
{
|
||||||
if (codeId != entry.codeId) continue;
|
if (codeId != entry.codeId)
|
||||||
else foundExisting = true;
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foundExisting = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(name.length() < 1)
|
if(name.length() < 1)
|
||||||
{
|
{
|
||||||
memset(oldName, 0, sizeof(oldName));
|
memset(oldName, 0, sizeof(oldName));
|
||||||
memcpy(oldName, entry.name, sizeof(entry.name));
|
memcpy(oldName, entry.name, sizeof(entry.name));
|
||||||
}
|
}
|
||||||
if(code == 12) code = entry.code;
|
if(code == 12)
|
||||||
if(enabled == 2) enabled = entry.enabled;
|
{
|
||||||
if(timeLimited == 2) timeLimited = entry.timeLimited;
|
code = entry.code;
|
||||||
|
}
|
||||||
|
if(enabled == 2)
|
||||||
|
{
|
||||||
|
enabled = entry.enabled;
|
||||||
|
}
|
||||||
|
if(timeLimited == 2)
|
||||||
|
{
|
||||||
|
timeLimited = entry.timeLimited;
|
||||||
|
}
|
||||||
if(allowedFrom.length() < 1)
|
if(allowedFrom.length() < 1)
|
||||||
{
|
{
|
||||||
allowedFrom = "old";
|
allowedFrom = "old";
|
||||||
@@ -2969,7 +3007,10 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
allowedUntilAr[4] = entry.allowedUntilMin;
|
allowedUntilAr[4] = entry.allowedUntilMin;
|
||||||
allowedUntilAr[5] = entry.allowedUntilSec;
|
allowedUntilAr[5] = entry.allowedUntilSec;
|
||||||
}
|
}
|
||||||
if(allowedWeekdays.length() < 1) allowedWeekdaysInt = entry.allowedWeekdays;
|
if(allowedWeekdays.length() < 1)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt = entry.allowedWeekdays;
|
||||||
|
}
|
||||||
if(allowedFromTime.length() < 1)
|
if(allowedFromTime.length() < 1)
|
||||||
{
|
{
|
||||||
allowedFromTime = "old";
|
allowedFromTime = "old";
|
||||||
@@ -3068,10 +3109,14 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result != Nuki::CmdResult::Success) {
|
if(result != Nuki::CmdResult::Success)
|
||||||
|
{
|
||||||
++retryCount;
|
++retryCount;
|
||||||
}
|
}
|
||||||
else break;
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateKeypad(false);
|
updateKeypad(false);
|
||||||
|
|||||||
@@ -2710,7 +2710,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end();
|
idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(action, "check") == 0) {
|
if(strcmp(action, "check") == 0)
|
||||||
|
{
|
||||||
if(!_preferences->getBool(preference_keypad_check_code_enabled, false))
|
if(!_preferences->getBool(preference_keypad_check_code_enabled, false))
|
||||||
{
|
{
|
||||||
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
|
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
|
||||||
@@ -2765,7 +2766,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
|
|
||||||
while(retryCount < _nrOfRetries + 1)
|
while(retryCount < _nrOfRetries + 1)
|
||||||
{
|
{
|
||||||
if(strcmp(action, "delete") == 0) {
|
if(strcmp(action, "delete") == 0)
|
||||||
|
{
|
||||||
if(idExists)
|
if(idExists)
|
||||||
{
|
{
|
||||||
result = _nukiLock.deleteKeypadEntry(codeId);
|
result = _nukiLock.deleteKeypadEntry(codeId);
|
||||||
@@ -2902,13 +2904,34 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(allowedWeekdays.indexOf("mon") >= 0) allowedWeekdaysInt += 64;
|
if(allowedWeekdays.indexOf("mon") >= 0)
|
||||||
if(allowedWeekdays.indexOf("tue") >= 0) allowedWeekdaysInt += 32;
|
{
|
||||||
if(allowedWeekdays.indexOf("wed") >= 0) allowedWeekdaysInt += 16;
|
allowedWeekdaysInt += 64;
|
||||||
if(allowedWeekdays.indexOf("thu") >= 0) allowedWeekdaysInt += 8;
|
}
|
||||||
if(allowedWeekdays.indexOf("fri") >= 0) allowedWeekdaysInt += 4;
|
if(allowedWeekdays.indexOf("tue") >= 0)
|
||||||
if(allowedWeekdays.indexOf("sat") >= 0) allowedWeekdaysInt += 2;
|
{
|
||||||
if(allowedWeekdays.indexOf("sun") >= 0) allowedWeekdaysInt += 1;
|
allowedWeekdaysInt += 32;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("wed") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 16;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("thu") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 8;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("fri") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 4;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("sat") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 2;
|
||||||
|
}
|
||||||
|
if(allowedWeekdays.indexOf("sun") >= 0)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(action, "add") == 0)
|
if(strcmp(action, "add") == 0)
|
||||||
@@ -2983,17 +3006,32 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
|
|
||||||
for(const auto& entry : entries)
|
for(const auto& entry : entries)
|
||||||
{
|
{
|
||||||
if (codeId != entry.codeId) continue;
|
if (codeId != entry.codeId)
|
||||||
else foundExisting = true;
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foundExisting = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(name.length() < 1)
|
if(name.length() < 1)
|
||||||
{
|
{
|
||||||
memset(oldName, 0, sizeof(oldName));
|
memset(oldName, 0, sizeof(oldName));
|
||||||
memcpy(oldName, entry.name, sizeof(entry.name));
|
memcpy(oldName, entry.name, sizeof(entry.name));
|
||||||
}
|
}
|
||||||
if(code == 12) code = entry.code;
|
if(code == 12)
|
||||||
if(enabled == 2) enabled = entry.enabled;
|
{
|
||||||
if(timeLimited == 2) timeLimited = entry.timeLimited;
|
code = entry.code;
|
||||||
|
}
|
||||||
|
if(enabled == 2)
|
||||||
|
{
|
||||||
|
enabled = entry.enabled;
|
||||||
|
}
|
||||||
|
if(timeLimited == 2)
|
||||||
|
{
|
||||||
|
timeLimited = entry.timeLimited;
|
||||||
|
}
|
||||||
if(allowedFrom.length() < 1)
|
if(allowedFrom.length() < 1)
|
||||||
{
|
{
|
||||||
allowedFrom = "old";
|
allowedFrom = "old";
|
||||||
@@ -3014,7 +3052,10 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
allowedUntilAr[4] = entry.allowedUntilMin;
|
allowedUntilAr[4] = entry.allowedUntilMin;
|
||||||
allowedUntilAr[5] = entry.allowedUntilSec;
|
allowedUntilAr[5] = entry.allowedUntilSec;
|
||||||
}
|
}
|
||||||
if(allowedWeekdays.length() < 1) allowedWeekdaysInt = entry.allowedWeekdays;
|
if(allowedWeekdays.length() < 1)
|
||||||
|
{
|
||||||
|
allowedWeekdaysInt = entry.allowedWeekdays;
|
||||||
|
}
|
||||||
if(allowedFromTime.length() < 1)
|
if(allowedFromTime.length() < 1)
|
||||||
{
|
{
|
||||||
allowedFromTime = "old";
|
allowedFromTime = "old";
|
||||||
@@ -3113,10 +3154,14 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result != Nuki::CmdResult::Success) {
|
if(result != Nuki::CmdResult::Success)
|
||||||
|
{
|
||||||
++retryCount;
|
++retryCount;
|
||||||
}
|
}
|
||||||
else break;
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateKeypad(false);
|
updateKeypad(false);
|
||||||
|
|||||||
@@ -159,9 +159,9 @@ void WebCfgServer::initialize()
|
|||||||
_psychicServer->on("/savewifi", HTTP_POST, [&](PsychicRequest *request)
|
_psychicServer->on("/savewifi", HTTP_POST, [&](PsychicRequest *request)
|
||||||
{
|
{
|
||||||
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword))
|
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword))
|
||||||
{
|
{
|
||||||
return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
|
||||||
}
|
}
|
||||||
String message = "";
|
String message = "";
|
||||||
bool connected = processWiFi(request, message);
|
bool connected = processWiFi(request, message);
|
||||||
esp_err_t res = buildConfirmHtml(request, message, 10, true);
|
esp_err_t res = buildConfirmHtml(request, message, 10, true);
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ void NetworkDevice::init()
|
|||||||
_mqttClientSecure->setCertificate(_cert);
|
_mqttClientSecure->setCertificate(_cert);
|
||||||
_mqttClientSecure->setPrivateKey(_key);
|
_mqttClientSecure->setPrivateKey(_key);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Log->println(F("MQTT without TLS."));
|
Log->println(F("MQTT without TLS."));
|
||||||
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
|
||||||
@@ -35,9 +36,18 @@ void NetworkDevice::init()
|
|||||||
{
|
{
|
||||||
MqttLoggerMode mode;
|
MqttLoggerMode mode;
|
||||||
|
|
||||||
if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb;
|
if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false))
|
||||||
else if (_preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb;
|
{
|
||||||
else mode = MqttLoggerMode::MqttAndSerial;
|
mode = MqttLoggerMode::MqttAndSerialAndWeb;
|
||||||
|
}
|
||||||
|
else if (_preferences->getBool(preference_webserial_enabled, false))
|
||||||
|
{
|
||||||
|
mode = MqttLoggerMode::SerialAndWeb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mode = MqttLoggerMode::MqttAndSerial;
|
||||||
|
}
|
||||||
|
|
||||||
_path = new char[200];
|
_path = new char[200];
|
||||||
memset(_path, 0, sizeof(_path));
|
memset(_path, 0, sizeof(_path));
|
||||||
|
|||||||
@@ -166,24 +166,24 @@ bool WifiDevice::connect()
|
|||||||
|
|
||||||
switch (status)
|
switch (status)
|
||||||
{
|
{
|
||||||
case WL_CONNECTED:
|
case WL_CONNECTED:
|
||||||
Log->println("WiFi connected");
|
Log->println("WiFi connected");
|
||||||
break;
|
break;
|
||||||
case WL_NO_SSID_AVAIL:
|
case WL_NO_SSID_AVAIL:
|
||||||
Log->println("WiFi SSID not available");
|
Log->println("WiFi SSID not available");
|
||||||
break;
|
break;
|
||||||
case WL_CONNECT_FAILED:
|
case WL_CONNECT_FAILED:
|
||||||
Log->println("WiFi connection failed");
|
Log->println("WiFi connection failed");
|
||||||
break;
|
break;
|
||||||
case WL_IDLE_STATUS:
|
case WL_IDLE_STATUS:
|
||||||
Log->println("WiFi changing status");
|
Log->println("WiFi changing status");
|
||||||
break;
|
break;
|
||||||
case WL_DISCONNECTED:
|
case WL_DISCONNECTED:
|
||||||
Log->println("WiFi disconnected");
|
Log->println("WiFi disconnected");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log->println("WiFi timeout");
|
Log->println("WiFi timeout");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != WL_CONNECTED)
|
if (status != WL_CONNECTED)
|
||||||
@@ -250,7 +250,10 @@ void WifiDevice::onConnected()
|
|||||||
|
|
||||||
void WifiDevice::onDisconnected()
|
void WifiDevice::onDisconnected()
|
||||||
{
|
{
|
||||||
if (!_connected) return;
|
if (!_connected)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
_connected = false;
|
_connected = false;
|
||||||
|
|
||||||
Log->println("Wi-Fi disconnected");
|
Log->println("Wi-Fi disconnected");
|
||||||
|
|||||||
Reference in New Issue
Block a user