From 997b598100d3e76bdcee83d7dfdc2346d5e96b94 Mon Sep 17 00:00:00 2001 From: Bad Date: Wed, 15 Jun 2022 09:11:30 +0200 Subject: [PATCH 1/6] Add useBeaconUuidForPresence flag (disabled by default) --- main/ZgatewayBT.ino | 6 ++++++ main/config_BT.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 6e55afb33f..633bed4b80 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -114,6 +114,12 @@ void pubBTMainCore(JsonObject& data, bool haPresenceEnabled = true) { data.remove("servicedatauuid"); if (data.containsKey("servicedata")) data.remove("servicedata"); +# if useBeaconUuidForPresence + if (data.containsKey("model_id") && data["model_id"].as() == "IBEACON") { + data["mac"] = data["id"]; + data["id"] = data["uuid"]; + } +# endif String topic = String(Base_Topic) + "home_presence/" + String(gateway_name); Log.trace(F("Pub HA Presence %s" CR), topic.c_str()); pub_custom_topic((char*)topic.c_str(), data, false); diff --git a/main/config_BT.h b/main/config_BT.h index c6c88bed68..dcd29bf948 100644 --- a/main/config_BT.h +++ b/main/config_BT.h @@ -130,6 +130,10 @@ bool hassPresence = HassPresence; /*-------------------HOME ASSISTANT ROOM PRESENCE ----------------------*/ #define subjectHomePresence "home_presence/" // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name) +#ifndef useBeaconUuidForPresence +# define useBeaconUuidForPresence false // //define true to use iBeacon UUID as for presence, instead of sender mac (random) address +#endif + /*-------------------PIN DEFINITIONS----------------------*/ #if !defined(BT_RX) || !defined(BT_TX) # ifdef ESP8266 From 3fd16ccccfd6a436551310e5e3e18aa9452de243 Mon Sep 17 00:00:00 2001 From: Bad Date: Wed, 15 Jun 2022 09:13:41 +0200 Subject: [PATCH 2/6] Change MQTTDecodeTopic to include only the sufixe --- main/ZgatewayBT.ino | 9 +++++---- main/config_BT.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 633bed4b80..ad05831b88 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -97,16 +97,17 @@ void pubBTMainCore(JsonObject& data, bool haPresenceEnabled = true) { if (abs((int)data["rssi"] | 0) < minRssi && data.containsKey("id")) { String mac_address = data["id"].as(); mac_address.replace(":", ""); -# ifdef MQTTDecodeTopic String mactopic; +# ifdef MQTTDecodeTopic if (data.containsKey("model")) { - mactopic = subjectBTtoMQTT + String("/") + mac_address; + mactopic = mac_address; } else { - mactopic = String("/") + MQTTDecodeTopic; + mactopic = MQTTDecodeTopic; } # else - String mactopic = subjectBTtoMQTT + String("/") + mac_address; + mactopic = mac_address; # endif + mactopic = subjectBTtoMQTT + String("/") + mactopic; pub((char*)mactopic.c_str(), data); } if (haPresenceEnabled && data.containsKey("distance")) { diff --git a/main/config_BT.h b/main/config_BT.h index dcd29bf948..a3587bc318 100644 --- a/main/config_BT.h +++ b/main/config_BT.h @@ -53,7 +53,7 @@ bool bleConnect = AttemptBLECOnnect; #define subjectBTtoMQTT "/BTtoMQTT" #define subjectMQTTtoBTset "/commands/MQTTtoBT/config" // Uncomment to send undecoded device data to another gateway device for decoding -// #define MQTTDecodeTopic "BTtoMQTT/undecoded" +// #define MQTTDecodeTopic "undecoded" #define MinimumRSSI -100 //default minimum rssi value, all the devices below -90 will not be reported From 4ac772169de316faff9ee96c3dae274c9fc0ec8a Mon Sep 17 00:00:00 2001 From: Bad Date: Wed, 15 Jun 2022 09:17:04 +0200 Subject: [PATCH 3/6] Rename mac_address to topic and remove unnecessary variable mactopic --- main/ZgatewayBT.ino | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index ad05831b88..df87eac674 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -95,20 +95,14 @@ int minRssi = abs(MinimumRSSI); //minimum rssi value void pubBTMainCore(JsonObject& data, bool haPresenceEnabled = true) { if (abs((int)data["rssi"] | 0) < minRssi && data.containsKey("id")) { - String mac_address = data["id"].as(); - mac_address.replace(":", ""); - String mactopic; + String topic = data["id"].as(); + topic.replace(":", ""); // Initially publish topic ends with mac address # ifdef MQTTDecodeTopic - if (data.containsKey("model")) { - mactopic = mac_address; - } else { - mactopic = MQTTDecodeTopic; - } -# else - mactopic = mac_address; + if (!data.containsKey("model")) + topic = MQTTDecodeTopic; // If MQTTDecodeTopic and no model, topic is changed # endif - mactopic = subjectBTtoMQTT + String("/") + mactopic; - pub((char*)mactopic.c_str(), data); + topic = subjectBTtoMQTT + String("/") + topic; + pub((char*)topic.c_str(), data); } if (haPresenceEnabled && data.containsKey("distance")) { if (data.containsKey("servicedatauuid")) From a327e29fd49e3ee83673c385dad0dab095d64dd1 Mon Sep 17 00:00:00 2001 From: Bad Date: Wed, 15 Jun 2022 09:20:12 +0200 Subject: [PATCH 4/6] Add useBeaconUuidForTopic flag (disabled by default) --- main/ZgatewayBT.ino | 6 +++++- main/config_BT.h | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index df87eac674..031c4566d2 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -97,9 +97,13 @@ void pubBTMainCore(JsonObject& data, bool haPresenceEnabled = true) { if (abs((int)data["rssi"] | 0) < minRssi && data.containsKey("id")) { String topic = data["id"].as(); topic.replace(":", ""); // Initially publish topic ends with mac address +# if useBeaconUuidForTopic + if (data.containsKey("model_id") && data["model_id"].as() == "IBEACON") + topic = data["uuid"].as(); // If model_id is IBEACON, use uuid as topic +# endif # ifdef MQTTDecodeTopic if (!data.containsKey("model")) - topic = MQTTDecodeTopic; // If MQTTDecodeTopic and no model, topic is changed + topic = MQTTDecodeTopic; // If external decoder, topic is MQTTDecodeTopic # endif topic = subjectBTtoMQTT + String("/") + topic; pub((char*)topic.c_str(), data); diff --git a/main/config_BT.h b/main/config_BT.h index a3587bc318..2f6acc8477 100644 --- a/main/config_BT.h +++ b/main/config_BT.h @@ -127,6 +127,10 @@ bool hassPresence = HassPresence; # define pubBLEServiceUUID false // define true if you want to publish the service UUID data #endif +#ifndef useBeaconUuidForTopic +# define useBeaconUuidForTopic false // define true to use iBeacon UUID as topic, instead of sender (random) mac address +#endif + /*-------------------HOME ASSISTANT ROOM PRESENCE ----------------------*/ #define subjectHomePresence "home_presence/" // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name) From 02e2d036ab992a9000abc57febc416d60f8a4711 Mon Sep 17 00:00:00 2001 From: Bad Date: Wed, 15 Jun 2022 09:20:39 +0200 Subject: [PATCH 5/6] Fix jsonPublishing #ifdef -> #if --- main/main.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/main.ino b/main/main.ino index 63b93e509c..4f8ede8b44 100644 --- a/main/main.ino +++ b/main/main.ino @@ -328,7 +328,7 @@ void pub(const char* topicori, JsonObject& data) { # endif #endif -#ifdef jsonPublishing +#if jsonPublishing Log.trace(F("jsonPubl - ON" CR)); pubMQTT(topic, dataAsString.c_str()); #endif From 019f9e84a874a37b6725c31532df43089b3e8192 Mon Sep 17 00:00:00 2001 From: Bad Date: Sun, 19 Jun 2022 09:12:34 +0200 Subject: [PATCH 6/6] Revert commit 02e2d03 --- main/main.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/main.ino b/main/main.ino index 4f8ede8b44..63b93e509c 100644 --- a/main/main.ino +++ b/main/main.ino @@ -328,7 +328,7 @@ void pub(const char* topicori, JsonObject& data) { # endif #endif -#if jsonPublishing +#ifdef jsonPublishing Log.trace(F("jsonPubl - ON" CR)); pubMQTT(topic, dataAsString.c_str()); #endif