From 8314a507fab4f695e898f04cbeb09eb8b0040c95 Mon Sep 17 00:00:00 2001 From: technyon Date: Sat, 30 Dec 2023 04:57:10 +0100 Subject: [PATCH] support presence detection for HA app: Catch minor id 40004 --- Config.h | 2 +- PreferencesKeys.h | 4 ++-- PresenceDetection.cpp | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Config.h b/Config.h index 6fcddd46..aec09983 100644 --- a/Config.h +++ b/Config.h @@ -1,6 +1,6 @@ #pragma once -#define NUKI_HUB_VERSION "8.28" +#define NUKI_HUB_VERSION "8.29-pre-1" #define MQTT_QOS_LEVEL 1 #define MQTT_CLEAN_SESSIONS false diff --git a/PreferencesKeys.h b/PreferencesKeys.h index a620e6f5..9bd0c94d 100644 --- a/PreferencesKeys.h +++ b/PreferencesKeys.h @@ -96,11 +96,11 @@ class DebugPreferences { return s == "" ? "" : "***"; } - const String redact(const int i) const + const String redact(const int32_t i) const { return i == 0 ? "" : "***"; } - const String redact(const uint i) const + const String redact(const uint32_t i) const { return i == 0 ? "" : "***"; } diff --git a/PresenceDetection.cpp b/PresenceDetection.cpp index 45a87023..6f702d59 100644 --- a/PresenceDetection.cpp +++ b/PresenceDetection.cpp @@ -2,6 +2,10 @@ #include "PreferencesKeys.h" #include "Logger.h" #include "CharBuffer.h" +#include +#include +#include "NimBLEBeacon.h" +#include "NukiUtils.h" PresenceDetection::PresenceDetection(Preferences* preferences, BleScanner::Scanner *bleScanner, Network* network, char* buffer, size_t bufferSize) : _preferences(preferences), @@ -173,6 +177,25 @@ void PresenceDetection::onResult(NimBLEAdvertisedDevice *device) _devices[addr] = pdDevice; } + else if (device->haveManufacturerData()) + { + std::string strManufacturerData = device->getManufacturerData(); + + uint8_t cManufacturerData[100]; + strManufacturerData.copy((char *)cManufacturerData, std::min(strManufacturerData.length(), sizeof(cManufacturerData)), 0); + + if (strManufacturerData.length() == 25 && cManufacturerData[0] == 0x4C && cManufacturerData[1] == 0x00) + { + BLEBeacon oBeacon = BLEBeacon(); + oBeacon.setData(strManufacturerData); + + if(ENDIAN_CHANGE_U16(oBeacon.getMinor()) == 40004) + { + pdDevice.timestamp = millis(); + _devices[addr] = pdDevice; + } + } + } } else {