[BT] Fix BT command triggering a stack trace due to conflict (#2104)
related to the vector between BLE scanning and BLE control Co-authored-by: Florian <1technophile@users.noreply.github.com>
This commit is contained in:
1 parent
bb05011bdc
commit
921488359e
2 files changed
+27
-16
No files matched your search
@@ -317,6 +317,11 @@ By the way, if you want to load the default built-in configuration (on any board
|
|||||||
`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"init":true}'`
|
`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"init":true}'`
|
||||||
Note that it will not change the stored configuration, `erase` or `save` is still needed to overwrite the saved configuration.
|
Note that it will not change the stored configuration, `erase` or `save` is still needed to overwrite the saved configuration.
|
||||||
|
|
||||||
|
## Controlling devices
|
||||||
|
::: tip
|
||||||
|
To control devices reliably, set the interval between scans to at least 5 seconds and the scan duration to 1 second to ensure commands are successfully transmitted to your devices.
|
||||||
|
:::
|
||||||
|
|
||||||
## Read/write BLE characteristics over MQTT
|
## Read/write BLE characteristics over MQTT
|
||||||
|
|
||||||
The gateway can read and write BLE characteristics from devices and provide the results in an MQTT message.
|
The gateway can read and write BLE characteristics from devices and provide the results in an MQTT message.
|
||||||
|
|||||||
+22
-16
@@ -1359,22 +1359,27 @@ void immediateBTAction(void* pvParameters) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (xSemaphoreTake(semaphoreBLEOperation, pdMS_TO_TICKS(5000)) == pdTRUE) {
|
if (xSemaphoreTake(semaphoreBLEOperation, pdMS_TO_TICKS(5000)) == pdTRUE) {
|
||||||
// swap the vectors so only this device is processed
|
if (xSemaphoreTake(semaphoreCreateOrUpdateDevice, pdMS_TO_TICKS(QueueSemaphoreTimeOutTask)) == pdTRUE) {
|
||||||
std::vector<BLEdevice*> dev_swap;
|
// swap the vectors so only this device is processed
|
||||||
dev_swap.push_back(getDeviceByMac(BLEactions.back().addr));
|
std::vector<BLEdevice*> dev_swap;
|
||||||
std::swap(devices, dev_swap);
|
dev_swap.push_back(getDeviceByMac(BLEactions.back().addr));
|
||||||
|
std::swap(devices, dev_swap);
|
||||||
|
|
||||||
std::vector<BLEAction> act_swap;
|
std::vector<BLEAction> act_swap;
|
||||||
act_swap.push_back(BLEactions.back());
|
act_swap.push_back(BLEactions.back());
|
||||||
BLEactions.pop_back();
|
BLEactions.pop_back();
|
||||||
std::swap(BLEactions, act_swap);
|
std::swap(BLEactions, act_swap);
|
||||||
|
|
||||||
// Unlock here to allow the action to be performed
|
// Unlock here to allow the action to be performed
|
||||||
BTProcessLock = false;
|
BTProcessLock = false;
|
||||||
BLEconnect();
|
BLEconnect();
|
||||||
// back to normal
|
// back to normal
|
||||||
std::swap(devices, dev_swap);
|
std::swap(devices, dev_swap);
|
||||||
std::swap(BLEactions, act_swap);
|
std::swap(BLEactions, act_swap);
|
||||||
|
xSemaphoreGive(semaphoreCreateOrUpdateDevice);
|
||||||
|
} else {
|
||||||
|
Log.error(F("CreateOrUpdate Semaphore NOT taken" CR));
|
||||||
|
}
|
||||||
|
|
||||||
// If we stopped the scheduled connect for this action, do the scheduled now
|
// If we stopped the scheduled connect for this action, do the scheduled now
|
||||||
if (millis() > (timeBetweenConnect + BTConfig.intervalConnect) && BTConfig.bleConnect) {
|
if (millis() > (timeBetweenConnect + BTConfig.intervalConnect) && BTConfig.bleConnect) {
|
||||||
@@ -1383,7 +1388,8 @@ void immediateBTAction(void* pvParameters) {
|
|||||||
}
|
}
|
||||||
xSemaphoreGive(semaphoreBLEOperation);
|
xSemaphoreGive(semaphoreBLEOperation);
|
||||||
} else {
|
} else {
|
||||||
Log.error(F("BLE busy - command not sent" CR));
|
Log.error(F("BLE busy - immediateBTAction not sent" CR));
|
||||||
|
gatewayState = GatewayState::ERROR;
|
||||||
StaticJsonDocument<JSON_MSG_BUFFER> BLEdataBuffer;
|
StaticJsonDocument<JSON_MSG_BUFFER> BLEdataBuffer;
|
||||||
JsonObject BLEdata = BLEdataBuffer.to<JsonObject>();
|
JsonObject BLEdata = BLEdataBuffer.to<JsonObject>();
|
||||||
BLEdata["id"] = BLEactions.back().addr;
|
BLEdata["id"] = BLEactions.back().addr;
|
||||||
@@ -1575,7 +1581,7 @@ void XtoBT(const char* topicOri, JsonObject& BTdata) { // json object decoding
|
|||||||
XtoBTAction(BTdata);
|
XtoBTAction(BTdata);
|
||||||
xSemaphoreGive(semaphoreBLEOperation);
|
xSemaphoreGive(semaphoreBLEOperation);
|
||||||
} else {
|
} else {
|
||||||
Log.error(F("BLE busy - command not sent" CR));
|
Log.error(F("BLE busy - BTActions not sent" CR));
|
||||||
gatewayState = GatewayState::ERROR;
|
gatewayState = GatewayState::ERROR;
|
||||||
}
|
}
|
||||||
} else if (strstr(topicOri, subjectTrackerSync) != NULL) {
|
} else if (strstr(topicOri, subjectTrackerSync) != NULL) {
|
||||||
|
|||||||
Reference in new issue
Block a user