Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AuthName and Authorization log, check for validPin #368

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ Example usage for changing multiple settings at once:<br>
The result of the last configuration change action will be published to the `configuration/commandResult` MQTT topic as JSON data.<br>
<br>
The JSON data will include a node called "general" and a node for every setting that Nuki Hub detected in the action.<br>
Possible values for the "general" node are "noPinSet", "invalidJson", "invalidConfig", "success" and "noChange".<br>
Possible values for the "general" node are "noValidPinSet", "invalidJson", "invalidConfig", "success" and "noChange".<br>
Possible values for the node per setting are "unchanged", "noValueSet", "invalidValue", "valueTooLong", "accessDenied", "success", "failed", "timeOut", "working", "notPaired", "error" and "undefined"<br>
<br>
Example:
Expand Down Expand Up @@ -465,7 +465,7 @@ Examples:
### Result of attempted keypad code changes

The result of the last configuration change action will be published to the `configuration/commandResultJson` MQTT topic.<br>
Possible values are "noPinSet", "keypadControlDisabled", "keypadNotAvailable", "keypadDisabled", "invalidConfig", "invalidJson", "noActionSet", "invalidAction", "noExistingCodeIdSet", "noNameSet", "noValidCodeSet", "noCodeSet", "invalidAllowedFrom", "invalidAllowedUntil", "invalidAllowedFromTime", "invalidAllowedUntilTime", "success", "failed", "timeOut", "working", "notPaired", "error" and "undefined".<br>
Possible values are "noValidPinSet", "keypadControlDisabled", "keypadNotAvailable", "keypadDisabled", "invalidConfig", "invalidJson", "noActionSet", "invalidAction", "noExistingCodeIdSet", "noNameSet", "noValidCodeSet", "noCodeSet", "invalidAllowedFrom", "invalidAllowedUntil", "invalidAllowedFromTime", "invalidAllowedUntilTime", "success", "failed", "timeOut", "working", "notPaired", "error" and "undefined".<br>

## Keypad control (alternative, optional)

Expand Down
51 changes: 35 additions & 16 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ build_flags =
-DESP_PLATFORM
-DESP32
-DARDUINO_ARCH_ESP32
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
; -DDEBUG_SENSE_NUKI
; -DDEBUG_NUKI_COMMAND
; -DDEBUG_NUKI_CONNECT
; -DDEBUG_NUKI_COMMUNICATION
; -DDEBUG_NUKI_HEX_DATA
; -DDEBUG_NUKI_READABLE_DATA
lib_deps =

monitor_speed = 115200
Expand All @@ -41,61 +33,88 @@ monitor_filters =

[env:esp32dev]
board = esp32dev
build_flags =
${env.build_flags}
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0

[env:esp32-c3]
board = esp32-c3-devkitc-02
build_flags =
${env.build_flags}
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0

[env:esp32solo1]
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32-2023.10.03.zip
board = esp32-solo1
build_flags =
${env.build_flags}
-DFRAMEWORK_ARDUINO_SOLO1
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0

[env:esp32-s3]
board = esp32-s3-devkitc-1
build_flags =
${env.build_flags}
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0

[env:esp32dev_dbg]
extends = env:esp32dev
board = esp32dev
build_flags =
${env.build_flags}
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=4
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
-DDEBUG_NUKI_HEX_DATA
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA

[env:esp32-s3_dbg]
extends = env:esp32-s3
board = esp32-s3-devkitc-1
build_flags =
${env.build_flags}
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=4
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
-DDEBUG_NUKI_HEX_DATA
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA

[env:esp32-c3_dbg]
extends = env:esp32-c3
board = esp32-c3-devkitc-02
build_flags =
${env.build_flags}
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=4
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
-DDEBUG_NUKI_HEX_DATA
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA

[env:esp32solo1_dbg]
extends = env:esp32solo1
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32-2023.10.03.zip
board = esp32-solo1
build_flags =
${env.build_flags}
-DFRAMEWORK_ARDUINO_SOLO1
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=4
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
-DDEBUG_NUKI_HEX_DATA
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA
36 changes: 22 additions & 14 deletions src/NetworkLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const uns
if(comparePrefixedPath(topic, mqtt_topic_config_action))
{
if(strcmp(value, "") == 0 || strcmp(value, "--") == 0) return;

if(_configUpdateReceivedCallback != NULL)
{
_configUpdateReceivedCallback(value);
Expand Down Expand Up @@ -265,7 +265,7 @@ void NetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurne
}

json["trigger"] = str;

char curTime[20];
sprintf(curTime, "%04d-%02d-%02d %02d:%02d:%02d", keyTurnerState.currentTimeYear, keyTurnerState.currentTimeMonth, keyTurnerState.currentTimeDay, keyTurnerState.currentTimeHour, keyTurnerState.currentTimeMinute, keyTurnerState.currentTimeSecond);
json["currentTime"] = curTime;
Expand Down Expand Up @@ -375,11 +375,8 @@ void NetworkLock::publishState(NukiLock::LockState lockState)
void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>& logEntries)
{
char str[50];

_authId = 0;
memset(_authName, 0, sizeof(_authName));
_authName[0] = '\0';
_authFound = false;
char authName[33];
bool authFound = false;

JsonDocument json;

Expand All @@ -391,20 +388,31 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
break;
}
--i;
if((log.loggingType == NukiLock::LoggingType::LockAction || log.loggingType == NukiLock::LoggingType::KeypadAction) && ! _authFound)

