This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Keyfob, Android, Accelerometer, CC2541 - Did not work from android works BTool and Device Monitor

Other Parts Discussed in Thread: CC2541

Tried my best but could not enable Accelerometer in Android on Keyfob  CC2541 Mini Kit

final static public UUID ACC_NOTFIY = UUID.fromString("0000ffa1-0000-1000-8000-00805f9b34fb");
final static public UUID ACC_ENABLEX = UUID.fromString("0000ffa3-0000-1000-8000-00805f9b34fb");

if(ch.getUuid().compareTo(BleDefinedUUIDs.Characteristic.ACC_NOTFIY) == 0) {
Log.i(TAG, "Characterstic:" + "ACC_NOTFIY found");
setCharacteristicNotification(ch, enable);
waitIdle(GATT_TIMEOUT);
}

if(ch.getUuid().compareTo(BleDefinedUUIDs.Characteristic.ACC_ENABLEX) == 0) {
Log.i(TAG, "Characterstic:" + "ACC_ENABLEX found");
setCharacteristicNotification(ch, enable);
waitIdle(GATT_TIMEOUT);
}

 public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
        mBusy = true;
        boolean success = mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
        
        if(!success) {
        mBusy = false;
        Log.e(TAG, "Seting proper notification status for characteristic failed!");
        }
        else {
        //SChadha
        Log.i(TAG, "setNotificationForCharacteristic " +  characteristic.getUuid().toString() + " enabled: " + enabled);
        }
        waitIdle(GATT_TIMEOUT);
        
        // This is also sometimes required (e.g. for heart rate monitors) to enable notifications/indications
        // see: https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
        BluetoothGattDescriptor descriptor1 = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
        if(descriptor1 != null) {
        mBusy = true;
        Log.i(TAG, "setNotificationForCharacteristic" +  characteristic.getUuid().toString() + " descriptor 2902  found");
        byte[] val = enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
       descriptor1.setValue(val);
       mBluetoothGatt.writeDescriptor(descriptor1);
        }
        else {
        Log.i(TAG, "setNotificationForCharacteristic" +  characteristic.getUuid().toString() + " descriptor 2902 not found");
            }
        }
  }
  • Anybody can you please look at the code and let me know what I may be doing incorrect:

    I am not able to turn Accelerometer on CC2541 keyfob using Android. I appreciate your help:

    private static final UUID ACCEL_SERVICE_UUID = UUID.fromString("0000FFA0-0000-1000-8000-00805f9b34fb");
    	    private static final UUID ACCEL_ENABLE_UUID  =  UUID.fromString("0000FFA1-0000-1000-8000-00805f9b34fb");
    	    private static final UUID X_ENABLE_UUID      =  UUID.fromString("0000FFA3-0000-1000-8000-00805f9b34fb");
    	    private static final UUID X_ENABLE_UUID_DESC      =  UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
    	    
    	    public void EnableAccel(boolean enable) {
    
    	    	BluetoothGattService keyService = mBluetoothGatt.getService(ACCEL_SERVICE_UUID);
    	    	if(keyService == null) {
    		    	Log.d(TAG, "Acceleration service not found!");
    		    	return;
    	    	}
    
    	    	BluetoothGattCharacteristic enableAcceleration = keyService.getCharacteristic(ACCEL_ENABLE_UUID);
    	    	if(enableAcceleration == null) {
    		    	Log.d(TAG, "Acceleration Enable charateristic not found!");
    		    	return;
    	    	}
    	    	setCharacteristicNotification(enableAcceleration, enable);
    
    	    	BluetoothGattCharacteristic enableX = keyService.getCharacteristic(X_ENABLE_UUID);
    	    	if(enableX == null) {
    		    	Log.e(TAG, "Enable X charateristic not found!");
    	    	} else {	
    		    	BluetoothGattDescriptor gatDesc = enableX.getDescriptor(X_ENABLE_UUID_DESC);
    		    	if(gatDesc == null) {
    			    	Log.e(TAG, "Enable X BluetoothGattDescriptor not found!");
    			    	return;
    		    	}
    		    	
    		    	setDescriptorNotification(gatDesc, enable);
    	    	}
    	    	
    	    }

        public void setDescriptorNotification(BluetoothGattDescriptor descriptor, boolean enabled)
        {
        	Log.i(TAG, "setDescriptorNotification " +  descriptor.getUuid().toString());
        	byte[] val = enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
            descriptor.setValue(val);
            mBluetoothGatt.writeDescriptor(descriptor);
        }