From a74eb769312a3e40cfcedc8515c0a150f27dbb30 Mon Sep 17 00:00:00 2001 From: animavitis Date: Fri, 9 Nov 2018 22:19:02 +0100 Subject: [PATCH] fix ESP32 ble (#304) * remove redundant code for home presence * hopefully fix ESP32 BLE hangs * basic support for duplicate detection when JSON publishing is active --- OpenMQTTGateway.ino | 13 +++++++++++++ ZgatewayBT.ino | 10 +++++----- config_BT.h | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index 744e380..dc2c69a 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -830,9 +830,22 @@ void receivingMQTT(char * topicOri, char * datacallback) { if (strstr(topicOri, subjectMultiGTWKey) != NULL) // storing received value so as to avoid publishing this value if it has been already sent by this or another OpenMQTTGateway { trc(F("Storing signal")); + #ifdef jsonPublishing + trc(F("Creating Json buffer")); + StaticJsonBuffer jsonBuffer; + JsonObject& jsondata = jsonBuffer.parseObject(datacallback); + unsigned long data = strtoul(jsondata["value"], NULL, 10); // we will not be able to pass values > 4294967295 + storeValue(data); + trc(F("Data from JSON stored")); + #endif + + + #ifdef simplePublishing unsigned long data = strtoul(datacallback, NULL, 10); // we will not be able to pass values > 4294967295 storeValue(data); trc(F("Data stored")); + #endif + } //YELLOW ON digitalWrite(led_send, LOW); diff --git a/ZgatewayBT.ino b/ZgatewayBT.ino index c82a114..4d67e3c 100644 --- a/ZgatewayBT.ino +++ b/ZgatewayBT.ino @@ -74,11 +74,12 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht BLEdata.set("txpower", (int8_t) advertisedDevice.getTXPower()); } if (advertisedDevice.haveServiceData()){ - + char mac[mac_adress.length()+1]; mac_adress.toCharArray(mac,mac_adress.length()+1); trc(F("Get service data ")); + std::string serviceData = advertisedDevice.getServiceData(); int serviceDataLength = serviceData.length(); String returnedString = ""; @@ -98,9 +99,7 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht BLEdata.set("servicedatauuid", (char *)advertisedDevice.getServiceDataUUID().toString().c_str()); - char topic[] = subjectBTtoMQTT; - strcat(topic, mac); - pub(topic,BLEdata); + pub((char *)mactopic.c_str(),BLEdata); if (strstr(BLEdata["servicedatauuid"].as(),"fe95") != NULL){ trc("Processing BLE device data"); @@ -116,6 +115,7 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht trc("mi jia data reading"); boolean result = process_data(pos - 26,service_data,mac); } + } } } @@ -129,7 +129,7 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht "coreTask", /* Name of the task */ 10000, /* Stack size in words */ NULL, /* Task input parameter */ - 0, /* Priority of the task */ + 1, /* Priority of the task */ NULL, /* Task handle. */ taskCore); /* Core where the task should run */ trc(F("ZgatewayBT multicore ESP32 setup done ")); diff --git a/config_BT.h b/config_BT.h index a4aee29..b428d4d 100644 --- a/config_BT.h +++ b/config_BT.h @@ -35,7 +35,7 @@ /*-------------------HOME ASSISTANT ROOM PRESENCE ----------------------*/ // if not commented Home presence integration with HOME ASSISTANT is activated -#define subjectHomePresence Base_Topic "/salon" // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name) +#define subjectHomePresence Base_Topic "home_presence/" Gateway_Name // will send Home Assistant room presence message to this topic (first part is same for all rooms, second is room name) struct decompose