Skip to content

Commit

Permalink
support presence detection for HA app: Catch minor id 40004
Browse files Browse the repository at this point in the history
  • Loading branch information
technyon committed Dec 30, 2023
1 parent 060d82e commit 8314a50
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Config.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions PreferencesKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? "" : "***";
}
Expand Down
23 changes: 23 additions & 0 deletions PresenceDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "PreferencesKeys.h"
#include "Logger.h"
#include "CharBuffer.h"
#include <NimBLEDevice.h>
#include <NimBLEAdvertisedDevice.h>
#include "NimBLEBeacon.h"
#include "NukiUtils.h"

PresenceDetection::PresenceDetection(Preferences* preferences, BleScanner::Scanner *bleScanner, Network* network, char* buffer, size_t bufferSize)
: _preferences(preferences),
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 8314a50

Please sign in to comment.