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:
h2zero authored and GitHub committed 2021-06-21 20:27:06 -05:00
1 parent ac23235327
commit 7cfbd3d050
5 files changed
+251 -2

No files matched your search

+22
View File
@@ -46,6 +46,7 @@ bool bleConnect = AttemptBLECOnnect;
# ifndef BLE_FILTER_CONNECTABLE
# define BLE_FILTER_CONNECTABLE 1
# endif
# include "NimBLEDevice.h"
#endif
/*----------------------BT topics & parameters-------------------------*/
@@ -151,6 +152,7 @@ enum ble_sensor_model {
IBT4XS,
DT24,
EDDYSTONE_TLM,
GENERIC,
};
/*-------------------PIN DEFINITIONS----------------------*/
@@ -168,6 +170,26 @@ enum ble_sensor_model {
#endif
/*---------------INTERNAL USE: DO NOT MODIFY--------------*/
#ifdef ESP32
enum ble_val_type {
BLE_VAL_STRING = 0,
BLE_VAL_HEX,
BLE_VAL_INT,
BLE_VAL_FLOAT,
};
struct BLEAction {
std::string value;
char addr[18];
NimBLEUUID service;
NimBLEUUID characteristic;
bool write;
bool complete;
uint8_t ttl;
ble_val_type value_type;
};
#endif
struct BLEdevice {
char macAdr[18];
bool isDisc;