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

  • @Shrikant: Please be more specific on the issue you have. My suggestion is to modify the UartService.java to add the HRS service and characteristic in. If you simply create 2 service similar to UartService, it won't work. Be aware that the "Android's service" is not the same as Bluetooth service. One Android service can be modified to handle several BLE services.

  • I need UART Service and HRS service both data at a same time. to get UART profile data, i have accessed service and characteristics in enableTXNotification() function in UARTService.java I have same tried with HRS profile in same function , but it is not working.

    sample code below:

    public void enableTXNotification()
        {
            try {
            BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID);
            if (RxService == null) {
                showMessage("Rx service not found!");
                broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
                return;
            }
            BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID);
            if (TxChar == null) {
                showMessage("Tx charateristic not found!");
                Log.d("no tx char ","Tx charateristic not found!");
                broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
                return;
            }
                mBluetoothGatt.setCharacteristicNotification(TxChar,true);
                BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
                descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                mBluetoothGatt.writeDescriptor(descriptor);
    
            BluetoothGattService RxServiceHRS = mBluetoothGatt.getService(RX_TSSERVICE_UUID);
            if (RxServiceHRS == null) {
                showMessage("Rx service not found!");
                broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
                return;
            }
            BluetoothGattCharacteristic TxCharHRS = RxService.getCharacteristic(RX_TSCHAR_UUID);
            if (TxCharHRS == null) {
                showMessage("Tx charateristic not found!");
                Log.d("no tx char ","Tx charateristic not found!");
                broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
                return;
            }
    
  • Have you checked with this call: BluetoothGattService RxServiceHRS = mBluetoothGatt.getService(RX_TSSERVICE_UUID);

    you receive anything ? Make sure the RX_TSSERVICE_UUID is matched with your HRS service. How did you configure your Gatt server ? Please post a screenshot when you do service discovery with nRFConnect.

  • Please see this .. i have problem with this

    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 have tried to read characterictics and it is showing null. when i debug the code it is showing charactecteristcs as null value. only UART Characteristic is notified and read

  • Please answer my questions. You need to get RxServiceHRS first before you get the characteristic.

Related