I am trying to develop a BLE bluetooth (SMART) application for Android, using Bluegiga BLED 112 device. I am following BLE demo sample code given in android sdk samples.
This is what my GattCallBack.
// Implements callback methods for GATT events that the app cares about.
// For example,
// connection status has changed, services are discovered,etc...
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
// Called when device has changed connection status and appropriate
// broadcast with device address extra is sent
// It can be either connected or disconnected state
@Override
public void onConnectionStateChange(final BluetoothGatt gatt,
int status, int newState) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// LogUtils.LOGI("BLE_STATUS", "SUCCESS");
Log.i("BLE service", "onConnectionStateChange - status: "
+ status + " - new state: " + newState);
if (gatt.discoverServices())
LogUtils.LOGI("DISCOVER_SERVC", "STARTED");
} else
// LogUtils.LOGI("DISCOVER_SERVC", "NOT_STARTED");
if (newState == BluetoothProfile.STATE_CONNECTED) {
LogUtils.LOGI("BLE_STATUS", "CON");
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
}
Log.i("BLE service", "onConnectionStateChange - status: " + status
+ " - new state: " + newState);
}
// Called when services are discovered on remote device
// If success broadcast with device address extra is sent
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
LogUtils.LOGI("BLE_STATUS", "SUCCESS");
}
Log.i("BLE service", "onServicesDiscovered - status: " + status);
}
// Called when characteristic was read
// Broadcast with characteristic uuid and status is sent
@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) {
Log.i("BLE service", "onCharacteristicRead - status: " + status
+ " - UUID: " + characteristic.getUuid());
}
// Called when characteristic was written
// Broadcast with characteristic uuid and status is sent
@Override
public void onCharacteristicWrite(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) {
Log.i("BLE service", "onCharacteristicWrite - status: " + status
+ " - UUID: " + characteristic.getUuid());
}
// Called when remote device rssi was read
// If success broadcast with device address extra is sent
@Override
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
}
Log.i("BLE service", "onReadRemoteRssi - status: " + status);
}
// Called when descriptor was written
@Override
public void onDescriptorWrite(BluetoothGatt gatt,
BluetoothGattDescriptor descriptor, int status) {
Log.i("BLE service", "onDescriptorWrite - status: " + status
+ " - UUID: " + descriptor.getUuid());
}
// Called when notification has been sent from remote device
// Broadcast with characteristic uuid is sent
@Override
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
Log.i("BLE service", "onCharacteristicChanged - status: "
+ " - UUID: " + characteristic.getUuid());
}
};
No matter what i do am not getting any services nor its charectrestics of the BLE Device The status code i am receiving in onConnectionstateChange is 133
Workaround tried : Since i already know the service UUID i tried to get the service object in GattCallBack as shown below
BluetoothGattService gattService = gatt.getService(device);
if (gattService == null) {
LogUtils.LOGI("GATT SERVICE", "null :" + gattService);
} else {
LogUtils.LOGI("GATT SERVICE", "not null :" + gattService);
}
But the result is always returning null
What should i do to get Gattservices and charectrestics ?