add auto discovery for keypad result
This commit is contained in:
@@ -43,6 +43,7 @@ include_directories(${PROJECT_NAME}
|
||||
set(SRCFILES
|
||||
Pins.h
|
||||
Config.h
|
||||
CharBuffer.cpp
|
||||
Network.cpp
|
||||
MqttReceiver.h
|
||||
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",
|
||||
"",
|
||||
{ { "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)
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
void publishHASSConfigLedBrightness(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 publishHASSConfigKeypadAttemptInfo(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 removeHASSConfig(char* uidString);
|
||||
|
||||
@@ -5,10 +5,14 @@
|
||||
#include "PreferencesKeys.h"
|
||||
#include "Logger.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),
|
||||
_preferences(preferences)
|
||||
_preferences(preferences),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
{
|
||||
_configTopics.reserve(5);
|
||||
_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)
|
||||
{
|
||||
char str[50];
|
||||
@@ -283,7 +286,7 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
|
||||
char authName[33];
|
||||
memset(authName, 0, sizeof(authName));
|
||||
|
||||
String json = "[\n";
|
||||
DynamicJsonDocument json(_bufferSize);
|
||||
|
||||
for(const auto& log : logEntries)
|
||||
{
|
||||
@@ -294,90 +297,75 @@ void NetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntry>&
|
||||
memcpy(authName, log.name, sizeof(log.name));
|
||||
}
|
||||
|
||||
json.concat("{\n");
|
||||
auto entry = json.add();
|
||||
|
||||
json.concat("\"index\": "); json.concat(log.index); json.concat(",\n");
|
||||
json.concat("\"authorizationId\": "); json.concat(log.authId); json.concat(",\n");
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
memcpy(str, log.name, sizeof(log.name));
|
||||
json.concat("\"authorizationName\": \""); json.concat(str); json.concat("\",\n");
|
||||
|
||||
json.concat("\"timeYear\": "); json.concat(log.timeStampYear); json.concat(",\n");
|
||||
json.concat("\"timeMonth\": "); json.concat(log.timeStampMonth); json.concat(",\n");
|
||||
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");
|
||||
entry["index"] = log.index;
|
||||
entry["authorizationId"] = log.authId;
|
||||
entry["authorizationName"] = log.name;
|
||||
entry["timeYear"] = log.timeStampYear;
|
||||
entry["timeMonth"] = log.timeStampMonth;
|
||||
entry["timeDay"] = log.timeStampDay;
|
||||
entry["timeHour"] = log.timeStampHour;
|
||||
entry["timeMinute"] = log.timeStampMinute;
|
||||
entry["timeSecond"] = log.timeStampSecond;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
loggingTypeToString(log.loggingType, str);
|
||||
json.concat("\"type\": \""); json.concat(str); json.concat("\",\n");
|
||||
entry["type"] = str;
|
||||
|
||||
switch(log.loggingType)
|
||||
{
|
||||
case NukiLock::LoggingType::LockAction:
|
||||
memset(str, 0, sizeof(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));
|
||||
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));
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
||||
entry["completionStatus"] = str;
|
||||
break;
|
||||
case NukiLock::LoggingType::KeypadAction:
|
||||
memset(str, 0, sizeof(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));
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
||||
entry["completionStatus"] = str;
|
||||
break;
|
||||
case NukiLock::LoggingType::DoorSensor:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
json.concat("\"action\": \"");
|
||||
|
||||
switch(log.data[0])
|
||||
{
|
||||
case 0:
|
||||
json.concat("DoorOpened");
|
||||
entry["action"] = "DoorOpened";
|
||||
break;
|
||||
case 1:
|
||||
json.concat("DoorClosed");
|
||||
entry["action"] = "DoorClosed";
|
||||
break;
|
||||
case 2:
|
||||
json.concat("SensorJammed");
|
||||
entry["action"] = "SensorJammed";
|
||||
break;
|
||||
default:
|
||||
json.concat("Unknown");
|
||||
entry["action"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
json.concat("\",\n");
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
||||
entry["completionStatus"] = str;
|
||||
break;
|
||||
}
|
||||
|
||||
json.concat("}");
|
||||
if(&log == &logEntries.back())
|
||||
{
|
||||
json.concat("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
json.concat(",\n");
|
||||
}
|
||||
}
|
||||
|
||||
json.concat("]");
|
||||
publishString(mqtt_topic_lock_log, json);
|
||||
serializeJson(json, reinterpret_cast<char(&)[CHAR_BUFFER_SIZE]>(*_buffer));
|
||||
publishString(mqtt_topic_lock_log, _buffer);
|
||||
|
||||
if(authFound)
|
||||
{
|
||||
@@ -540,6 +528,15 @@ void NetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic, cha
|
||||
{
|
||||
_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)
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
#include "Network.h"
|
||||
#include "QueryCommand.h"
|
||||
|
||||
#define LOCK_LOG_JSON_BUFFER_SIZE 2048
|
||||
|
||||
class NetworkLock : public MqttReceiver
|
||||
{
|
||||
public:
|
||||
explicit NetworkLock(Network* network, Preferences* preferences);
|
||||
explicit NetworkLock(Network* network, Preferences* preferences, char* buffer, size_t bufferSize);
|
||||
virtual ~NetworkLock();
|
||||
|
||||
void initialize();
|
||||
@@ -79,6 +81,9 @@ private:
|
||||
int _keypadCommandEnabled = 1;
|
||||
uint8_t _queryCommands = 0;
|
||||
|
||||
char* _buffer;
|
||||
size_t _bufferSize;
|
||||
|
||||
bool (*_lockActionReceivedCallback)(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;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "PreferencesKeys.h"
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
NetworkOpener::NetworkOpener(Network* network, Preferences* preferences)
|
||||
: _preferences(preferences),
|
||||
@@ -268,130 +269,114 @@ void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntr
|
||||
char authName[33];
|
||||
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)
|
||||
{
|
||||
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;
|
||||
authId = log.authId;
|
||||
memcpy(authName, log.name, sizeof(log.name));
|
||||
}
|
||||
|
||||
json.concat("{\n");
|
||||
auto entry = json.add();
|
||||
|
||||
json.concat("\"index\": "); json.concat(log.index); json.concat(",\n");
|
||||
json.concat("\"authorizationId\": "); json.concat(log.authId); json.concat(",\n");
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
memcpy(str, log.name, sizeof(log.name));
|
||||
json.concat("\"authorizationName\": \""); json.concat(str); json.concat("\",\n");
|
||||
|
||||
json.concat("\"timeYear\": "); json.concat(log.timeStampYear); json.concat(",\n");
|
||||
json.concat("\"timeMonth\": "); json.concat(log.timeStampMonth); json.concat(",\n");
|
||||
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");
|
||||
entry["index"] = log.index;
|
||||
entry["authorizationId"] = log.authId;
|
||||
entry["authorizationName"] = log.name;
|
||||
entry["timeYear"] = log.timeStampYear;
|
||||
entry["timeMonth"] = log.timeStampMonth;
|
||||
entry["timeDay"] = log.timeStampDay;
|
||||
entry["timeHour"] = log.timeStampHour;
|
||||
entry["timeMinute"] = log.timeStampMinute;
|
||||
entry["timeSecond"] = log.timeStampSecond;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
loggingTypeToString(log.loggingType, str);
|
||||
json.concat("\"type\": \""); json.concat(str); json.concat("\",\n");
|
||||
entry["type"] = str;
|
||||
|
||||
switch(log.loggingType)
|
||||
{
|
||||
case NukiOpener::LoggingType::LockAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
lockactionToString((NukiOpener::LockAction)log.data[0], str);
|
||||
json.concat("\"action\": \""); json.concat(str); json.concat("\",\n");
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
triggerToString((NukiOpener::Trigger)log.data[1], str);
|
||||
json.concat("\"trigger\": \""); json.concat(str); json.concat("\",\n");
|
||||
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
|
||||
entry["trigger"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
logactionCompletionStatusToString(log.data[3], str);
|
||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
||||
entry["completionStatus"] = str;
|
||||
break;
|
||||
case NukiOpener::LoggingType::KeypadAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
lockactionToString((NukiOpener::LockAction)log.data[0], str);
|
||||
json.concat("\"action\": \""); json.concat(str); json.concat("\",\n");
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
completionStatusToString((NukiOpener::CompletionStatus)log.data[2], str);
|
||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||
entry["completionStatus"] = str;
|
||||
break;
|
||||
case NukiOpener::LoggingType::DoorbellRecognition:
|
||||
json.concat("\"mode\": \"");
|
||||
switch(log.data[0] & 3)
|
||||
{
|
||||
case 0:
|
||||
json.concat("None");
|
||||
entry["mode"] = "None";
|
||||
break;
|
||||
case 1:
|
||||
json.concat("RTO");
|
||||
entry["mode"] = "RTO";
|
||||
break;
|
||||
case 2:
|
||||
json.concat("CM");
|
||||
entry["mode"] = "CM";
|
||||
break;
|
||||
default:
|
||||
json.concat("Unknown");
|
||||
entry["mode"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
json.concat("\",\n");
|
||||
|
||||
json.concat("\"source\": \"");
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
json.concat("Doorbell");
|
||||
entry["source"] = "Doorbell";
|
||||
break;
|
||||
case 1:
|
||||
json.concat("Timecontrol");
|
||||
entry["source"] = "Timecontrol";
|
||||
break;
|
||||
case 2:
|
||||
json.concat("App");
|
||||
entry["source"] = "App";
|
||||
break;
|
||||
case 3:
|
||||
json.concat("Button");
|
||||
entry["source"] = "Button";
|
||||
break;
|
||||
case 4:
|
||||
json.concat("Fob");
|
||||
entry["source"] = "Fob";
|
||||
break;
|
||||
case 5:
|
||||
json.concat("Bridge");
|
||||
entry["source"] = "Bridge";
|
||||
break;
|
||||
case 6:
|
||||
json.concat("Keypad");
|
||||
entry["source"] = "Keypad";
|
||||
break;
|
||||
}
|
||||
json.concat("\",\n");
|
||||
default:
|
||||
entry["source"] = "Unknown";
|
||||
break; }
|
||||
|
||||
json.concat("\"geofence\": \""); json.concat(log.data[2] == 1 ? "active" : "inactive"); json.concat("\",\n");
|
||||
json.concat("\"doorbellSuppression\": \""); json.concat(log.data[3] == 1 ? "active" : "inactive"); json.concat("\",\n");
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
logactionCompletionStatusToString(log.data[5], str);
|
||||
json.concat("\"completionStatus\": \""); json.concat(str); json.concat("\"\n");
|
||||
entry["geofence"] = log.data[2] == 1 ? "active" : "inactive";
|
||||
entry["doorbellSuppression"] = log.data[3] == 1 ? "active" : "inactive";
|
||||
entry["completionStatus"] = str;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
json.concat("}");
|
||||
if(&log == &logEntries.back())
|
||||
{
|
||||
json.concat("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
json.concat(",\n");
|
||||
}
|
||||
}
|
||||
|
||||
json.concat("]");
|
||||
publishString(mqtt_topic_lock_log, json);
|
||||
serializeJson(json, reinterpret_cast<char(&)[OPENER_LOG_JSON_BUFFER_SIZE]>(*jsonOut));
|
||||
publishString(mqtt_topic_lock_log, jsonOut);
|
||||
|
||||
delete jsonOut;
|
||||
|
||||
if(authFound)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "NukiOpenerConstants.h"
|
||||
#include "NetworkLock.h"
|
||||
|
||||
#define OPENER_LOG_JSON_BUFFER_SIZE 2048
|
||||
|
||||
class NetworkOpener : public MqttReceiver
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -646,7 +646,7 @@ void NukiOpenerWrapper::setupHASS()
|
||||
String baseTopic = _preferences->getString(preference_mqtt_opener_path);
|
||||
char uidString[20];
|
||||
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;
|
||||
|
||||
Log->println("HASS setup for opener completed.");
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "PresenceDetection.h"
|
||||
#include "PreferencesKeys.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),
|
||||
_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;
|
||||
if(_timeout == 0)
|
||||
{
|
||||
@@ -41,7 +42,7 @@ void PresenceDetection::update()
|
||||
delay(3000);
|
||||
|
||||
if(_timeout < 0) return;
|
||||
memset(_csv, 0, presence_detection_buffer_size);
|
||||
memset(_csv, 0, _bufferSize);
|
||||
|
||||
if(_devices.size() == 0)
|
||||
{
|
||||
@@ -60,7 +61,7 @@ void PresenceDetection::update()
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,10 @@ struct PdDevice
|
||||
bool hasRssi = false;
|
||||
};
|
||||
|
||||
#define presence_detection_buffer_size 4096
|
||||
|
||||
class PresenceDetection : public BleScanner::Subscriber
|
||||
{
|
||||
public:
|
||||
PresenceDetection(Preferences* preferences, BleScanner::Scanner* bleScanner, Network* network);
|
||||
PresenceDetection(Preferences* preferences, BleScanner::Scanner* bleScanner, Network* network, char* buffer, size_t bufferSize);
|
||||
virtual ~PresenceDetection();
|
||||
|
||||
void initialize();
|
||||
@@ -33,6 +31,7 @@ private:
|
||||
BleScanner::Scanner* _bleScanner;
|
||||
Network* _network;
|
||||
char* _csv = {0};
|
||||
size_t _bufferSize = 0;
|
||||
std::map<long long, PdDevice> _devices;
|
||||
int _timeout = 20000;
|
||||
int _csvIndex = 0;
|
||||
|
||||
7
main.cpp
7
main.cpp
@@ -13,6 +13,7 @@
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include "RestartReason.h"
|
||||
#include "CharBuffer.h"
|
||||
|
||||
Network* network = nullptr;
|
||||
NetworkLock* networkLock = nullptr;
|
||||
@@ -170,6 +171,8 @@ void setup()
|
||||
bool firstStart = initPreferences();
|
||||
initializeRestartReason();
|
||||
|
||||
CharBuffer::initialize();
|
||||
|
||||
if(preferences->getInt(preference_restart_timer) > 0)
|
||||
{
|
||||
restartTs = preferences->getInt(preference_restart_timer) * 60 * 1000;
|
||||
@@ -182,7 +185,7 @@ void setup()
|
||||
network = new Network(preferences, mqttLockPath);
|
||||
network->initialize();
|
||||
|
||||
networkLock = new NetworkLock(network, preferences);
|
||||
networkLock = new NetworkLock(network, preferences, CharBuffer::get(), CHAR_BUFFER_SIZE);
|
||||
networkLock->initialize();
|
||||
|
||||
if(openerEnabled)
|
||||
@@ -226,7 +229,7 @@ void setup()
|
||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, ethServer, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi);
|
||||
webCfgServer->initialize();
|
||||
|
||||
presenceDetection = new PresenceDetection(preferences, bleScanner, network);
|
||||
presenceDetection = new PresenceDetection(preferences, bleScanner, network, CharBuffer::get(), CHAR_BUFFER_SIZE);
|
||||
presenceDetection->initialize();
|
||||
|
||||
setupTasks();
|
||||
|
||||
Reference in New Issue
Block a user