Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


Bluetooth Low Energy device discovery management. More...

Import Statement: import Felgo 4.0
Since: Felgo 3.7.0



Detailed Description

General info and usage examples for Bluetooth LE: Use Bluetooth Low Energy

The BluetoothLeManager component controls the Local Bluetooth device, the local bluetooth device can be turned on and off in Android, on iOS the device status is set via event updates only and might not be completely accurate. The local device mode can be set to Central only at the moment, via the Role enumeration and role property. Device discovery is started by setting the discoveryRunning property to true, once a new device is discovered the deviceDiscovered signal is emitted.

Connect to a device by calling the connect method and passing the desired remote device as parameter, this will also start the service discovery. Stop the connection by calling the disconnect method.

You can define ahead of time the devices and services you expect to connect to, this way it's simpler than using the values from the device list, since you can reference the service component id in other parts of your QML code.

 BluetoothLeManager {
   BluetoothLeDevice {
     id: myDevice
     BluetoothLeService {
       id: myDeviceBatteryService
       uuid: 0x180F

Note: On Android location permission must be set and location must be enabled for device discovery to work.

Property Documentation

ManagerState : enumeration

Specifies the Local Device on state.

  • BluetoothLeManager.PoweredOff The Local Bluetooth Device state is powered off.
  • BluetoothLeManager.PoweredOn The Local Bluetooth Devices state is powered on.

See also state.

Role : enumeration

Specifies the Local Device role, the default value is BluetoothLeManager.Central.

  • BluetoothLeManager.Central The Local Bluetooth Device acts as Central device.
  • BluetoothLeManager.Peripheral The Local Bluetooth Devices acts as Peripheral, not implemented.

See also role.

devices : list<BluetoothLeDevice>

List children devices described in QML used for connection, you can describe multiple devices if your use case case requires you to have the ability to connect to several devices, of the same or different type.

discoveredDevices : list<BluetoothLeDevice>

List of devices discovered from the last time the discoveryRunning property was set to true, the list is cleared every time a new discovery process starts.

discoveryRunning : bool

Enable or disable device discovery.

discoveryTimeout : int

Device discovery in milliseconds, a 0 timeout is used for continuous discovery until the discoveryRunning property is set to false. The default value is 5000 ms.

localDeviceName : string

The local Bluetooth device name, empty on iOS and macOS.

role : BluetoothLeManager::Role

Sets the Bluetooth stack for Central or Peripheral role, default value is Central, only Central role is implemented at the moment.

state : BluetoothLeManager::ManagerState

Enable or disable Local Bluetooth Device on Android, read-only on state in iOS.

Signal Documentation

deviceDiscovered(QVariantMap device)

Emitted for every new device discovered by the Bluetooth LE controller. A device object with the following properties:

  • name As reported by the remote device, might be empty
  • address The remote device address, in android corresponds to the actual remote device address, on iOS a random unique address is returned
  • services A list of the advertised services in long string format.
  • rssi The rssi signal at the moment of discovery.

Check if the discovered contains one or more services you are interested and connect to it.

 BluetoothLeManager {
   discoveryRunning: true

     id: myBleDevice

   onDeviceDiscovered: device => {
     // Match device with service UUID
     if (device.services.indexOf('{0000180f-0000-1000-8000-00805f9b34fb}') > -1) {
       //Set and connect
       myBleDevice.setDevice(device, true)
       discoveryRunning = false

Note: The corresponding handler is onDeviceDiscovered.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded