From 23e4f5e5d48172d818de4280fa3861c8822b2d73 Mon Sep 17 00:00:00 2001 From: technyon Date: Fri, 13 May 2022 22:04:15 +0200 Subject: [PATCH] set lock action node to ack or unknown_action after receiving command --- Network.cpp | 7 ++++--- Network.h | 4 ++-- NukiWrapper.cpp | 6 ++++-- NukiWrapper.h | 2 +- README.md | 2 +- Version.h | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Network.cpp b/Network.cpp index 41db8ca..b5ec1a9 100644 --- a/Network.cpp +++ b/Network.cpp @@ -222,11 +222,12 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len Serial.print(F("Lock action received: ")); Serial.println(value); + bool success = false; if(_lockActionReceivedCallback != NULL) { - _lockActionReceivedCallback(value); + success = _lockActionReceivedCallback(value); } - publishString(mqtt_topic_lock_action, ""); + publishString(mqtt_topic_lock_action, success ? "ack" : "unknown_action"); } for(auto configTopic : _configTopics) @@ -323,7 +324,7 @@ void Network::publishPresenceDetection(char *csv) _presenceCsv = csv; } -void Network::setLockActionReceivedCallback(void (*lockActionReceivedCallback)(const char *)) +void Network::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *)) { _lockActionReceivedCallback = lockActionReceivedCallback; } diff --git a/Network.h b/Network.h index 8531673..5b857a5 100644 --- a/Network.h +++ b/Network.h @@ -36,7 +36,7 @@ public: void publishAdvancedConfig(const Nuki::AdvancedConfig& config); void publishPresenceDetection(char* csv); - void setLockActionReceivedCallback(void (*lockActionReceivedCallback)(const char* value)); + void setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char* value)); void setConfigUpdateReceivedCallback(void (*configUpdateReceivedCallback)(const char* path, const char* value)); void restartAndConfigureWifi(); @@ -78,6 +78,6 @@ private: long _lastMaintain = 0; - void (*_lockActionReceivedCallback)(const char* value) = nullptr; + bool (*_lockActionReceivedCallback)(const char* value) = nullptr; void (*_configUpdateReceivedCallback)(const char* path, const char* value) = nullptr; }; diff --git a/NukiWrapper.cpp b/NukiWrapper.cpp index d5b421b..3497bad 100644 --- a/NukiWrapper.cpp +++ b/NukiWrapper.cpp @@ -242,9 +242,11 @@ Nuki::LockAction NukiWrapper::lockActionToEnum(const char *str) return (Nuki::LockAction)0xff; } -void NukiWrapper::onLockActionReceivedCallback(const char *value) +bool NukiWrapper::onLockActionReceivedCallback(const char *value) { - nukiInst->_nextLockAction = nukiInst->lockActionToEnum(value); + Nuki::LockAction action = nukiInst->lockActionToEnum(value); + nukiInst->_nextLockAction = action; + return (int)action != 0xff; } void NukiWrapper::onConfigUpdateReceivedCallback(const char *topic, const char *value) diff --git a/NukiWrapper.h b/NukiWrapper.h index 054c8d8..ec3bf86 100644 --- a/NukiWrapper.h +++ b/NukiWrapper.h @@ -25,7 +25,7 @@ public: void notify(Nuki::EventType eventType) override; private: - static void onLockActionReceivedCallback(const char* value); + static bool onLockActionReceivedCallback(const char* value); static void onConfigUpdateReceivedCallback(const char* topic, const char* value); void onConfigUpdateReceived(const char* topic, const char* value); diff --git a/README.md b/README.md index e235e31..05717c6 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Just enable pairing mode on the NUKI lock and power on the ESP32. Pairing should ## MQTT Interface -- lock/action: Allows to execute lock actions. After executing the action, the value is reset to an empty string. Possible actions: unlock, lock, unlatch, lockNgo, lockNgoUnlatch, fullLock, fobAction1, fobAction2, fobAction3 +- lock/action: Allows to execute lock actions. After receiving the action, the value is set to "ack". Possible actions: unlock, lock, unlatch, lockNgo, lockNgoUnlatch, fullLock, fobAction1, fobAction2, fobAction3 - lock/state: Reports the current lock state as a string. Possible values are: uncalibrated, locked, unlocked, unlatched, unlockedLnga, unlatching, bootRun, motorBlocked - lock/trigger: The trigger of the last action: autoLock, automatic, button, manual, system - lock/completionStatus: Status of the last action as reported by NUKI lock (needs bluetooth connection): success, motorBlocked, canceled, tooRecent, busy, lowMotorVoltage, clutchFailure, motorPowerFailure, incompleteFailure, invalidCode, otherError, unknown diff --git a/Version.h b/Version.h index 4e25e3f..5e1034d 100644 --- a/Version.h +++ b/Version.h @@ -1,3 +1,3 @@ #pragma once -#define nuki_hub_version "2.1" \ No newline at end of file +#define nuki_hub_version "2.2" \ No newline at end of file