add auto discovery for keypad result
This commit is contained in:
@@ -43,6 +43,7 @@ include_directories(${PROJECT_NAME}
|
|||||||
set(SRCFILES
|
set(SRCFILES
|
||||||
Pins.h
|
Pins.h
|
||||||
Config.h
|
Config.h
|
||||||
|
CharBuffer.cpp
|
||||||
Network.cpp
|
Network.cpp
|
||||||
MqttReceiver.h
|
MqttReceiver.h
|
||||||
NetworkLock.cpp
|
NetworkLock.cpp
|
||||||
|
|||||||
13
CharBuffer.cpp
Normal file
13
CharBuffer.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "CharBuffer.h"
|
||||||
|
|
||||||
|
void CharBuffer::initialize()
|
||||||
|
{
|
||||||
|
_buffer = new char[CHAR_BUFFER_SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
char *CharBuffer::get()
|
||||||
|
{
|
||||||
|
return _buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* CharBuffer::_buffer;
|
||||||
13
CharBuffer.h
Normal file
13
CharBuffer.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define CHAR_BUFFER_SIZE 4096
|
||||||
|
|
||||||
|
class CharBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void initialize();
|
||||||
|
static char* get();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static char* _buffer;
|
||||||
|
};
|
||||||
22
Network.cpp
22
Network.cpp
@@ -890,8 +890,28 @@ void Network::publishHASSConfigAccessLog(char *deviceType, const char *baseTopic
|
|||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
"",
|
"",
|
||||||
{ { "value_template", "{{ (value_json|selectattr('type', 'eq', 'LockAction')|selectattr('action', 'in', ['Lock', 'Unlock', 'Unlatch'])|first).authorizationName }}" }});}
|
{ { "ic", "mdi:format-list-bulleted" },
|
||||||
|
{ "value_template", "{{ (value_json|selectattr('type', 'eq', 'LockAction')|selectattr('action', 'in', ['Lock', 'Unlock', 'Unlatch'])|first).authorizationName }}" }});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Network::publishHASSConfigKeypadAttemptInfo(char *deviceType, const char *baseTopic, char *name, char *uidString)
|
||||||
|
{
|
||||||
|
publishHassTopic("sensor",
|
||||||
|
"keypad_status",
|
||||||
|
uidString,
|
||||||
|
"_keypad_stats",
|
||||||
|
"Keypad status",
|
||||||
|
name,
|
||||||
|
baseTopic,
|
||||||
|
mqtt_topic_lock_log,
|
||||||
|
deviceType,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"diagnostic",
|
||||||
|
"",
|
||||||
|
{ { "ic", "mdi:drag-vertical" },
|
||||||
|
{ "value_template", "{% for state in value_json %} {% if state.type == 'KeypadAction' %} {{ state.completionStatus }} {% endif %} {% endfor %}" }});
|
||||||
|
}
|
||||||
|
|
||||||
void Network::publishHASSWifiRssiConfig(char *deviceType, const char *baseTopic, char *name, char *uidString)
|
void Network::publishHASSWifiRssiConfig(char *deviceType, const char *baseTopic, char *name, char *uidString)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public:
|
|||||||
void publishHASSConfigLedBrightness(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
void publishHASSConfigLedBrightness(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
||||||
void publishHASSConfigSoundLevel(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
void publishHASSConfigSoundLevel(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
||||||
void publishHASSConfigAccessLog(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
void publishHASSConfigAccessLog(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
||||||
|
void publishHASSConfigKeypadAttemptInfo(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
||||||
void publishHASSWifiRssiConfig(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
void publishHASSWifiRssiConfig(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
||||||
void publishHASSBleRssiConfig(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
void publishHASSBleRssiConfig(char* deviceType, const char* baseTopic, char* name, char* uidString);
|
||||||
void removeHASSConfig(char* uidString);
|
void removeHASSConfig(char* uidString);
|
||||||
|
|||||||
@@ -5,10 +5,14 @@
|
|||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "RestartReason.h"
|
#include "RestartReason.h"
|
||||||
|
#include "CharBuffer.h"
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
NetworkLock::NetworkLock(Network* network, Preferences* preferences)
|
NetworkLock::NetworkLock(Network* network, Preferences* preferences, char* buffer, size_t bufferSize)
|
||||||
: _network(network),
|
: _network(network),
|
||||||
_preferences(preferences)
|
_preferences(preferences),
|
||||||
|
_buffer(buffer),
|
||||||
|
_bufferSize(bufferSize)
|
||||||
{
|
{
|
||||||
_configTopics.reserve(5);
|
_configTopics.reserve(5);
|
||||||
_configTopics.push_back(mqtt_topic_config_button_enabled);
|
_configTopics.push_back(mqtt_topic_config_button_enabled);
|
||||||
@@ -273,7 +277,6 @@ void NetworkLock::publishBinaryState(NukiLock::LockState lockState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>& logEntries)
|
void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>& logEntries)
|
||||||
{
|
{
|
||||||
char str[50];
|
char str[50];
|
||||||
@@ -283,7 +286,7 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
|
|||||||
char authName[33];
|
char authName[33];
|
||||||
memset(authName, 0, sizeof(authName));
|
memset(authName, 0, sizeof(authName));
|
||||||
|
|
||||||
String json = "[\n";
|
DynamicJsonDocument json(_bufferSize);
|
||||||
|
|
||||||
for(const auto& log : logEntries)
|
for(const auto& log : logEntries)
|
||||||
{
|
{
|
||||||
@@ -294,90 +297,75 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
|
|||||||
memcpy(authName, log.name, sizeof(log.name));
|
memcpy(authName, log.name, sizeof(log.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
json.concat("{\n");
|
auto entry = json.add();
|
||||||
|
|
||||||
json.concat("\"index\": "); json.concat(log.index); json.concat(",\n");
|
entry["index"] = log.index;
|
||||||
json.concat("\"authorizationId\": "); json.concat(log.authId); json.concat(",\n");
|
entry["authorizationId"] = log.authId;
|
||||||
|
entry["authorizationName"] = log.name;
|
||||||
memset(str, 0, sizeof(str));
|
entry["timeYear"] = log.timeStampYear;
|
||||||
memcpy(str, log.name, sizeof(log.name));
|
entry["timeMonth"] = log.timeStampMonth;
|
||||||
json.concat("\"authorizationName\": \""); json.concat(str); json.concat("\",\n");
|
entry["timeDay"] = log.timeStampDay;
|
||||||
|
entry["timeHour"] = log.timeStampHour;
|
||||||
json.concat("\"timeYear\": "); json.concat(log.timeStampYear); json.concat(",\n");
|
entry["timeMinute"] = log.timeStampMinute;
|
||||||
json.concat("\"timeMonth\": "); json.concat(log.timeStampMonth); json.concat(",\n");
|
entry["timeSecond"] = log.timeStampSecond;
|
||||||
json.concat("\"timeDay\": "); json.concat(log.timeStampDay); json.concat(",\n");
|
|
||||||
json.concat("\"timeHour\": "); json.concat(log.timeStampHour); json.concat(",\n");
|
|
||||||
json.concat("\"timeMinute\": "); json.concat(log.timeStampMinute); json.concat(",\n");
|
|
||||||
json.concat("\"timeSecond\": "); json.concat(log.timeStampSecond); json.concat(",\n");
|
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
loggingTypeToString(log.loggingType, str);
|
loggingTypeToString(log.loggingType, str);
|
||||||
json.concat("\"type\": \""); json.concat(str); json.concat("\",\n");
|
entry["type"] = str;
|
||||||
|
|
||||||
switch(log.loggingType)
|
switch(log.loggingType)
|
||||||
{
|
{
|
||||||
case NukiLock::LoggingType::LockAction:
|
case NukiLock::LoggingType::LockAction:
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||||
json.concat("\"action\": \""); json.concat(str); json.concat("\",\n");
|
entry["action"] = str;
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
|
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
|
||||||
json.concat("\"trigger\": \""); json.concat(str); json.concat("\",\n");
|
entry["trigger"] = str;
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
||||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
entry["completionStatus"] = str;
|
||||||
break;
|
break;
|
||||||
case NukiLock::LoggingType::KeypadAction:
|
case NukiLock::LoggingType::KeypadAction:
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||||
json.concat("\"action\": \""); json.concat(str); json.concat("\",\n");
|
entry["action"] = str;
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
entry["completionStatus"] = str;
|
||||||
break;
|
break;
|
||||||
case NukiLock::LoggingType::DoorSensor:
|
case NukiLock::LoggingType::DoorSensor:
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||||
json.concat("\"action\": \"");
|
|
||||||
switch(log.data[0])
|
switch(log.data[0])
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
json.concat("DoorOpened");
|
entry["action"] = "DoorOpened";
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
json.concat("DoorClosed");
|
entry["action"] = "DoorClosed";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
json.concat("SensorJammed");
|
entry["action"] = "SensorJammed";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
json.concat("Unknown");
|
entry["action"] = "Unknown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
json.concat("\",\n");
|
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
entry["completionStatus"] = str;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
json.concat("}");
|
|
||||||
if(&log == &logEntries.back())
|
|
||||||
{
|
|
||||||
json.concat("\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
json.concat(",\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json.concat("]");
|
serializeJson(json, reinterpret_cast<char(&)[CHAR_BUFFER_SIZE]>(*_buffer));
|
||||||
publishString(mqtt_topic_lock_log, json);
|
publishString(mqtt_topic_lock_log, _buffer);
|
||||||
|
|
||||||
if(authFound)
|
if(authFound)
|
||||||
{
|
{
|
||||||
@@ -540,6 +528,15 @@ void NetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic, cha
|
|||||||
{
|
{
|
||||||
_network->removeHASSConfigTopic("sensor", "last_action_authorization", uidString);
|
_network->removeHASSConfigTopic("sensor", "last_action_authorization", uidString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(hasKeypad)
|
||||||
|
{
|
||||||
|
_network->publishHASSConfigKeypadAttemptInfo(deviceType, baseTopic, name, uidString);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_network->removeHASSConfigTopic("sensor", "keypad_status", uidString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkLock::removeHASSConfig(char *uidString)
|
void NetworkLock::removeHASSConfig(char *uidString)
|
||||||
|
|||||||
@@ -11,10 +11,12 @@
|
|||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
#include "QueryCommand.h"
|
#include "QueryCommand.h"
|
||||||
|
|
||||||
|
#define LOCK_LOG_JSON_BUFFER_SIZE 2048
|
||||||
|
|
||||||
class NetworkLock : public MqttReceiver
|
class NetworkLock : public MqttReceiver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit NetworkLock(Network* network, Preferences* preferences);
|
explicit NetworkLock(Network* network, Preferences* preferences, char* buffer, size_t bufferSize);
|
||||||
virtual ~NetworkLock();
|
virtual ~NetworkLock();
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
@@ -79,6 +81,9 @@ private:
|
|||||||
int _keypadCommandEnabled = 1;
|
int _keypadCommandEnabled = 1;
|
||||||
uint8_t _queryCommands = 0;
|
uint8_t _queryCommands = 0;
|
||||||
|
|
||||||
|
char* _buffer;
|
||||||
|
size_t _bufferSize;
|
||||||
|
|
||||||
bool (*_lockActionReceivedCallback)(const char* value) = nullptr;
|
bool (*_lockActionReceivedCallback)(const char* value) = nullptr;
|
||||||
void (*_configUpdateReceivedCallback)(const char* path, const char* value) = nullptr;
|
void (*_configUpdateReceivedCallback)(const char* path, const char* value) = nullptr;
|
||||||
void (*_keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled) = nullptr;
|
void (*_keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled) = nullptr;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
NetworkOpener::NetworkOpener(Network* network, Preferences* preferences)
|
NetworkOpener::NetworkOpener(Network* network, Preferences* preferences)
|
||||||
: _preferences(preferences),
|
: _preferences(preferences),
|
||||||
@@ -268,130 +269,114 @@ void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntr
|
|||||||
char authName[33];
|
char authName[33];
|
||||||
memset(authName, 0, sizeof(authName));
|
memset(authName, 0, sizeof(authName));
|
||||||
|
|
||||||
String json = "[\n";
|
char *jsonOut = new char[OPENER_LOG_JSON_BUFFER_SIZE];
|
||||||
|
DynamicJsonDocument json(OPENER_LOG_JSON_BUFFER_SIZE);
|
||||||
|
|
||||||
for(const auto& log : logEntries)
|
for(const auto& log : logEntries)
|
||||||
{
|
{
|
||||||
if((log.loggingType == NukiOpener::LoggingType::LockAction || log.loggingType == NukiOpener::LoggingType::KeypadAction || log.loggingType == NukiOpener::LoggingType::DoorbellRecognition) && ! authFound)
|
if((log.loggingType == NukiOpener::LoggingType::LockAction || log.loggingType == NukiOpener::LoggingType::KeypadAction) && ! authFound)
|
||||||
{
|
{
|
||||||
authFound = true;
|
authFound = true;
|
||||||
authId = log.authId;
|
authId = log.authId;
|
||||||
memcpy(authName, log.name, sizeof(log.name));
|
memcpy(authName, log.name, sizeof(log.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
json.concat("{\n");
|
auto entry = json.add();
|
||||||
|
|
||||||
json.concat("\"index\": "); json.concat(log.index); json.concat(",\n");
|
entry["index"] = log.index;
|
||||||
json.concat("\"authorizationId\": "); json.concat(log.authId); json.concat(",\n");
|
entry["authorizationId"] = log.authId;
|
||||||
|
entry["authorizationName"] = log.name;
|
||||||
memset(str, 0, sizeof(str));
|
entry["timeYear"] = log.timeStampYear;
|
||||||
memcpy(str, log.name, sizeof(log.name));
|
entry["timeMonth"] = log.timeStampMonth;
|
||||||
json.concat("\"authorizationName\": \""); json.concat(str); json.concat("\",\n");
|
entry["timeDay"] = log.timeStampDay;
|
||||||
|
entry["timeHour"] = log.timeStampHour;
|
||||||
json.concat("\"timeYear\": "); json.concat(log.timeStampYear); json.concat(",\n");
|
entry["timeMinute"] = log.timeStampMinute;
|
||||||
json.concat("\"timeMonth\": "); json.concat(log.timeStampMonth); json.concat(",\n");
|
entry["timeSecond"] = log.timeStampSecond;
|
||||||
json.concat("\"timeDay\": "); json.concat(log.timeStampDay); json.concat(",\n");
|
|
||||||
json.concat("\"timeHour\": "); json.concat(log.timeStampHour); json.concat(",\n");
|
|
||||||
json.concat("\"timeMinute\": "); json.concat(log.timeStampMinute); json.concat(",\n");
|
|
||||||
json.concat("\"timeSecond\": "); json.concat(log.timeStampSecond); json.concat(",\n");
|
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
loggingTypeToString(log.loggingType, str);
|
loggingTypeToString(log.loggingType, str);
|
||||||
json.concat("\"type\": \""); json.concat(str); json.concat("\",\n");
|
entry["type"] = str;
|
||||||
|
|
||||||
switch(log.loggingType)
|
switch(log.loggingType)
|
||||||
{
|
{
|
||||||
case NukiOpener::LoggingType::LockAction:
|
case NukiOpener::LoggingType::LockAction:
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
lockactionToString((NukiOpener::LockAction)log.data[0], str);
|
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||||
json.concat("\"action\": \""); json.concat(str); json.concat("\",\n");
|
entry["action"] = str;
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
triggerToString((NukiOpener::Trigger)log.data[1], str);
|
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
|
||||||
json.concat("\"trigger\": \""); json.concat(str); json.concat("\",\n");
|
entry["trigger"] = str;
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
logactionCompletionStatusToString(log.data[3], str);
|
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
||||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
entry["completionStatus"] = str;
|
||||||
break;
|
break;
|
||||||
case NukiOpener::LoggingType::KeypadAction:
|
case NukiOpener::LoggingType::KeypadAction:
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
lockactionToString((NukiOpener::LockAction)log.data[0], str);
|
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||||
json.concat("\"action\": \""); json.concat(str); json.concat("\",\n");
|
entry["action"] = str;
|
||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
completionStatusToString((NukiOpener::CompletionStatus)log.data[2], str);
|
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
entry["completionStatus"] = str;
|
||||||
break;
|
break;
|
||||||
case NukiOpener::LoggingType::DoorbellRecognition:
|
case NukiOpener::LoggingType::DoorbellRecognition:
|
||||||
json.concat("\"mode\": \"");
|
|
||||||
switch(log.data[0] & 3)
|
switch(log.data[0] & 3)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
json.concat("None");
|
entry["mode"] = "None";
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
json.concat("RTO");
|
entry["mode"] = "RTO";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
json.concat("CM");
|
entry["mode"] = "CM";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
json.concat("Unknown");
|
entry["mode"] = "Unknown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
json.concat("\",\n");
|
|
||||||
|
|
||||||
json.concat("\"source\": \"");
|
|
||||||
switch(log.data[1])
|
switch(log.data[1])
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
json.concat("Doorbell");
|
entry["source"] = "Doorbell";
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
json.concat("Timecontrol");
|
entry["source"] = "Timecontrol";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
json.concat("App");
|
entry["source"] = "App";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
json.concat("Button");
|
entry["source"] = "Button";
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
json.concat("Fob");
|
entry["source"] = "Fob";
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
json.concat("Bridge");
|
entry["source"] = "Bridge";
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
json.concat("Keypad");
|
entry["source"] = "Keypad";
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
json.concat("\",\n");
|
entry["source"] = "Unknown";
|
||||||
|
break; }
|
||||||
|
|
||||||
json.concat("\"geofence\": \""); json.concat(log.data[2] == 1 ? "active" : "inactive"); json.concat("\",\n");
|
entry["geofence"] = log.data[2] == 1 ? "active" : "inactive";
|
||||||
json.concat("\"doorbellSuppression\": \""); json.concat(log.data[3] == 1 ? "active" : "inactive"); json.concat("\",\n");
|
entry["doorbellSuppression"] = log.data[3] == 1 ? "active" : "inactive";
|
||||||
|
entry["completionStatus"] = str;
|
||||||
memset(str, 0, sizeof(str));
|
|
||||||
logactionCompletionStatusToString(log.data[5], str);
|
|
||||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
json.concat("}");
|
|
||||||
if(&log == &logEntries.back())
|
|
||||||
{
|
|
||||||
json.concat("\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
json.concat(",\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json.concat("]");
|
serializeJson(json, reinterpret_cast<char(&)[OPENER_LOG_JSON_BUFFER_SIZE]>(*jsonOut));
|
||||||
publishString(mqtt_topic_lock_log, json);
|
publishString(mqtt_topic_lock_log, jsonOut);
|
||||||
|
|
||||||
|
delete jsonOut;
|
||||||
|
|
||||||
if(authFound)
|
if(authFound)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include "NukiOpenerConstants.h"
|
#include "NukiOpenerConstants.h"
|
||||||
#include "NetworkLock.h"
|
#include "NetworkLock.h"
|
||||||
|
|
||||||
|
#define OPENER_LOG_JSON_BUFFER_SIZE 2048
|
||||||
|
|
||||||
class NetworkOpener : public MqttReceiver
|
class NetworkOpener : public MqttReceiver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -646,7 +646,7 @@ void NukiOpenerWrapper::setupHASS()
|
|||||||
String baseTopic = _preferences->getString(preference_mqtt_opener_path);
|
String baseTopic = _preferences->getString(preference_mqtt_opener_path);
|
||||||
char uidString[20];
|
char uidString[20];
|
||||||
itoa(_nukiConfig.nukiId, uidString, 16);
|
itoa(_nukiConfig.nukiId, uidString, 16);
|
||||||
_network->publishHASSConfig("Opener",baseTopic.c_str(),(char*)_nukiConfig.name,uidString, _publishAuthData, "deactivateRTO","activateRTO","electricStrikeActuation","locked","unlocked");
|
_network->publishHASSConfig("Opener",baseTopic.c_str(),(char*)_nukiConfig.name,uidString, "deactivateRTO","activateRTO","electricStrikeActuation","locked","unlocked");
|
||||||
_hassSetupCompleted = true;
|
_hassSetupCompleted = true;
|
||||||
|
|
||||||
Log->println("HASS setup for opener completed.");
|
Log->println("HASS setup for opener completed.");
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#include "PresenceDetection.h"
|
#include "PresenceDetection.h"
|
||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "CharBuffer.h"
|
||||||
|
|
||||||
PresenceDetection::PresenceDetection(Preferences* preferences, BleScanner::Scanner *bleScanner, Network* network)
|
PresenceDetection::PresenceDetection(Preferences* preferences, BleScanner::Scanner *bleScanner, Network* network, char* buffer, size_t bufferSize)
|
||||||
: _preferences(preferences),
|
: _preferences(preferences),
|
||||||
_bleScanner(bleScanner),
|
_bleScanner(bleScanner),
|
||||||
_network(network)
|
_network(network),
|
||||||
|
_csv(buffer),
|
||||||
|
_bufferSize(bufferSize)
|
||||||
{
|
{
|
||||||
_csv = new char[presence_detection_buffer_size];
|
|
||||||
|
|
||||||
_timeout = _preferences->getInt(preference_presence_detection_timeout) * 1000;
|
_timeout = _preferences->getInt(preference_presence_detection_timeout) * 1000;
|
||||||
if(_timeout == 0)
|
if(_timeout == 0)
|
||||||
{
|
{
|
||||||
@@ -41,7 +42,7 @@ void PresenceDetection::update()
|
|||||||
delay(3000);
|
delay(3000);
|
||||||
|
|
||||||
if(_timeout < 0) return;
|
if(_timeout < 0) return;
|
||||||
memset(_csv, 0, presence_detection_buffer_size);
|
memset(_csv, 0, _bufferSize);
|
||||||
|
|
||||||
if(_devices.size() == 0)
|
if(_devices.size() == 0)
|
||||||
{
|
{
|
||||||
@@ -60,7 +61,7 @@ void PresenceDetection::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prevent csv buffer overflow
|
// Prevent csv buffer overflow
|
||||||
if(_csvIndex > presence_detection_buffer_size - (sizeof(it.second.name) + sizeof(it.second.address) + 10))
|
if(_csvIndex > _bufferSize - (sizeof(it.second.name) + sizeof(it.second.address) + 10))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,10 @@ struct PdDevice
|
|||||||
bool hasRssi = false;
|
bool hasRssi = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define presence_detection_buffer_size 4096
|
|
||||||
|
|
||||||
class PresenceDetection : public BleScanner::Subscriber
|
class PresenceDetection : public BleScanner::Subscriber
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PresenceDetection(Preferences* preferences, BleScanner::Scanner* bleScanner, Network* network);
|
PresenceDetection(Preferences* preferences, BleScanner::Scanner* bleScanner, Network* network, char* buffer, size_t bufferSize);
|
||||||
virtual ~PresenceDetection();
|
virtual ~PresenceDetection();
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
@@ -33,6 +31,7 @@ private:
|
|||||||
BleScanner::Scanner* _bleScanner;
|
BleScanner::Scanner* _bleScanner;
|
||||||
Network* _network;
|
Network* _network;
|
||||||
char* _csv = {0};
|
char* _csv = {0};
|
||||||
|
size_t _bufferSize = 0;
|
||||||
std::map<long long, PdDevice> _devices;
|
std::map<long long, PdDevice> _devices;
|
||||||
int _timeout = 20000;
|
int _timeout = 20000;
|
||||||
int _csvIndex = 0;
|
int _csvIndex = 0;
|
||||||
|
|||||||
7
main.cpp
7
main.cpp
@@ -13,6 +13,7 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "RestartReason.h"
|
#include "RestartReason.h"
|
||||||
|
#include "CharBuffer.h"
|
||||||
|
|
||||||
Network* network = nullptr;
|
Network* network = nullptr;
|
||||||
NetworkLock* networkLock = nullptr;
|
NetworkLock* networkLock = nullptr;
|
||||||
@@ -170,6 +171,8 @@ void setup()
|
|||||||
bool firstStart = initPreferences();
|
bool firstStart = initPreferences();
|
||||||
initializeRestartReason();
|
initializeRestartReason();
|
||||||
|
|
||||||
|
CharBuffer::initialize();
|
||||||
|
|
||||||
if(preferences->getInt(preference_restart_timer) > 0)
|
if(preferences->getInt(preference_restart_timer) > 0)
|
||||||
{
|
{
|
||||||
restartTs = preferences->getInt(preference_restart_timer) * 60 * 1000;
|
restartTs = preferences->getInt(preference_restart_timer) * 60 * 1000;
|
||||||
@@ -182,7 +185,7 @@ void setup()
|
|||||||
network = new Network(preferences, mqttLockPath);
|
network = new Network(preferences, mqttLockPath);
|
||||||
network->initialize();
|
network->initialize();
|
||||||
|
|
||||||
networkLock = new NetworkLock(network, preferences);
|
networkLock = new NetworkLock(network, preferences, CharBuffer::get(), CHAR_BUFFER_SIZE);
|
||||||
networkLock->initialize();
|
networkLock->initialize();
|
||||||
|
|
||||||
if(openerEnabled)
|
if(openerEnabled)
|
||||||
@@ -226,7 +229,7 @@ void setup()
|
|||||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, ethServer, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi);
|
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, ethServer, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi);
|
||||||
webCfgServer->initialize();
|
webCfgServer->initialize();
|
||||||
|
|
||||||
presenceDetection = new PresenceDetection(preferences, bleScanner, network);
|
presenceDetection = new PresenceDetection(preferences, bleScanner, network, CharBuffer::get(), CHAR_BUFFER_SIZE);
|
||||||
presenceDetection->initialize();
|
presenceDetection->initialize();
|
||||||
|
|
||||||
setupTasks();
|
setupTasks();
|
||||||
|
|||||||
Reference in New Issue
Block a user