abhishek
abhishek

Reputation: 1434

Cannot fetch data from Smart Bluetooth LE Device Android

I am using a bluetooth LE device to connect with android app and i am able to make connection. But after making the connection i am not able to get the callback for the updates from device. I am not sure what i am doing wrong , so following is a part of the documentation from the manufacturer which i could not understand :-

"The oximeter supports a Display Sync command in its control point. The Display Sync command is a 2 octet message that is written to the control point. This feature can be used to synchronize the display of the oximeter with the display of the host device, which helps the operator confirm the pulse oximeter reading was received correctly."

where the 1st octet will have the value 0x61 and second octet should have a value between 5 and 25 seconds

In order to get this i did the following :-

  1. In LeScanCallback i connect the BluetoothDevice to BluetoothGattCallback

  2. In onServicesDiscovered i write the following line of code which i highly doubt is the correct way of achieving it and may be that is the reason i am not getting the data from Bluetooth Device :-

    BluetoothGattCharacteristic oximeterCharacteristic =

    noninService.getCharacteristic(UUID.fromString(Oximeter_characteristic_uuid));
        BluetoothGattCharacteristic noninControlPointCharacteristic = 
    
       noninService.getCharacteristic(UUID.fromString(Nonin_control_point_characteristic_uuid)); 
    
       oximeterCharacteristic.setValue(0x61, oximeterCharacteristic.FORMAT_SINT16, 1);
        oximeterCharacteristic.setValue(15, oximeterCharacteristic.FORMAT_SINT16, 2);
        noninControlPointCharacteristic.setValue(0x61, noninControlPointCharacteristic.FORMAT_SINT16, 1);
        noninControlPointCharacteristic.setValue(15, noninControlPointCharacteristic.FORMAT_SINT16, 2);
    
    
    gatt.writeCharacteristic(noninControlPointCharacteristic);
        gatt.writeCharacteristic(oximeterCharacteristic);
        gatt.setCharacteristicNotification(oximeterCharacteristic, true);
        gatt.setCharacteristicNotification(noninControlPointCharacteristic, true);
    

Upvotes: 0

Views: 417

Answers (1)

Zomb
Zomb

Reputation: 911

I am not sure how the multiple set values are going to work, but there are a couple of other things that I can point out you need to change. You want to set your Notification alerts before you do the write. Its also not enough to just call setCharacteristicNotification, you would also need to write down the notification descriptor (you can see an example of this in the Android bluetooth examples) and wait for the callback saying that the descriptor is written to the device. Once you get the call back saying the descriptor write is successful, you can do the writes. Once you make these changes to the code, I would advise restarting both the device and the phone, because the Android bluetooth stack tends to get into an unstable mode that does not recover unless you restart the phone.

Upvotes: 0

Related Questions