From 5b730fb5d973c32a3d2920927d28d5f07f742dfd Mon Sep 17 00:00:00 2001 From: Roman Bazalevsky Date: Sun, 8 Nov 2020 15:44:57 +0300 Subject: [PATCH] All detected beacons reporing moved from callbacks to loop() to prevent wrong MQTT payload due to race condition between regular jobs and callbacks. --- tasmota/xsns_52_ibeacon.ino | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tasmota/xsns_52_ibeacon.ino b/tasmota/xsns_52_ibeacon.ino index 8071d14a7..7ae8c4921 100755 --- a/tasmota/xsns_52_ibeacon.ino +++ b/tasmota/xsns_52_ibeacon.ino @@ -122,6 +122,7 @@ struct IBEACON_UID { uint8_t FLAGS; uint8_t TIME; #ifdef USE_IBEACON_ESP32 + uint8_t REPORTED; uint8_t REPTIME; char NAME[16]; #endif @@ -202,9 +203,7 @@ class ESP32BLEScanCallback : public BLEAdvertisedDeviceCallbacks memcpy(ib.RSSI,sRSSI,4); memset(ib.NAME,0x0,16); - if (ibeacon_add(&ib)==2) { - ibeacon_mqtt(ib.MAC,ib.RSSI,ib.UID,ib.MAJOR,ib.MINOR,ib.NAME); - } + ibeacon_add(&ib); } else { @@ -221,9 +220,7 @@ class ESP32BLEScanCallback : public BLEAdvertisedDeviceCallbacks memset(ib.NAME,0x0,16); } - if (ibeacon_add(&ib)==2) { - ibeacon_mqtt(ib.MAC,ib.RSSI,ib.UID,ib.MAJOR,ib.MINOR,ib.NAME); - } + ibeacon_add(&ib); } } } @@ -453,7 +450,7 @@ uint32_t ibeacon_add(struct IBEACON *ib) { #ifdef USE_IBEACON_ESP32 if (ibeacons[cnt].REPTIME >= IB_UPDATE_TIME) { ibeacons[cnt].REPTIME = 0; - return 2; + ibeacons[cnt].REPORTED = 0; } #endif return 1; @@ -466,7 +463,7 @@ uint32_t ibeacon_add(struct IBEACON *ib) { #ifdef USE_IBEACON_ESP32 if (ibeacons[cnt].REPTIME >= IB_UPDATE_TIME) { ibeacons[cnt].REPTIME = 0; - return 2; + ibeacons[cnt].REPORTED = 0; } #endif return 1; @@ -486,6 +483,7 @@ uint32_t ibeacon_add(struct IBEACON *ib) { #ifdef USE_IBEACON_ESP32 memcpy(ibeacons[cnt].NAME,ib->NAME,16); ibeacons[cnt].REPTIME = 0; + ibeacons[cnt].REPORTED = 0; #endif return 1; } @@ -698,7 +696,12 @@ void IBEACON_loop() { #ifdef USE_IBEACON_ESP32 - return; + for (uint32_t cnt=0;cnt