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

Nordik UART app with Multiple service reception

I need to receive both UART Service data and HRS service data on the app.

Currently I have seen on Nordik Connect app , both the services can be found and can connect and receive data.

I need to do same with my app using nordik UART App code.

I have changed UART profile to HRS profile and code was working, i was receiving Nordik HRS service data.

But i want both services should be used and receives data. so i have prepare separate UARTService_HRS for hrs profile in the same code.also added needed changed.but it gives error null pointer exception on BLEGattService.

Please help

  • I don't get what you write here. onCharacteristicRead() is when you read the characteristic.

    You mean you can get the characteristic correctly and now doing a characteristic read ?

    Why don't you call characteristic.getValue() to get the value ?? This is what I did in the UART app code, check function broadcastUpdate() in UartService.java

  • in above code i tried to read characteristics from both services . also tried to read characteristics in list fashion(code is commented for the same). we have broadcast update function. but when i debug the code HRS characteristics never executed. this below line return always false ,so i am unable to read. if (RX_TSCHAR_UUID.equals(characteristic.getUuid())) so i got something garbage data on this characteristics read not byte array.in represent my TS keyword for hrs profile in my code.

    private void broadcastUpdate(final String action,
                                     final BluetoothGattCharacteristic characteristic) {
            final Intent intent = new Intent(action);
            //final Intent intent1 = new Intent(action);
    
            // This is special handling for the Heart Rate Measurement profile.  Data parsing is
            // carried out as per profile specifications:
            // developer.bluetooth.org/.../CharacteristicViewer.aspx
            if (TX_CHAR_UUID.equals(characteristic.getUuid())) {
    
                // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() ));
                intent.putExtra(EXTRA_DATA, characteristic.getValue());
                BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CCCD);
    
                byte[] received= characteristic.getValue();
                String data = (characteristic.getValue() == null || characteristic.getValue().length <= 0) ? "0 bytes" : GeneralCharacteristicParser.parse(characteristic);
    
                intent.putExtra(SOME_MORE,data);
    
            }
    
            if (RX_TSCHAR_UUID.equals(characteristic.getUuid())) {
    
                // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() ));
                intent.putExtra(EXTRA_DATA, characteristic.getValue());
                BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CCCDTS);
    
                byte[] received= characteristic.getValue();
                String data = (characteristic.getValue() == null || characteristic.getValue().length <= 0) ? "0 bytes" : GeneralCharacteristicParser.parse(characteristic);
    
                intent.putExtra(SOME_MORE,data);
    
    
            }
            else
            {
    
            }
            LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
            //LocalBroadcastManager.getInstance(this).sendBroadcast(intent1);
        }
    
  • I don't understand what you say here:

    in above code i tried to read characteristics from both services . also tried to read characteristics in list fashion(code is commented for the same). we have broadcast update function.

    You tried but it's successful or not ?? You have broadcast update function, what does that mean ?

    Please answer my question , what you do have when you call RxServiceHRS.getCharacteristics() to get the list ? And what was the UUID when you call "characteristic.getUuid()" ? Tell me what was exactly the " something garbage data " you saw.

  • the meaning of my statement is, i have tried to read characteristics in broadcast update function .but, TX_TS CHAR_UUID doesn't match with received characteristics. so, no getValue function is called in that block.it only match with TX_CHAR_UUID which mean it only read UART characteristics value in broadcast update function. i try to log value in enableTXnotification function,which is giving me below in log result

    BluetoothGattCharacteristic TxCharHRS = RxServiceHRS.getCharacteristic(TX_TSCHAR_UUID); Log.d("CHAR"," "+TxCharHRS);

    Log Result->android.bluetooth.BluetoothGattCharacteristic@609367b

    BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID); Log.d("CHAR"," "+TxChar);

    log result: android.bluetooth.BluetoothGattCharacteristic@ea7dc98]

    UUID i have used

    public static final UUID TX_TSCHAR_UUID = UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb"); public static final UUID RX_TSSERVICE_UUID = UUID.fromString("0000180D-0000-1000-8000-00805f9b34fb"); public static final UUID TX_CHAR_UUID = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e");

    i think garbage means: this value @609367b at characteristics log.

  • I would suggest you to try to read and write to the characteristic first. 609367b is not garbage data, it's an address in the memory, what do you expect to see? You won't see the UUID because to get the UUID you should call characteristic.getUuid() you should try to print that in the log.

    broadcastUpdate() is called when you get a notification, if you don't send a notification on HRS side (or if you don't enable notification for HRS) there will be no notification for the HRS characteristic.

    I suggest you to get familiar with HRS profile, know how to get characteristic, enable notification (write to CCCD), receive notification before you try to combine it with UART.

Related