Skip to content

Commit

Permalink
[BT] Fix BLE MQTT command trigger a reset (#1698)
Browse files Browse the repository at this point in the history
Problem introduced with the bump of ESP32 platform from 3.5.0 to 6.1.0
  • Loading branch information
1technophile authored Jun 26, 2023
1 parent 7b3b14e commit 5ff086a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/use/ble.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
}'
Expand Down
8 changes: 5 additions & 3 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
std::string val = BTdata["SBS1"].as<std::string>(); // Fix #1694
action.value = val;
action.ttl = 1;
createOrUpdateDevice(action.addr, device_flags_connect,
TheengsDecoder::BLE_ID_NUM::SBS1, 1);
Expand Down Expand Up @@ -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<std::string>(); // Fix #1694
action.value = val;
action.write = true;
Log.trace(F("BLE ACTION Write" CR));
} else if (BTdata.containsKey("ble_read_address") &&
Expand Down Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions main/config_BT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ff086a

Please sign in to comment.