Android BLE Gatt timeout after gatt.writeDescriptor ()

I am currently trying to run the BLE application on Android. In particular, I am trying to get a BLE signal sent from an iOS device. Below is the code related to my problem.

   public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
            Log.w(tag, "State: " + newState+"    status: "+ status + "  (0 is success)");
            if (newState == BluetoothProfile.STATE_CONNECTED) {
                String intentAction = "com.example.bluetooth.le.ACTION_GATT_CONNECTED";
                final Intent intent = new Intent(intentAction);
                callbackActivity.sendBroadcast(intent);
                Log.w(tag, "Connected to GATT server.");
                // Attempts to discover services after successful connection.
                Log.w(tag, "Attempting to start service discovery:" +
                        mConnectedGatt.discoverServices());
                // Clear data to prepare for new data reading
                bluetoothData.clear();
            } else {
                Log.w(tag, "GATT connection unsuccessful.");
                restartSearch(gatt);
            }
        }

        /**
         * Called when a service has been discovered in the connected device
         */
        @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            Log.w(tag, "Services Discovered! "+status);
            if(gatt.getService(SERVICE_UUID)!=null){
                Log.w(tag, "Not null!");
                BluetoothGattCharacteristic characteristic=gatt.getService(SERVICE_UUID).getCharacteristic(CHARACTERISTC_UUID);                       
                gatt.setCharacteristicNotification(characteristic, true);
                BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                        CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
                descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
                Log.w(tag, "Writing to descriptor: "+mConnectedGatt.writeDescriptor(descriptor));
            }
            else{
                Log.w(tag, "Services discovered unsuccessful");
                restartSearch(gatt);
            }

, Android . , discoverServices() onServiceDiscovered. , , mConnectedGatt.writeDescriptor() true. callback onCharacteristicChanged . 10 writeDescriptor, onConnectionStateChanged, , . 95% . 5% , , onCharacteristicChanged.

, ? , , Android, BLE iOS.

+4

Source: https://habr.com/ru/post/1547608/


All Articles