android и bluetooth ble - соединение и передача данных

У меня есть устройство c bluetooth low energy (ble). Не получается к нему подключиться и получить данные (прочитать). Пытаюсь сделать так:

   gatt = device.connectGatt(ctx, false, bluetoothGattCallback)

   private val bluetoothGattCallback = object : BluetoothGattCallback() {
       ...
       override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) {
         if (newState == BluetoothProfile.STATE_CONNECTED) {
                 Timber.d("onConnectionStateChange BluetoothProfile.STATE_CONNECTED")
                 // successfully connected to the GATT Server
                 ...
                 gatt?.discoverServices()
                 gatt?.services

                 readAction()
            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                 Timber.d("onConnectionStateChange BluetoothProfile.STATE_DISCONNECTED")
                 // disconnected from the GATT Server
                 connectionInfoView?.text = getString(R.string.disconnected)
                 connectionInfoView?.setTextColor(ContextCompat.getColor(ctx, R.color.gray))
             ...
                 gatt?.close()
                 gatt?.connect()
            }
        }
   }

Сервисы (gatt?.services) пустые. Не соображу что делать. Что мне нужно, чтобы получить данные с bluetooth ble?


Ответы (0 шт):