Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iBeacon: Flag to use UUID in topic or presence (and fixes) #1226

Merged
merged 6 commits into from
Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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(":", "");
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
# ifdef MQTTDecodeTopic
String mactopic;
if (data.containsKey("model")) {
mactopic = subjectBTtoMQTT + String("/") + mac_address;
} else {
mactopic = String("/") + MQTTDecodeTopic;
}
# else
String mactopic = subjectBTtoMQTT + String("/") + mac_address;
if (!data.containsKey("model"))
topic = MQTTDecodeTopic; // If external decoder, topic is MQTTDecodeTopic
# endif
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"))
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);
Expand Down
10 changes: 9 additions & 1 deletion main/config_BT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down