diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 98e922cf0e..14dd8221ff 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -402,17 +402,18 @@ void updateDevicesStatus() { for (vector::iterator it = devices.begin(); it != devices.end(); ++it) { BLEdevice* p = *it; unsigned long now = millis(); + // Check for tracker status + bool isTracker = false; + std::string tag = decoder.getTheengAttribute(p->sensorModel_id, "tag"); + if (tag.length() >= 3) { + uint8_t data = getBinaryData(tag[3]); + if (((data >> 3) & 0x01) == 1) { + isTracker = true; + Log.notice(F("Is Device Tracker for offline evaluation" CR)); + } + } // Device tracker devices - if (BTConfig.presenceEnable && (p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::NUT || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::NUTALE || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::MIBAND || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::TAGIT || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::TILE || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::TILEN || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::ITAG || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::BM2 || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::RUUVITAG_RAWV1 || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::RUUVITAG_RAWV2)) { // We apply the offline status only for tracking device, can be extended further to all the devices + if (isTracker) { // We apply the offline status only for tracking device, can be extended further to all the devices if ((p->lastUpdate != 0) && (p->lastUpdate < (now - BTConfig.presenceAwayTimer) && (now > BTConfig.presenceAwayTimer)) && (BTConfig.ignoreWBlist || ((!oneWhite || isWhite(p)) && !isBlack(p)))) { // Only if WBlist is disabled OR ((no white MAC OR this MAC is white) AND not a black listed MAC)) { StaticJsonDocument BLEdataBuffer; @@ -587,6 +588,16 @@ std::string convertServiceData(std::string deviceServiceData) { return spr; } +uint8_t getBinaryData(char ch) { + uint8_t data = 0; + if (ch >= '0' && ch <= '9') + data = ch - '0'; + else if (ch >= 'a' && ch <= 'f') + data = 10 + (ch - 'a'); + + return data; +} + void procBLETask(void* pvParameters) { BLEAdvertisedDevice* advertisedDevice = nullptr; @@ -971,20 +982,24 @@ void launchBTDiscovery(bool overrideDiscovery) { std::string brand = decoder.getTheengAttribute(p->sensorModel_id, "brand"); std::string model = decoder.getTheengAttribute(p->sensorModel_id, "model"); std::string model_id = decoder.getTheengAttribute(p->sensorModel_id, "model_id"); + + // Check for tracker status + bool isTracker = false; + std::string tag = decoder.getTheengAttribute(p->sensorModel_id, "tag"); + if (tag.length() >= 3) { + uint8_t data = getBinaryData(tag[3]); + if (((data >> 3) & 0x01) == 1) { + isTracker = true; + Log.notice(F("Is Device Tracker for discovery" CR)); + } + } + String discovery_topic = String(subjectBTtoMQTT) + "/" + macWOdots; if (!BTConfig.extDecoderEnable && // Do not decode if an external decoder is configured p->sensorModel_id > TheengsDecoder::BLE_ID_NUM::UNKNOWN_MODEL && p->sensorModel_id < TheengsDecoder::BLE_ID_NUM::BLE_ID_MAX && p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::HHCCJCY01HHCC && p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::BM2) { // Exception on HHCCJCY01HHCC and BM2 as these ones are discoverable and connectable - if (p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::NUT || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::NUTALE || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::MIBAND || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::TAGIT || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::TILE || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::TILEN || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::ITAG || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::RUUVITAG_RAWV1 || - p->sensorModel_id == TheengsDecoder::BLE_ID_NUM::RUUVITAG_RAWV2) { + if (isTracker) { String tracker_name = String(model_id.c_str()) + "-tracker"; String tracker_id = macWOdots + "-tracker"; createDiscovery("device_tracker",