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) {
|
void pubBTMainCore(JsonObject& data, bool haPresenceEnabled = true) {
|
||||||
if (abs((int)data["rssi"] | 0) < minRssi && data.containsKey("id")) {
|
if (abs((int)data["rssi"] | 0) < minRssi && data.containsKey("id")) {
|
||||||
String mac_address = data["id"].as<const char*>();
|
String topic = data["id"].as<const char*>();
|
||||||
mac_address.replace(":", "");
|
topic.replace(":", ""); // Initially publish topic ends with mac address
|
||||||
# ifdef MQTTDecodeTopic
|
# if useBeaconUuidForTopic
|
||||||
String mactopic;
|
if (data.containsKey("model_id") && data["model_id"].as<String>() == "IBEACON")
|
||||||
if (data.containsKey("model")) {
|
topic = data["uuid"].as<const char*>(); // If model_id is IBEACON, use uuid as topic
|
||||||
mactopic = subjectBTtoMQTT + String("/") + mac_address;
|
|
||||||
} else {
|
|
||||||
mactopic = String("/") + MQTTDecodeTopic;
|
|
||||||
}
|
|
||||||
# else
|
|
||||||
String mactopic = subjectBTtoMQTT + String("/") + mac_address;
|
|
||||||
# endif
|
# 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 (haPresenceEnabled && data.containsKey("distance")) {
|
||||||
if (data.containsKey("servicedatauuid"))
|
if (data.containsKey("servicedatauuid"))
|
||||||
data.remove("servicedatauuid");
|
data.remove("servicedatauuid");
|
||||||
if (data.containsKey("servicedata"))
|
if (data.containsKey("servicedata"))
|
||||||
data.remove("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);
|
String topic = String(Base_Topic) + "home_presence/" + String(gateway_name);
|
||||||
Log.trace(F("Pub HA Presence %s" CR), topic.c_str());
|
Log.trace(F("Pub HA Presence %s" CR), topic.c_str());
|
||||||
pub_custom_topic((char*)topic.c_str(), data, false);
|
pub_custom_topic((char*)topic.c_str(), data, false);
|
||||||
|
|||||||
+9
-1
@@ -53,7 +53,7 @@ bool bleConnect = AttemptBLECOnnect;
|
|||||||
#define subjectBTtoMQTT "/BTtoMQTT"
|
#define subjectBTtoMQTT "/BTtoMQTT"
|
||||||
#define subjectMQTTtoBTset "/commands/MQTTtoBT/config"
|
#define subjectMQTTtoBTset "/commands/MQTTtoBT/config"
|
||||||
// Uncomment to send undecoded device data to another gateway device for decoding
|
// 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
|
#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
|
# define pubBLEServiceUUID false // define true if you want to publish the service UUID data
|
||||||
#endif
|
#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 ----------------------*/
|
/*-------------------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)
|
#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----------------------*/
|
/*-------------------PIN DEFINITIONS----------------------*/
|
||||||
#if !defined(BT_RX) || !defined(BT_TX)
|
#if !defined(BT_RX) || !defined(BT_TX)
|
||||||
# ifdef ESP8266
|
# ifdef ESP8266
|
||||||
|
|||||||
Reference in new issue
Block a user