From 5ff086a296b514e23d8cc63d623548a5319723ce Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 26 Jun 2023 05:13:41 -0500 Subject: [PATCH] [BT] Fix BLE MQTT command trigger a reset (#1698) Problem introduced with the bump of ESP32 platform from 3.5.0 to 6.1.0 --- docs/use/ble.md | 6 +++--- main/ZgatewayBT.ino | 8 +++++--- main/config_BT.h | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/use/ble.md b/docs/use/ble.md index bcb0ac26eb..2e3e3bfdf6 100644 --- a/docs/use/ble.md +++ b/docs/use/ble.md @@ -287,7 +287,7 @@ To specify the MAC address type add the parameter `"mac_type"` to the command. F ### Example write command ``` -mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{ +mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT -m '{ "ble_write_address":"AA:BB:CC:DD:EE:FF", "ble_write_service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b", "ble_write_char":"cba20002-224d-11e6-9fb8-0002a5d5c51b", @@ -308,7 +308,7 @@ Response: ``` ### Example read command ``` -mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{ +mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT -m '{ "ble_read_address":"AA:BB:CC:DD:EE:FF", "ble_read_service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b", "ble_read_char":"cba20002-224d-11e6-9fb8-0002a5d5c51b", @@ -343,7 +343,7 @@ The device can also be controlled over MQTT with a simplified BLE write command. ### Example command to set the SwitchBot state to ON: ``` -mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{ +mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT -m '{ "SBS1":"on", "mac":"AA:BB:CC:DD:EE:FF" }' diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index d340e99833..5979df8f0f 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -1361,7 +1361,8 @@ void MQTTtoBTAction(JsonObject& BTdata) { if (BTdata.containsKey("SBS1")) { strcpy(action.addr, (const char*)BTdata["mac"]); action.write = true; - action.value = BTdata["SBS1"].as(); + std::string val = BTdata["SBS1"].as(); // Fix #1694 + action.value = val; action.ttl = 1; createOrUpdateDevice(action.addr, device_flags_connect, TheengsDecoder::BLE_ID_NUM::SBS1, 1); @@ -1397,7 +1398,8 @@ void MQTTtoBTAction(JsonObject& BTdata) { strcpy(action.addr, (const char*)BTdata["ble_write_address"]); action.service = NimBLEUUID((const char*)BTdata["ble_write_service"]); action.characteristic = NimBLEUUID((const char*)BTdata["ble_write_char"]); - action.value = std::string((const char*)BTdata["ble_write_value"]); + std::string val = BTdata["ble_write_value"].as(); // Fix #1694 + action.value = val; action.write = true; Log.trace(F("BLE ACTION Write" CR)); } else if (BTdata.containsKey("ble_read_address") && @@ -1464,7 +1466,7 @@ void MQTTtoBT(char* topicOri, JsonObject& BTdata) { // json object decoding if (BTdata.containsKey("lowpowermode")) { changelowpowermode((int)BTdata["lowpowermode"]); } - + } else if (cmpToMainTopic(topicOri, subjectMQTTtoBT)) { MQTTtoBTAction(BTdata); } } diff --git a/main/config_BT.h b/main/config_BT.h index 45dc5c42af..ebde35a52d 100644 --- a/main/config_BT.h +++ b/main/config_BT.h @@ -46,6 +46,7 @@ extern int btQueueLengthCount; /*-----------BT TOPICS & COMPILATION PARAMETERS-----------*/ #define subjectBTtoMQTT "/BTtoMQTT" #define subjectMQTTtoBTset "/commands/MQTTtoBT/config" +#define subjectMQTTtoBT "/commands/MQTTtoBT" // Uncomment to send undecoded device data to another gateway device for decoding // #define MQTTDecodeTopic "undecoded" #ifndef UseExtDecoder