Improve room assistant detection (#268)

This commit is contained in:
Darrell 2022-02-14 13:04:41 -05:00 committed by GitHub
parent 5bb652c858
commit 69bf3b1e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 15 deletions

View File

@ -456,20 +456,12 @@ bool BleFingerprint::query()
pClient->setConnectTimeout(5); pClient->setConnectTimeout(5);
if (pClient->connect(address)) if (pClient->connect(address))
{ {
if (rmAsst) bool iphone = true;
{ if (allowQuery)
auto sRmAst = pClient->getValue(roomAssistantService, rootAssistantCharacteristic);
if (!sRmAst.empty())
{
setId(String("roomAssistant:") + kebabify(sRmAst).c_str(), ID_TYPE_RM_ASST);
Serial.printf("%d RmAst | MAC: %s, ID: %-60s %s\n", xPortGetCoreID(), getMac().c_str(), getId().c_str(), sRmAst.c_str());
success = true;
}
}
else if (allowQuery)
{ {
auto sMdl = pClient->getValue(deviceInformationService, modelChar); auto sMdl = pClient->getValue(deviceInformationService, modelChar);
auto sName = pClient->getValue(genericAccessService, nameChar); auto sName = pClient->getValue(genericAccessService, nameChar);
iphone = sMdl.find("iPhone") == 0;
if (!sName.empty() && !sMdl.empty() && sMdl.find(sName) == std::string::npos && sName.compare("Apple Watch") != 0) if (!sName.empty() && !sMdl.empty() && sMdl.find(sName) == std::string::npos && sName.compare("Apple Watch") != 0)
{ {
Serial.printf("%d Name | MAC: %s, ID: %-60s %s\n", xPortGetCoreID(), getMac().c_str(), getId().c_str(), sName.c_str()); Serial.printf("%d Name | MAC: %s, ID: %-60s %s\n", xPortGetCoreID(), getMac().c_str(), getId().c_str(), sName.c_str());
@ -488,6 +480,18 @@ bool BleFingerprint::query()
if (name.isEmpty()) name = sName.c_str(); if (name.isEmpty()) name = sName.c_str();
} }
} }
if (rmAsst || iphone) // For some reason we often don't get room asssistants service advertisement
{
auto sRmAst = pClient->getValue(roomAssistantService, rootAssistantCharacteristic);
if (!sRmAst.empty())
{
setId(String("roomAssistant:") + kebabify(sRmAst).c_str(), ID_TYPE_RM_ASST);
Serial.printf("%d RmAst | MAC: %s, ID: %-60s %s\n", xPortGetCoreID(), getMac().c_str(), getId().c_str(), sRmAst.c_str());
success = true;
}
}
} }
NimBLEDevice::deleteClient(pClient); NimBLEDevice::deleteClient(pClient);

View File

@ -72,6 +72,7 @@ public:
long getAge() { return millis() - lastSeenMillis; }; long getAge() { return millis() - lastSeenMillis; };
bool getIgnore() { return ignore; }; bool getIgnore() { return ignore; };
bool getAllowQuery() { return allowQuery; }; bool getAllowQuery() { return allowQuery; };
bool getRmAsst() { return rmAsst; };
int getSeenCount() int getSeenCount()
{ {
auto sc = seenCount; auto sc = seenCount;

View File

@ -87,10 +87,7 @@ void GUI::connected(bool wifi = false, bool mqtt = false)
void GUI::added(BleFingerprint *f) void GUI::added(BleFingerprint *f)
{ {
if (f->getIgnore()) return; if (f->getIgnore()) return;
if (f->getAllowQuery()) Serial.printf("%d New %s | MAC: %s, ID: %-60s %s\n", xPortGetCoreID(), f->getRmAsst() ? "R" : (f->getAllowQuery() ? "Q" : " "), f->getMac().c_str(), f->getId().c_str(), f->getDiscriminator().c_str());
Serial.printf("%d New Q | MAC: %s, ID: %-60s %s\n", xPortGetCoreID(), f->getMac().c_str(), f->getId().c_str(), f->getDiscriminator().c_str());
else
Serial.printf("%d New | MAC: %s, ID: %-60s %s\n", xPortGetCoreID(), f->getMac().c_str(), f->getId().c_str(), f->getDiscriminator().c_str());
} }
void GUI::removed(BleFingerprint *f, long age) void GUI::removed(BleFingerprint *f, long age)