iBeacon: Flag to use UUID in topic or presence (and fixes) (#1226)
* Add useBeaconUuidForPresence flag (disabled by default) * Change MQTTDecodeTopic to include only the sufixe * Rename mac_address to topic and remove unnecessary variable mactopic * Add useBeaconUuidForTopic flag (disabled by default) * Fix jsonPublishing #ifdef -> #if * Revert commit 02e2d03
This commit is contained in:
2 files changed
+26
-13
No files matched your search
+17
-12
@@ -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<const char*>();
|
||||
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<const char*>();
|
||||
topic.replace(":", ""); // Initially publish topic ends with mac address
|
||||
# if useBeaconUuidForTopic
|
||||
if (data.containsKey("model_id") && data["model_id"].as<String>() == "IBEACON")
|
||||
topic = data["uuid"].as<const char*>(); // 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<String>() == "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);
|
||||
|
||||
+9
-1
@@ -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
|
||||
|
||||
Reference in new issue
Block a user