3
votes

I'm trying to create an Android 5 (lollipop) app that acts as a Bluetooth Low Energy (BLE) peripheral. The app runs on a Nexus 9 which supports BLE peripheral mode. So far I've managed to advertise a service and allow another BLE device connect to it successfully. However, it is fails when trying to read the characteristic value.

I've checked that the characteristic has the read property and that the read permission is set.

When using the LightBlue iOS app (https://itunes.apple.com/gb/app/lightblue-bluetooth-low-energy/id557428110?mt=8) I manage to discover and connect to my Nexus and see the characteristic uuid but the value doesn't show.

Any help would be highly appreciated.

1
Did you get an answer to this? I am also trying to connect 2 Android devices, one as consumer and the other one as producer of data.Héctor Júdez Sapena

1 Answers

0
votes

First check the characteristic data you are advertising in the peripheral mode usually there are three modes

BluetoothGattCharacteristic.PROPERTY_WRITE,      BluetoothGattCharacteristic.PROPERTY_READ,
BluetoothGattCharacteristic.PROPERTY_NOTIFY;

and you can build characteristic with all modes using

BluetoothGattCharacteristic.PROPERTY_WRITE |BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY;

Once done look for onCharacteristicWriteRequest() in BluetoothGattServerCallback() that you gave while building characteristic. When central want to send data it can write data to the characteristic with WRITE mode and you will have onCharacteristicWriteRequest() callback method triggered at peripheral side and you will have data in byte[] and make sure send response using btGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, null); by checking the responseNeeded bool value in callback method. In this way the data is transferred from central to peripheral.

And to send data from peripheral to central use notification charatertertistc

BluetoothGattCharacteristic bgc = bluetoothGattService
                    .getCharacteristic(chartersticUUID);
                bgc.setValue(bnd.data);
    btGattServer.notifyCharacteristicChanged(centralbluetoothdevice, bgc, false);

.