This guide will help you to get familiar with BLE connector configuration for ThingsBoard IoT Gateway. Use general configuration to enable this extension. We will describe connector configuration file below.

BLE connector need some system libraries, to install them please select version of package manager in your system below and run a command to install libraries:
**

| APT-GET |
YUM
| | :—-: | :—-: |

APT-GET
You should install some system libraries for using BLE Connector and bluepy library for python.
Just copy following commands and run them:
This command will install required libraries:

  1. sudo apt-get install -y libglib2.0-dev zlib1g-dev

This command will install bluepy library:

  1. sudo pip3 install bluepy

YUM
You should install some system libraries for using BLE Connector and bluepy library for python.
Just copy following commands and run them:
This command will install required libraries:

  1. sudo yum groupinstall -y "development tools"

This command will install bluepy library:

  1. sudo pip3 install bluepy

Example of BLE Connector config file. Press to expand.

  1. {
  2. "name": "BLE Connector",
  3. "rescanIntervalSeconds": 100,
  4. "checkIntervalSeconds": 100,
  5. "scanTimeSeconds": 5,
  6. "passiveScanMode": true,
  7. "devices": [
  8. {
  9. "name": "Temperature and humidity sensor",
  10. "MACAddress": "4C:65:A8:DF:85:C0",
  11. "telemetry": [
  12. {
  13. "key": "temperature",
  14. "method": "notify",
  15. "characteristicUUID": "226CAA55-6476-4566-7562-66734470666D",
  16. "byteFrom": 2,
  17. "byteTo": 6
  18. },
  19. {
  20. "key": "humidity",
  21. "method": "notify",
  22. "characteristicUUID": "226CAA55-6476-4566-7562-66734470666D",
  23. "byteFrom": 9,
  24. "byteTo": 13
  25. }
  26. ],
  27. "attributes": [
  28. {
  29. "key": "name",
  30. "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB",
  31. "method": "read",
  32. "byteFrom": 0,
  33. "byteTo": -1
  34. }
  35. ],
  36. "attributeUpdates": [
  37. {
  38. "attributeOnThingsBoard": "sharedName",
  39. "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB"
  40. }
  41. ],
  42. "serverSideRpc": [
  43. {
  44. "methodRPC": "sharedName",
  45. "withResponse": true,
  46. "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB",
  47. "methodProcessing": "write"
  48. }
  49. ]
  50. }
  51. ]
  52. }
To understand how this connector works, we will describe how to connect device Xiaomi Mi Smart Temperature Humidity Sensor to ThingsBoard using gateway. We know following device parameters: Device MAC address - 4C:65:A8:DF:85:C0 Default name characteristic id - 00002A00-0000-1000-8000-00805F9B34FB - This is a default characteristic - we have got it ID from GATT characeristics documentation Temperature characteristic id - 00002A00-0000-1000-8000-00805F9B34FB - This is a custom characteristic - we have got it after scanning device characteristics.

Default configuration created for this device to process data from it, receive notifies and write some information.

In a main section we write general configuration for our connector, such as connector name scan interval, etc.
In a device subsection we write general configuration for connection to our device (name for device in ThingsBoard and device MAC address, etc.).
In a subsection telemetry we write the configuration for processing data from the device (Where the gateway should take the data, method and converter will interpret this data to telemetry and attributes on ThingsBoard).
In a subsection attributeUpdates we write the configuration to rename the device after receiving attribute update request from ThingsBoard.
If device shared attribute with a name “sharedName” changed - gateway will write data from this attribute to characteristic with ID - 00002A00-0000-1000-8000-00805F9B34FB.

Main section

This section contains general settings for the connector.

Parameter Default value Description
name BLE Connector Connector name for logs and saving to persistent devices.
rescanIntervalSeconds 100 Interval for rescanning devices around.
checkIntervalSeconds 100 Interval for check device to obtain new data.
scanTimeSeconds 5 Time for scanning devices in seconds.
passiveScanMode true Scanning using passive mode.
devices Contains an array of devices of interest.

This part of configuration will look like:

  1. {
  2. "name": "BLE Connector",
  3. "rescanIntervalSeconds": 100,
  4. "checkIntervalSeconds": 100,
  5. "scanTimeSeconds": 5,
  6. "passiveScanMode": true,
  7. "devices": [
  8. ...
  9. ]
  10. }

