Skip To Content

BluetoothLEDevice QML Type

(BETA) Provides access to, and information about, Bluetooth Low Energy devices. More...

Import Statement: import ArcGIS.AppFramework.Devices 1.0
Inherits:

Device

Properties

Signals

Detailed Description

The BluetoothLEDevice component acts as the entry point for Bluetooth Low Energy (LE) integration, used to collect information about the device itself, as well as to collect information about and substantiate the next tier, BluetoothLEService.

Bluetooth LE devices use a heirarchical data structure, with four possible tiers: The device, services, characteristics, and descriptors. The components for these tiers can only be instantiated by the tier above it.

"GATT Profile Hierarchy"

This code sample demonstrates a potential usage of BluetoothLEDevice, using the AppFramework's Bluetooth LE integration to connect to a proprietary fitness device. This sample demonstrates how to detect a known service, characteristic and descriptor. The returned values can't be read; these values are proprietary information.

Item {
        //These 4 property values are the same for any vivofit device. Change these values to detect other devices.
        property string bluetoothDeviceName: "vivofit"
        property string serviceUuid: "{9b012401-bc30-ce9a-e111-0f67e491abde}"
        property string characteristicUuid: "{4acbcd28-7425-868e-f447-915c8f00d0cb}"
        property string descriptorUuid: "{00002902-0000-1000-8000-00805f9b34fb}"

        property BluetoothLEDevice bluetoothDevice: discoveryAgent.devices.count > 0 ? discoveryAgent.devices.get(0) : null
        property BluetoothLEService bluetoothService: null
        property BluetoothLECharacteristic bluetoothCharacteristic: null
        property BluetoothLEDescriptor bluetoothDescriptor: null

        DeviceDiscoveryAgent {
                id: discoveryAgent
                deviceFilter: function(device) {
                        return device.name === bluetoothDeviceName;
                }
        }

        Component.onCompleted: {
                log("To connect to a nearby " + bluetoothDeviceName + ", ensure sync is enabled on the device.")
                log(new Date() + " Searching for bluetooth device: " + bluetoothDeviceName);
                discoveryAgent.start();
        }

        onBluetoothDeviceChanged: {
                log(new Date() + " Expected bluetooth device found: ");
                JSON.stringify(bluetoothDevice, undefined, 2).split("\n").forEach(log);
                bluetoothDevice.connected = true;
                discoveryAgent.stop();
        }

        Connections {
                target: bluetoothDevice

                onConnectCompleted: log(new Date() + " Device connect completed")

                onServiceDiscoveryCompleted: log(new Date() + " Service discovery completed")

                onServiceDiscovered: {
                        if (service.uuid === serviceUuid) {
                                log(new Date() + " Found EXPECTED service: " + service.name + " " + service.uuid);
                                bluetoothService = service;
                                bluetoothService.discoverDetails();
                        }

                }

                onErrorChanged: {
                        log(new Date() + " Found error: " + bluetoothDevice.error);
                }
        }

        Connections {
                target: bluetoothService

                onCharacteristicsChanged: {
                        bluetoothCharacteristic = bluetoothService.characteristics.getByUuid(characteristicUuid)
                        bluetoothCharacteristic.read()
                }
        }

        Connections {
                target: bluetoothCharacteristic

                onValueChanged: {
                        if (bluetoothCharacteristic.uuid === characteristicUuid) {
                                log(new Date() + " Found EXPECTED characteristic: " + bluetoothCharacteristic.uuid);

                                bluetoothDescriptor = bluetoothCharacteristic.descriptors.getByUuid(descriptorUuid);
                                bluetoothDescriptor.read();
                        }
                }
        }

        Connections {
                target: bluetoothDescriptor

                onValueChanged: {
                        if (bluetoothDescriptor.uuid === descriptorUuid) {
                                log(new Date() + " Found EXPECTED descriptor: " + bluetoothDescriptor.uuid);
                        }
                }
        }

        ListView {
                anchors.fill: parent
                anchors.margins: 5
                model: messagesListModel
                delegate: Text {text: msg}
                clip: true
        }

        ListModel {
                id: messagesListModel
        }

        function log(txt) {
                console.log(txt);
                messagesListModel.append( { msg: txt } );
                if (messagesListModel.count > 40) { messagesListModel.remove(0); }
        }
}

Property Documentation

[read-only] rssi : int

Returns the signal strength when the device was last scanned.


serviceClass : string

Returns the service class of the device.


[read-only] services : ServiceListModel

Returns the list of services offered by the remote device.


Signal Documentation

connectCompleted()

Signal emitted when the device connection has been completed.


serviceDiscovered( BluetoothLEService service)

Signal emitted each time a new service is discovered.


serviceDiscoveryCompleted()

Signal emitted when service discovery has been completed.