memset(authName, 0, sizeof(authName));
authName[0] = '\0';

if((log.loggingType == NukiLock::LoggingType::LockAction || log.loggingType == NukiLock::LoggingType::KeypadAction))
{
_authFound = true;
_authId = log.authId;
int sizeName = sizeof(log.name);
memcpy(_authName, log.name, sizeName);
if(_authName[sizeName - 1] != '\0') _authName[sizeName] = '\0';
memcpy(authName, log.name, sizeName);
if(authName[sizeName - 1] != '\0') authName[sizeName] = '\0';

if(!authFound)
{
authFound = true;
_authFound = true;
_authId = log.authId;
memset(_authName, 0, sizeof(_authName));
memcpy(_authName, authName, sizeof(authName));
}
}

auto entry = json.add<JsonVariant>();

entry["index"] = log.index;
entry["authorizationId"] = log.authId;
entry["authorizationName"] = _authName;
entry["authorizationName"] = authName;
entry["timeYear"] = log.timeStampYear;
entry["timeMonth"] = log.timeStampMonth;
entry["timeDay"] = log.timeStampDay;
Expand Down Expand Up @@ -470,7 +478,7 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_lock_log, _buffer);

if(_authFound)
if(authFound)
{
publishUInt(mqtt_topic_lock_auth_id, _authId);
publishString(mqtt_topic_lock_auth_name, _authName);
Expand Down
33 changes: 20 additions & 13 deletions src/NetworkOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurn
}

json["trigger"] = str;

json["ringToOpenTimer"] = keyTurnerState.ringToOpenTimer;
char curTime[20];
sprintf(curTime, "%04d-%02d-%02d %02d:%02d:%02d", keyTurnerState.currentTimeYear, keyTurnerState.currentTimeMonth, keyTurnerState.currentTimeDay, keyTurnerState.currentTimeHour, keyTurnerState.currentTimeMinute, keyTurnerState.currentTimeSecond);
Expand Down Expand Up @@ -373,11 +373,8 @@ void NetworkOpener::publishState(NukiOpener::OpenerState lockState)
void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntry>& logEntries)
{
char str[50];

_authId = 0;
memset(_authName, 0, sizeof(_authName));
_authName[0] = '\0';
_authFound = false;
char authName[33];
bool authFound = false;

JsonDocument json;

Expand All @@ -390,13 +387,23 @@ void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntr
}
--i;

if((log.loggingType == NukiOpener::LoggingType::LockAction || log.loggingType == NukiOpener::LoggingType::KeypadAction) && ! _authFound)
memset(authName, 0, sizeof(authName));
authName[0] = '\0';

if((log.loggingType == NukiOpener::LoggingType::LockAction || log.loggingType == NukiOpener::LoggingType::KeypadAction))
{
_authFound = true;
_authId = log.authId;
int sizeName = sizeof(log.name);
memcpy(_authName, log.name, sizeName);
if(_authName[sizeName - 1] != '\0') _authName[sizeName] = '\0';
memcpy(authName, log.name, sizeName);
if(authName[sizeName - 1] != '\0') authName[sizeName] = '\0';

if(!authFound)
{
authFound = true;
_authFound = true;
_authId = log.authId;
memset(_authName, 0, sizeof(_authName));
memcpy(_authName, authName, sizeof(authName));
}
}

auto entry = json.add<JsonVariant>();
Expand Down Expand Up @@ -494,7 +501,7 @@ void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntr
serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_lock_log, _buffer);

if(_authFound)
if(authFound)
{
publishUInt(mqtt_topic_lock_auth_id, _authId);
publishString(mqtt_topic_lock_auth_name, _authName);
Expand Down Expand Up @@ -891,7 +898,7 @@ void NetworkOpener::publishStatusUpdated(const bool statusUpdated)
{
publishBool(mqtt_topic_lock_status_updated, statusUpdated);
}

void NetworkOpener::setLockActionReceivedCallback(LockActionResult (*lockActionReceivedCallback)(const char *))
{
_lockActionReceivedCallback = lockActionReceivedCallback;
Expand Down
Loading