Skip to content

BLE Device Discovery

The BLE Device Service can locate any BLE devices that are in advertising mode and within range when it is in discovery mode.

By default, discovery mode is enabled when the Device Service starts and a call is made every 10 seconds. These settings can be changed using the following environment variables:

Environment Variable Description
DEVICE_DISCOVERY_ENABLED Specifies whether device discovery is enabled

Set to true to enable device discovery

Set to false to disable device discovery. If discovery is disabled, new devices that are advertising are not discovered or added to Edge Xpert; the Device Service continues to recognize any devices that were previously discovered

Default is true
DEVICE_DISCOVERY_INTERVAL Specifies the interval in seconds at which to issue the discovery command

The discovery call is issued at the frequency defined in DEVICE_DISCOVERY_INTERVAL for the period defined by the DRIVER_BLE_DISCOVERYDURATION environment variable

Default is 30s

The environment variables are specified in the environments section of the docker-compose.yml file, as shown in the following extract:

DEVICE_DISCOVERY_ENABLED: 'true'
DEVICE_DISCOVERY_INTERVAL: '30s' 

If you need to update any of the default values, you must create a local copy of docker-compose.yml before starting the BLE Device Service. Once you have created the local file, you can update the environments section and start Edge Xpert from the directory containing your local docker-compose file.

To issue a discovery request, manually enter the following command in a terminal.

Dynamic Discovery

The BLE Device Service can locate any BLE devices that are in advertising mode and within range when it is in discovery mode.

The device service compares the attributes broadcast by the device with those listed in provision watchers.

To ensure that the Edge Xpert device name is unique, devices of the same type with the same name are described using the device name and MAC address. For example, a device named SensorTag with a MAC address of 00:00:00:00:01 is given an Edge Xpert device name of SensorTag(00:00:00:00:01).

The criteria are saved in a JSON file and uploaded to metadata to allow the BLE Device Service to identify the devices to add to Edge Xpert.

Example Provision Watcher

In the following example, you can see the command used to match broadcasting devices:

Info

If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.

curl --request POST 'http://localhost:59881/api/v2/provisionwatcher' \
--header 'Content-Type: application/json' \
--data-raw '[
   {
      "provisionwatcher":{
         "apiVersion":"v2",
         "name":"Provision-Watcher-BLE",
         "adminState":"UNLOCKED",
         "labels":[
            "ble"
         ],
         "identifiers":{
            "Alias":"^CC2650+(.*)$"
         },
         "serviceName":"device-ble",
         "profileName": "sensor-tag-cc2650",
         "protocolName":"ble",
         "deviceDescription":"ble device {{MAC}}"
      },
      "apiVersion":"v2"
   }
]'

Note

You have to upload a device profile first before adding a provision watcher.