Skip to content

Commit

Permalink
Fix detection of THX1 thermometers
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Oct 27, 2022
1 parent f5f54e8 commit c1c6b8e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ bool DeviceManager::isBleDeviceBlacklisted(const QString &addr)

void DeviceManager::addBleDevice(const QBluetoothDeviceInfo &info)
{
//qDebug() << "DeviceManager::addBleDevice()" << " > NAME" << info.name() << " > RSSI" << info.rssi();
qDebug() << "DeviceManager::addBleDevice()" << " > NAME" << info.name() << " > RSSI" << info.rssi();

// Various sanity checks
{
Expand Down
27 changes: 18 additions & 9 deletions src/DeviceManager_advertisement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
Q_UNUSED(updatedFields) // We don't use QBluetoothDeviceInfo::Fields, it's unreliable

if (info.rssi() >= 0) return; // we probably just hit the device cache
//if (info.isCached()) return; // we probably just hit the device cache
if ((info.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) == false) return; // not a BLE device
if (m_devices_blacklist.contains(info.address().toString())) return; // device is blacklisted
//if (info.name().isEmpty()) return; // skip beacons
if (info.name().replace('-', ':') == info.address().toString()) return; // skip beacons

for (auto d: qAsConst(m_devices_model->m_devices)) // KNOWN DEVICES ////////
{
Expand All @@ -72,7 +69,7 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
{
//qDebug() << info.name() << info.address() << Qt::hex
// << "ID" << id
// << "manufacturer data" << Qt::dec << info.manufacturerData(id).count() << Qt::hex
// << "manufacturer data" << Qt::dec << info.manufacturerData(id).size() << Qt::hex
// << "bytes:" << info.manufacturerData(id).toHex();

dd->parseAdvertisementData(DeviceUtils::BLE_ADV_MANUFACTURERDATA,
Expand Down Expand Up @@ -118,7 +115,7 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
{
//std::string input;
//serializeJson(doc, input);
//qDebug() << "input :" << input.c_str();
//qDebug() << "decodeBLEJson(mfd1) error:" << input.c_str();
}
}

Expand All @@ -127,7 +124,7 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
{
//qDebug() << info.name() << info.address() << Qt::hex
// << "ID" << id
// << "service data" << Qt::dec << info.serviceData(id).count() << Qt::hex
// << "service data" << Qt::dec << info.serviceData(id).size() << Qt::hex
// << "bytes:" << info.serviceData(id).toHex();

dd->parseAdvertisementData(DeviceUtils::BLE_ADV_MANUFACTURERDATA,
Expand Down Expand Up @@ -175,7 +172,7 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
{
//std::string input;
//serializeJson(doc, input);
//qDebug() << "input :" << input.c_str();
//qDebug() << "decodeBLEJson(svd1) error:" << input.c_str();
}
}

Expand Down Expand Up @@ -225,7 +222,7 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,
{
//qDebug() << info.name() << info.address() << Qt::hex
// << "ID" << id
// << "manufacturer data" << Qt::dec << info.manufacturerData(id).count() << Qt::hex
// << "manufacturer data" << Qt::dec << info.manufacturerData(id).size() << Qt::hex
// << "bytes:" << info.manufacturerData(id).toHex();

ArduinoJson::DynamicJsonDocument doc(2048);
Expand Down Expand Up @@ -255,14 +252,20 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,

status = true;
}
else
{
//std::string input;
//serializeJson(doc, input);
//qDebug() << "decodeBLEJson(mfd2) error:" << input.c_str();
}
}

const QList<QBluetoothUuid> &serviceIds = info.serviceIds();
for (const auto id: serviceIds)
{
//qDebug() << info.name() << info.address() << Qt::hex
// << "ID" << id
// << "service data" << Qt::dec << info.serviceData(id).count() << Qt::hex
// << "service data" << Qt::dec << info.serviceData(id).size() << Qt::hex
// << "bytes:" << info.serviceData(id).toHex();

ArduinoJson::DynamicJsonDocument doc(2048);
Expand Down Expand Up @@ -294,6 +297,12 @@ void DeviceManager::updateBleDevice(const QBluetoothDeviceInfo &info,

status = true;
}
else
{
//std::string input;
//serializeJson(doc, input);
//qDebug() << "decodeBLEJson(svd2) error:" << input.c_str();
}
}
}

Expand Down
36 changes: 26 additions & 10 deletions src/DeviceManager_theengs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "device_theengs.h"
#include "devices/device_theengs_generic.h"
#include "devices/device_theengs_beacons.h"
#include "devices/device_theengs_probes.h"
#include "devices/device_theengs_scales.h"
#include "devices/device_theengs_motionsensors.h"
Expand All @@ -41,13 +40,14 @@
#include <QList>
#include <QDebug>

/* ************************************************************************** */
/* ************************************************************************** */

Device * DeviceManager::createTheengsDevice_fromDb(const QString &deviceName,
const QString &deviceModel_theengs,
const QString &deviceAddr)
{
//qDebug() << "createTheengsDevice_fromDb(" << deviceName << "/" << deviceModel_theengs << "/" << deviceAddr << ")";
qDebug() << "createTheengsDevice_fromDb(" << deviceName << "/" << deviceModel_theengs << "/" << deviceAddr << ")";

DeviceTheengs *device = nullptr;

Expand Down Expand Up @@ -144,9 +144,11 @@ Device * DeviceManager::createTheengsDevice_fromDb(const QString &deviceName,
return device;
}

/* ************************************************************************** */

Device * DeviceManager::createTheengsDevice_fromAdv(const QBluetoothDeviceInfo &deviceInfo)
{
//qDebug() << "createTheengsDevice_fromAdv(" << deviceInfo.name() << ")";
qDebug() << "createTheengsDevice_fromAdv(" << deviceInfo.name() << ")";

DeviceTheengs *device = nullptr;

Expand All @@ -173,13 +175,19 @@ Device * DeviceManager::createTheengsDevice_fromAdv(const QBluetoothDeviceInfo &
device_modelid_theengs = QString::fromStdString(doc["model_id"]);
device_props = QString::fromUtf8(dec.getTheengProperties(device_modelid_theengs.toLocal8Bit()));

if (device_model_theengs == "IBEACON" && device_modelid_theengs == "IBEACON") continue;
if (device_model_theengs == "MS-CDP" && device_modelid_theengs == "MS-CDP") continue;
if (device_model_theengs == "GAEN" && device_modelid_theengs == "GAEN") continue;
if (device_modelid_theengs == "IBEACON") continue;
if (device_modelid_theengs == "MS-CDP") continue;
if (device_modelid_theengs == "GAEN") continue;

qDebug() << "addDevice() FOUND [mfd] :" << device_model_theengs << device_modelid_theengs << device_props;
break;
}
else
{
std::string input;
serializeJson(doc, input);
qDebug() << "decodeBLEJson(mfd_add) error:" << input.c_str();
}
}

const QList<QBluetoothUuid> &serviceIds = deviceInfo.serviceIds();
Expand All @@ -191,7 +199,7 @@ Device * DeviceManager::createTheengsDevice_fromAdv(const QBluetoothDeviceInfo &
doc["id"] = deviceInfo.address().toString().toStdString();
doc["name"] = deviceInfo.name().toStdString();
doc["servicedata"] = deviceInfo.serviceData(id).toHex().toStdString();
doc["servicedatauuid"] = id.toString(QUuid::Id128).toStdString();
doc["servicedatauuid"] = QByteArray::number(id.toUInt16(), 16).rightJustified(4, '0').toStdString();

TheengsDecoder dec;
ArduinoJson::JsonObject obj = doc.as<ArduinoJson::JsonObject>();
Expand All @@ -202,13 +210,19 @@ Device * DeviceManager::createTheengsDevice_fromAdv(const QBluetoothDeviceInfo &
device_modelid_theengs = QString::fromStdString(doc["model_id"]);
device_props = QString::fromUtf8(dec.getTheengProperties(device_modelid_theengs.toLocal8Bit()));

if (device_model_theengs == "IBEACON" && device_modelid_theengs == "IBEACON") continue;
if (device_model_theengs == "MS-CDP" && device_modelid_theengs == "MS-CDP") continue;
if (device_model_theengs == "GAEN" && device_modelid_theengs == "GAEN") continue;
if (device_modelid_theengs == "IBEACON") continue;
if (device_modelid_theengs == "MS-CDP") continue;
if (device_modelid_theengs == "GAEN") continue;

qDebug() << "addDevice() FOUND [svd] :" << device_model_theengs << device_modelid_theengs << device_props;
break;
}
else
{
std::string input;
serializeJson(doc, input);
qDebug() << "decodeBLEJson(svd_add) error:" << input.c_str();
}
}

if ((!device_modelid_theengs.isEmpty() && !device_props.isEmpty()))
Expand Down Expand Up @@ -307,6 +321,8 @@ Device * DeviceManager::createTheengsDevice_fromAdv(const QBluetoothDeviceInfo &
return device;
}

/* ************************************************************************** */

QString DeviceManager::getDeviceModelIdTheengs_fromAdv(const QBluetoothDeviceInfo &deviceInfo)
{
//qDebug() << "getDeviceModelIdTheengs_fromAdv(" << deviceInfo.name() << ")";
Expand Down

0 comments on commit c1c6b8e

Please sign in to comment.