diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 6e55afb..031c456 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -95,25 +95,30 @@ 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(":", ""); -# ifdef MQTTDecodeTopic - String mactopic; - if (data.containsKey("model")) { - mactopic = subjectBTtoMQTT + String("/") + mac_address; - } else { - mactopic = String("/") + MQTTDecodeTopic; - } -# else - String mactopic = subjectBTtoMQTT + String("/") + mac_address; + 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 - pub((char*)mactopic.c_str(), data); +# ifdef MQTTDecodeTopic + if (!data.containsKey("model")) + topic = MQTTDecodeTopic; // If external decoder, topic is MQTTDecodeTopic +# endif + topic = subjectBTtoMQTT + String("/") + topic; + pub((char*)topic.c_str(), data); } if (haPresenceEnabled && data.containsKey("distance")) { if (data.containsKey("servicedatauuid")) 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 c6c88be..2f6acc8 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 @@ -127,9 +127,17 @@ 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) +#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