NDU Gateway

Integrate legacy and third-party systems with NDU platform using IoT Gateway.

BLE Connector Configuration

This guide will help you to get familiar with BLE connector configuration for NDU 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:

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

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
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
    "name": "BLE Connector",
    "rescanIntervalSeconds": 100,
    "checkIntervalSeconds": 100,
    "scanTimeSeconds": 5,
    "passiveScanMode": true,
    "devices": [
        {
            "name": "Temperature and humidity sensor",
            "MACAddress": "4C:65:A8:DF:85:C0",
            "telemetry": [
                {
                    "key": "temperature",
                    "method": "notify",
                    "characteristicUUID": "226CAA55-6476-4566-7562-66734470666D",
                    "byteFrom": 2,
                    "byteTo": 6
                },
                {
                    "key": "humidity",
                    "method": "notify",
                    "characteristicUUID": "226CAA55-6476-4566-7562-66734470666D",
                    "byteFrom": 9,
                    "byteTo": 13
                }
            ],
            "attributes": [
                {
                    "key": "name",
                    "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB",
                    "method": "read",
                    "byteFrom": 0,
                    "byteTo": -1
                }
            ],
            "attributeUpdates": [
                {
                    "attributeOnNDU": "sharedName",
                    "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB"
                }
            ],
            "serverSideRpc": [
                {
                    "methodRPC": "sharedName",
                    "withResponse": true,
                    "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB",
                    "methodProcessing": "write"
                }
            ]
        }
    ]
}


To understand how this connector works, we will describe how to connect device Xiaomi Mi Smart Temperature Humidity Sensor to NDU 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 NDU 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 NDU).
In a subsection attributeUpdates we write the configuration to rename the device after receiving attribute update request from NDU.
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
3
4
5
6
7
8
9
10
{
    "name": "BLE Connector",
    "rescanIntervalSeconds": 100,
    "checkIntervalSeconds": 100,
    "scanTimeSeconds": 5,
    "passiveScanMode": true,
    "devices": [
                ...
                ]
}

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 NDU.
MACAddress 4C:65:A8:DF:C0 MAC address for the device of interest.
deviceType BLEDevice Device type for NDU, 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 NDU.
serverSideRpc   Array of objects for processing RPC requests from NDU.

This part of configuration will look like:

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

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

Parameter Default value Description
key temperature Name for telemetry in NDU.
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
3
4
5
6
7
                {
                    "key": "temperature",
                    "method": "notify",
                    "characteristicUUID": "226CAA55-6476-4566-7562-66734470666D",
                    "byteFrom": 2,
                    "byteTo": 6
                },

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 NDU.
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
3
4
5
6
7
                {
                    "key": "name",
                    "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB",
                    "method": "read",
                    "byteFrom": 0,
                    "byteTo": -1
                }

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 NDU.

Subsection attributeUpdates

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

Parameter Default name Description
attributeOnNDU sharedName Name of shared device attribute in NDU.
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
3
4
                {
                    "attributeOnNDU": "sharedName",
                    "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB"
                }


Characteristic should support method WRITE for processing the attributeUpdate request.

Subsection serverSideRpc

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

Parameter Default name Description
methodRPC rpcMethod1 RPC method name.
withResponse true If true, response will be sent to NDU.
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
3
4
5
6
                {
                    "methodRPC": "rpcMethod1",
                    "withResponse": true,
                    "characteristicUUID": "00002A00-0000-1000-8000-00805F9B34FB",
                    "methodProcessing": "read"
                }

Next steps

Explore guides related to main NDU features: