Re-publish BTtoMQTT Theengs discovery topics on MQTT re-connect (#1290)

* Re-publish BTtoMQTT Theengs discovery topics on MQTT re-connect

- Improved version of #1274, this should re-publish more
- Handle return value of (MQTT) client.loop() to detect connection loss
  faster

Signed-off-by: Sami Salonen <ssalonen@gmail.com>
This commit is contained in:
Sami Salonen authored and GitHub committed 2022-10-23 10:57:39 -05:00
1 parent 8bc65d62dc
commit 941b1e109f
3 files changed
+20 -21

No files matched your search

+5 -4
View File
@@ -853,8 +853,9 @@ boolean valid_service_data(const char* data, int size) {
# ifdef ZmqttDiscovery
// This function always should be called from the main core as it generates direct mqtt messages
void launchBTDiscovery() {
if (newDevices == 0)
// When overrideDiscovery=true, we publish discovery messages of known devices (even if no new)
void launchBTDiscovery(bool overrideDiscovery) {
if (!overrideDiscovery && newDevices == 0)
return;
if (xSemaphoreTake(semaphoreCreateOrUpdateDevice, pdMS_TO_TICKS(1000)) == pdFALSE) {
Log.error(F("Semaphore NOT taken" CR));
@@ -866,8 +867,8 @@ void launchBTDiscovery() {
for (vector<BLEdevice*>::iterator it = localDevices.begin(); it != localDevices.end(); ++it) {
BLEdevice* p = *it;
Log.trace(F("Device mac %s" CR), p->macAdr);
// Do not launch discovery for the devices already discovered or that are not unique by their MAC Address (Ibeacon, GAEN and Microsoft Cdp)
if (!isDiscovered(p) &&
// Do not launch discovery for the devices already discovered (unless we have overrideDiscovery) or that are not unique by their MAC Address (Ibeacon, GAEN and Microsoft Cdp)
if ((overrideDiscovery || !isDiscovered(p)) &&
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::IBEACON &&
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::MS_CDP &&
p->sensorModel_id != TheengsDecoder::BLE_ID_NUM::GAEN) {