0

I currently have a working Android App (code snippet posted down below) that scans for BLE devices but uses hard-coded UUID's to only work with 1 specific device. While the app successfully connects and reads data that has read permissions, it seems as though the data I want comes with NOTIFY and WRITE NO RESPONSE only and therefore cannot be read normally. I am looking for a solution to work around this barrier. I have already tried reading from all other Services and their respective characteristics to see if my wanted data is there and so far no luck.

I have scanned the device to get all of its services and characteristics (Screenshot of all services provided):

https://imgur.com/a/mYWnAwO

Keep in mind I am aware that I am showcasing the devices mac address. However, knowing what type of device it is this will not matter.

as well as put together an android app to read the information from these services. Currently, I have the UUID's hardcoded in and connected to a readable service/characteristic however its value is always 0100 (clearly not what I want).

    public void readCustomCharacteristic() {
        if (mBluetoothAdapter == null || mBluetoothGatt == null) {
            Log.w(TAG, "BluetoothAdapter not initialized");
            return;
        }
        /*check if the service is available on the device*/
        BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000feba-0000-1000-8000-00805f9b34fb"));
        if(mCustomService == null){
            Log.w(TAG, "Custom BLE Service not found");
            return;
        }
        /*get the read characteristic from the service*/
        BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fa12-0000-1000-8000-00805f9b34fb"));
        if(mBluetoothGatt.readCharacteristic(mReadCharacteristic) == false){
            Log.w(TAG, "Failed to read characteristic");
        }
    }

    public void writeCustomCharacteristic(int value) {
        if (mBluetoothAdapter == null || mBluetoothGatt == null) {
            Log.w(TAG, "BluetoothAdapter not initialized");
            return;
        }
        /*check if the service is available on the device*/
        BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000feba-0000-1000-8000-00805f9b34fb"));
        if(mCustomService == null){
            Log.w(TAG, "Custom BLE Service not found");
            return;
        }
        /*get the read characteristic from the service*/
        BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fa11-0000-1000-8000-00805f9b34fb"));
        mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
        if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
            Log.w(TAG, "Failed to write characteristic");
        }
    }

The number that appears on my server (peripheral) needs to be the value captured via BLE and most certainly should be under one of these services and one specific characteristic. However, it's all a matter of finding it and deciphering it so it becomes human-readable on my end (Android App).

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
  • If the characteristic is notify then you can't read it. You simply enable notifications and wait for the notification callback. Notify characteristics sometimes require you to write a value to that or some other characteristic in order to trigger the delivery of data. In other cases they will just issue a steam of values – Paulw11 Jul 18 '19 at 00:36
  • Would you be able to supply a code example? Im very new to using Android Studio + BLE so I don't quite understand this. Thank you so much for the feedback though! Also, knowing that it cant be read how can I use it to begin with? Would I still be able to print this value to the screen and store it in a variable for later use in text to speech? – EsotericLanguage Jul 18 '19 at 01:02
  • I'm sorry, I don't know about Android programming, just Bluetooth on iOS. [This](https://stackoverflow.com/questions/32184536/enabling-bluetooth-characteristic-notification-in-android-bluetooth-low-energy) might help get you started. As I said, once you enable notification you wait for a callback with the value when the peripheral updates the characteristic. – Paulw11 Jul 18 '19 at 01:19

0 Answers0