Device object subsection

This subsection contains general settings for the device and subsections for processing data.

Parameter Default value Description
name BLE Connector Name for the device in ThingsBoard.
MACAddress 4C:65:A8:DF:C0 MAC address for the device of interest.
deviceType BLEDevice Device type for ThingsBoard, by default this parameter is absent, but you can add it.
telemetry Array of objects for processing device telemetry.
attributes Array of objects for processing device attributes.
attributeUpdates Array of objects for processing attributeUpdate requests from ThingsBoard.
serverSideRpc Array of objects for processing RPC requests from ThingsBoard.

This part of configuration will look like:

  1. {
  2. "name": "Temperature and humidity sensor",
  3. "MACAddress": "4C:65:A8:DF:85:C0",
  4. "telemetry": [
  5. ...
  6. ],
  7. "attributes": [
  8. ...
  9. ],
  10. "attributeUpdates": [
  11. ...
  12. ],
  13. "serverSideRpc": [
  14. ...
  15. ]
  16. }

Subsection telemetry

This subsection contains general settings for the processing data interpreted as telemetry.

Parameter Default value Description
key temperature Name for telemetry in ThingsBoard.
method notify Method for Characteristic processing (Can be NOTIFY or READ).
characteristicUUID 226CAA55-6476-4566-7562-66734470666D UUID of characteristic on the device.
byteFrom 2 Start position of bytes in response interpreted as value**.
byteTo 6 The end position of bytes in the device response interpreted as value**.

This part of configuration will look like:

  1. {
  2. "key": "temperature",
  3. "method": "notify",
  4. "characteristicUUID": "226CAA55-6476-4566-7562-66734470666D",
  5. "byteFrom": 2,
  6. "byteTo": 6
  7. },


The values shown in the table above may differ in your configuration.
– For example response from device is bytes string like b’T=54.7 H=37.0’, in this case – 54.7 interpreted as value of key.
If you need to interpreted full response as value use byteFrom: 0 and byteTo: -1.

Subsection attributes

This subsection contains general settings for the processing data interpreted as attributes.

Parameter Default name Description
key name Name for telemetry in ThingsBoard.
method read Method for Characteristic processing (Can be NOTIFY or READ).
characteristicUUID 00002A00-0000-1000-8000-00805F9B34FB UUID of characteristic on the device.
byteFrom 0 Start position of bytes in response interpreted as value**.
byteTo -1 The end position of bytes in the device response interpreted as value**.

This part of configuration will look like:

  1. {
  2. "key": "name",
  3. "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB",
  4. "method": "read",
  5. "byteFrom": 0,
  6. "byteTo": -1
  7. }

The values shown in the table above may differ in your configuration.
– For example response from device is bytes string like b’Coolest device’, in this case – Coolest device interpreted as value of key.
If you need to interpreted full response as value use
byteFrom: 0 and byteTo: -1**.

Services and characteristics, from GATT Specification will also interpret as attributes of device and automatically loaded to ThingsBoard.

Subsection attributeUpdates

This subsection contains settings for the processing attributeUpdate requests from ThingsBoard.

Parameter Default name Description
attributeOnThingsBoard sharedName Name of shared device attribute in ThingsBoard.
characteristicUUID 00002A00-0000-1000-8000-00805F9B34FB UUID of characteristic in which the attribute value will be written.

This part of configuration will look like:

  1. {
  2. "attributeOnThingsBoard": "sharedName",
  3. "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB"
  4. }
Characteristic should support method WRITE for processing the attributeUpdate request.

Subsection serverSideRpc

This subsection contains settings for the processing RPC requests from ThingsBoard.

Parameter Default name Description
methodRPC rpcMethod1 RPC method name.
withResponse true If true, response will be sent to ThingsBoard.
characteristicUUID 00002A00-0000-1000-8000-00805F9B34FB UUID of characteristic.
methodProcessing read Method for processing to characteristic. (READ/WRITE/NOTIFY)

This part of configuration will look like:

  1. {
  2. "methodRPC": "rpcMethod1",
  3. "withResponse": true,
  4. "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB",
  5. "methodProcessing": "read"
  6. }

Next steps

Explore guides related to main ThingsBoard features: