Ble read/write characteristics over MQTT. (#988)
* EXPERIMENTAL: Ble read/write characteristics over MQTT. Uses #979 This allows reading and writing BLE characteristics from an MQTT message. Example format: 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", "ttl":4 }' mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"ble_read_address":"30:AE:A4:7C:3C:A6", "ble_read_service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b", "ble_read_char":"cba20002-224d-11e6-9fb8-0002a5d5c51b", "ttl": 2 }' The ttl parameter is the number of calls to connect (defaults to 1), which occur after the BLE scan completes. A response is provided over MQTT in the format: write : {"id":"30:AE:A4:7C:3C:A6","service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b","characteristic":"cba20002-224d-11e6-9fb8-0002a5d5c51b","write":"TEST","success":true} read : {"id":"30:AE:A4:7C:3C:A6","service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b","characteristic":"cba20002-224d-11e6-9fb8-0002a5d5c51b","read":"TEST","success":true} * Add generic BLE connect class and read data as hex. * Add value_type parameter and document usage * Add note to docs
This commit is contained in:
1 parent
ac23235327
commit
7cfbd3d050
5 files changed
+251
-2
No files matched your search
+53
-1
@@ -103,7 +103,7 @@ In this case you should deactivate the BLE connection mechanism to avoid concurr
|
||||
For certain devices like LYWSD03MMC OpenMQTTGateway use a connection (due to the fact that the advertized data are encrypted), this connection mechanism is launched after every `ScanBeforeConnect` per default, you can modify it by following the procedure below.
|
||||
:::
|
||||
|
||||
## Setting the number of scans between before connect attempt
|
||||
## Setting the number of scans between connection attempts
|
||||
|
||||
If you want to change the number of BLE scans that are done before a BLE connect you can change it by MQTT, if you want the BLE connect to be every 30 scans:
|
||||
|
||||
@@ -152,6 +152,58 @@ you can also accept all the devices by the following command:
|
||||
|
||||
The default value is set into config_BT.h
|
||||
|
||||
## Read/write BLE characteristics over MQTT (ESP32 only)
|
||||
|
||||
The gateway can read and write BLE characteristics from devices and provide the results in an MQTT message.
|
||||
::: tip
|
||||
These actions will be taken on the next BLE connection, which occurs after scanning and after the scan count is reached, [see above to set this.](#setting-the-number-of-scans-between-connection-attempts)
|
||||
:::
|
||||
|
||||
### Example write command
|
||||
```
|
||||
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 }'
|
||||
```
|
||||
Response:
|
||||
```
|
||||
{
|
||||
"id":"AA:BB:CC:DD:EE:FF",
|
||||
"service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b",
|
||||
"characteristic":"cba20002-224d-11e6-9fb8-0002a5d5c51b",
|
||||
"write":"TEST",
|
||||
"success":true
|
||||
}
|
||||
```
|
||||
### Example read commnad
|
||||
```
|
||||
mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -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",
|
||||
"value_type":"STRING",
|
||||
"ttl": 2 }'
|
||||
```
|
||||
Response:
|
||||
```
|
||||
{
|
||||
"id":"AA:BB:CC:DD:EE:FF",
|
||||
"service":"cba20d00-224d-11e6-9fb8-0002a5d5c51b",
|
||||
"characteristic":"cba20002-224d-11e6-9fb8-0002a5d5c51b",
|
||||
"read":"TEST",
|
||||
"success":true
|
||||
}
|
||||
```
|
||||
|
||||
::: tip
|
||||
The `ttl` parameter is the number of attempts to connect (defaults to 1), which occur after the BLE scan completes.
|
||||
`value_type` can be one of: STRING, HEX, INT, FLOAT. Default is STRING if omitted in the message.
|
||||
:::
|
||||
|
||||
## Other
|
||||
|
||||
To check your hm10 firmware version upload a serial sketch to the nodemcu (this will enable communication directly with the hm10) and launch the command:
|
||||
|
||||
Reference in new issue
Block a user