This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

As to Indicator Communication with Android app,

Hello,

I need your help, please review the following description and help to let me know the method to solve the issue,

thankful for your support in advance,

the symptom is ,

when using google app for ble communication with nrf51822, and trying to communicate as a indicator mode, 

I can't receive continuously after first touching in app in order to do indicate mode, after secondly touching in app, I can receive the data continuously, 

why ?

I update the log, please help to review it,

first touch, 

2018-11-19 16:26:59.344 13446-13446/com.example.android.bluetoothlegatt D/DeviceControlActivity: love PROPERTY_INDICATE
2018-11-19 16:26:59.347 13446-13446/com.example.android.bluetoothlegatt D/BluetoothLeService: love setCharacteristicIndication END
2018-11-19 16:26:59.347 13446-13446/com.example.android.bluetoothlegatt D/DeviceControlActivity: love PROPERTY_WRITE
2018-11-19 16:26:59.403 13446-13460/com.example.android.bluetoothlegatt D/BluetoothLeService: love onCharacteristicRead.
2018-11-19 16:26:59.404 13446-13460/com.example.android.bluetoothlegatt D/BluetoothLeService: love RAW_DATA format UINT8.
2018-11-19 16:26:59.417 13446-13460/com.example.android.bluetoothlegatt D/BluetoothLeService: love broadcastUpdate sendBroadcast execution

second touch, 

2018-11-19 16:27:13.713 13446-13446/com.example.android.bluetoothlegatt D/DeviceControlActivity: love PROPERTY_READ setCharacteristicIndication
2018-11-19 16:27:13.719 13446-13446/com.example.android.bluetoothlegatt D/BluetoothLeService: love setCharacteristicIndication END
2018-11-19 16:27:13.719 13446-13446/com.example.android.bluetoothlegatt D/DeviceControlActivity: love PROPERTY_INDICATE
2018-11-19 16:27:13.724 13446-13446/com.example.android.bluetoothlegatt D/BluetoothLeService: love setCharacteristicIndication END
2018-11-19 16:27:13.725 13446-13446/com.example.android.bluetoothlegatt D/DeviceControlActivity: love PROPERTY_WRITE
2018-11-19 16:27:13.802 13446-13499/com.example.android.bluetoothlegatt D/BluetoothLeService: love onCharacteristicChanged [B@3c4a623
2018-11-19 16:27:13.802 13446-13499/com.example.android.bluetoothlegatt D/BluetoothLeService: love RAW_DATA format UINT8.
2018-11-19 16:27:13.815 13446-13499/com.example.android.bluetoothlegatt D/BluetoothLeService: love broadcastUpdate sendBroadcast execution
2018-11-19 16:27:13.893 13446-13499/com.example.android.bluetoothlegatt D/BluetoothLeService: love onCharacteristicChanged [B@76b9720
2018-11-19 16:27:13.894 13446-13499/com.example.android.bluetoothlegatt D/BluetoothLeService: love RAW_DATA format UINT8.

thanks.

update the code, 

private final ExpandableListView.OnChildClickListener servicesListClickListner =
new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id) {
if (mGattCharacteristics != null) {
final BluetoothGattCharacteristic characteristic =
mGattCharacteristics.get(groupPosition).get(childPosition);
final int charaProp = characteristic.getProperties();
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
// If there is an active notification on a characteristic, clear
// it first so it doesn't update the data field on the user interface.
if (mNotifyCharacteristic != null)
{
Log.d(TAG, "love PROPERTY_READ setCharacteristicNotification");
mBluetoothLeService.setCharacteristicNotification(
mNotifyCharacteristic, false);
mNotifyCharacteristic = null;
}

if (mIndicateCharacteristic != null)
{
Log.d(TAG, "love PROPERTY_READ setCharacteristicIndication");
mBluetoothLeService.setCharacteristicIndication(
mIndicateCharacteristic, false);
mIndicateCharacteristic = null;
}

mBluetoothLeService.readCharacteristic(characteristic);
}

// if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0)
if ( (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == BluetoothGattCharacteristic.PROPERTY_NOTIFY )
{
Log.d(TAG, "love PROPERTY_NOTIFY");
mNotifyCharacteristic = characteristic;
mBluetoothLeService.setCharacteristicNotification(
characteristic, false);
}

// if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0)
if ( (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) == BluetoothGattCharacteristic.PROPERTY_INDICATE )
{
Log.d(TAG, "love PROPERTY_INDICATE");
mIndicateCharacteristic = characteristic;
mBluetoothLeService.setCharacteristicIndication(
characteristic, false);
}

if ((charaProp | BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) {
Log.d(TAG, "love PROPERTY_WRITE");

if (UUID.fromString(SampleGattAttributes.THD_CONTROL_COMMAND).equals(characteristic.getUuid()))
{
if (mNotifyCharacteristic != null) {
mBluetoothLeService.setCharacteristicNotification(
mNotifyCharacteristic, false);
mNotifyCharacteristic = null;
}

if (mIndicateCharacteristic != null) {
mBluetoothLeService.setCharacteristicIndication(
mIndicateCharacteristic, false);
mIndicateCharacteristic = null;
}

mBluetoothLeService.writeCharacteristic(characteristic);//love_1022
}
}
return true;
}
return false;
}
};

and the code of service is,

/**
* Enables or disables notification on a give characteristic.
*
* @param characteristic Characteristic to act on.
* @param enabled If true, enable notification. False otherwise.
*/
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}

mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

if (UUID_THD_RAW_DATA_TRANSFER.equals(characteristic.getUuid()))
{
//love_0831 devzone.nordicsemi.com/.../android-enable-notification-client-side-cccd-uuid

final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
}
}

public void setCharacteristicIndication(BluetoothGattCharacteristic characteristic,
boolean enabled) {//love_1022

if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}

mBluetoothGatt.setCharacteristicNotification(characteristic, true);

if (UUID_THD_RAW_DATA_TRANSFER.equals(characteristic.getUuid()))
{
//love_0831 devzone.nordicsemi.com/.../android-enable-notification-client-side-cccd-uuid

final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
Log.d(TAG, "love setCharacteristicIndication END");
}
}

public void writeCharacteristic(BluetoothGattCharacteristic characteristic){
// Toast.makeText(getApplicationContext(),"THD_CONTROL_COMMAND",Toast.LENGTH_SHORT).show();

if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "writeCharacteristic BluetoothAdapter not initialized");
return;
}

flag_count++;

if((flag_count % 2) == 1)
SampleGattAttributes.test_flag = 1;
else if((flag_count % 2) == 0)
SampleGattAttributes.test_flag = 2;
Toast.makeText(getApplicationContext(),SampleGattAttributes.test_flag+" value",Toast.LENGTH_SHORT).show();

final int Thdvalue;

if(SampleGattAttributes.test_flag == 1)
{
Log.d(TAG, "love THD_CONTROL_COMMAND 1 SET OK\r\n");
Thdvalue = 1;//START,
characteristic.setValue(Thdvalue,BluetoothGattCharacteristic.FORMAT_SINT8, 0);
mBluetoothGatt.writeCharacteristic(characteristic);
}
else if(SampleGattAttributes.test_flag == 2)
{
Log.d(TAG, "love THD_CONTROL_COMMAND 0 SET ==> OK\r\n");
Thdvalue = 0;//STOP,
flag_count = 0;
characteristic.setValue(Thdvalue,BluetoothGattCharacteristic.FORMAT_SINT8, 0);
mBluetoothGatt.writeCharacteristic(characteristic);

((DeviceControlActivity)DeviceControlActivity.mContext).saveExcel("");//love_1018
}

}

Parents
  • Hi.

    1. Which SDK do you use?

    2. Which example have you programmed on nRF51822?

    3. Have you made any modifications to the code?

    4.

    when using google app for ble communication with nrf51822, and trying to communicate as a indicator mode, 

     What do you mean by google app? Do you mean the nRF Connect App for Android?

    5. What do you mean by indicator mode?

    6.

    I can't receive continuously after first touching in app in order to do indicate mode, after secondly touching in app, I can receive the data continuously, 

     What do you mean by "touching in app"

    Could you be more detailed?

    Please answer these questions so I can get a bit more information about what your problem is, since it is not specified well.

    Best regards.

    - Andreas

Reply
  • Hi.

    1. Which SDK do you use?

    2. Which example have you programmed on nRF51822?

    3. Have you made any modifications to the code?

    4.

    when using google app for ble communication with nrf51822, and trying to communicate as a indicator mode, 

     What do you mean by google app? Do you mean the nRF Connect App for Android?

    5. What do you mean by indicator mode?

    6.

    I can't receive continuously after first touching in app in order to do indicate mode, after secondly touching in app, I can receive the data continuously, 

     What do you mean by "touching in app"

    Could you be more detailed?

    Please answer these questions so I can get a bit more information about what your problem is, since it is not specified well.

    Best regards.

    - Andreas

Children
No Data
Related