Add immediate parameter to BLE connection commands. (#1137)
* Add immediate parameter to BLE connection commands.
When sending a command to read/write a characteristic on a BLE server this adds a new parameter to cause the action to be
performed immediately. This will stop the scan in progress to perform the actions queued.
Example use:
```
mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -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",
"ble_write_value":"TEST",
"value_type":"STRING",
"ttl":4,
"immediate":true }'
```
Stop BLE processing when immeditate command sent.
* Use a shorter connection timeout.
* Update docs.
* Remove MQTT spam for connection retrys
* Prevent crashing when the normal connection process occurs at the same time as an immediate action.
* Use a semaphore to protect BLE device vector.
This commit is contained in:
1 parent
8d793a8b50
commit
5dac1a7035
4 files changed
+121
-53
No files matched your search
@@ -50,14 +50,14 @@ bool zBLEConnect::writeData(BLEAction* action) {
|
||||
std::string temp = action->value.substr(i, 2);
|
||||
buf.push_back((uint8_t)strtoul(temp.c_str(), nullptr, 16));
|
||||
}
|
||||
return pChar->writeValue((const uint8_t*)&buf[0], buf.size(), !pChar->canWrite());
|
||||
return pChar->writeValue((const uint8_t*)&buf[0], buf.size(), !pChar->canWriteNoResponse());
|
||||
}
|
||||
case BLE_VAL_INT:
|
||||
return pChar->writeValue(strtol(action->value.c_str(), nullptr, 0), !pChar->canWrite());
|
||||
return pChar->writeValue(strtol(action->value.c_str(), nullptr, 0), !pChar->canWriteNoResponse());
|
||||
case BLE_VAL_FLOAT:
|
||||
return pChar->writeValue(strtod(action->value.c_str(), nullptr), !pChar->canWrite());
|
||||
return pChar->writeValue(strtod(action->value.c_str(), nullptr), !pChar->canWriteNoResponse());
|
||||
default:
|
||||
return pChar->writeValue(action->value, !pChar->canWrite());
|
||||
return pChar->writeValue(action->value, !pChar->canWriteNoResponse());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -82,12 +82,12 @@ bool zBLEConnect::processActions(std::vector<BLEAction>& actions) {
|
||||
if (NimBLEAddress(it.addr) == m_pClient->getPeerAddress()) {
|
||||
JsonObject BLEresult = getBTJsonObject();
|
||||
BLEresult["id"] = it.addr;
|
||||
BLEresult["service"] = (char*)it.service.toString().c_str();
|
||||
BLEresult["characteristic"] = (char*)it.characteristic.toString().c_str();
|
||||
BLEresult["service"] = it.service.toString();
|
||||
BLEresult["characteristic"] = it.characteristic.toString();
|
||||
|
||||
if (it.write) {
|
||||
Log.trace(F("processing BLE write" CR));
|
||||
BLEresult["write"] = it.value.c_str();
|
||||
BLEresult["write"] = it.value;
|
||||
result = writeData(&it);
|
||||
} else {
|
||||
Log.trace(F("processing BLE read" CR));
|
||||
@@ -117,9 +117,11 @@ bool zBLEConnect::processActions(std::vector<BLEAction>& actions) {
|
||||
}
|
||||
}
|
||||
|
||||
it.complete = true;
|
||||
it.complete = result;
|
||||
BLEresult["success"] = result;
|
||||
pubBT(BLEresult);
|
||||
if (result || it.ttl <= 1) {
|
||||
pubBT(BLEresult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user