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

Android Application crash while enable notify

I have an external temperature on my nRF51 DK. I would like to read the value of the temperature on my mobile device(Android).

I am able to read the temperature on the MCP. But when I try to read the temperature on my Android device it will crash the app.

This is the line where the error occurs:

descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

Here the set up for the temperature characteristic on the nRF51 DK:

char_md.char_props.read   = 1;
char_md.char_props.write  = 1;
char_md.p_char_user_desc  = NULL;
char_md.p_char_pf         = NULL;
char_md.p_user_desc_md    = NULL;
char_md.p_cccd_md         = NULL;
char_md.p_sccd_md         = NULL;

CCCD is standing for notification if I understand that right. So do I have to set the CCCD? But if it works on the MCP, then it should also work with the mobile device...

Or is there another reason why the application will crash when I enable the notifcation?

Parents
  • Reading is not the same thing as notification. Reading means read, I'm sure you can read the value, I'm sure the MCP just reads the value. Notification means that value changes are sent out to the client (as long as you write the code to send the notifications yourself).

    I would expect the MCP just does a read, notes that the characteristic does not have notifications and so it doesn't try to set up for notify. In your BTLE android code you are trying to notify something which isn't set up for notification. That sounds like a perfectly reasonable reason for the app crashing, I assume (is that Java) it's throwing an exception at you. I suspect there is some method on the descriptor in that app code which tells you whether notifications are available and if you check it, you'll find they are not.

    Either do reads, not notifies, or add the cccd to the descriptor to make it notifyable (and then add the code to send out notifications).

    The heart rate monitor service demo code shows this.

Reply
  • Reading is not the same thing as notification. Reading means read, I'm sure you can read the value, I'm sure the MCP just reads the value. Notification means that value changes are sent out to the client (as long as you write the code to send the notifications yourself).

    I would expect the MCP just does a read, notes that the characteristic does not have notifications and so it doesn't try to set up for notify. In your BTLE android code you are trying to notify something which isn't set up for notification. That sounds like a perfectly reasonable reason for the app crashing, I assume (is that Java) it's throwing an exception at you. I suspect there is some method on the descriptor in that app code which tells you whether notifications are available and if you check it, you'll find they are not.

    Either do reads, not notifies, or add the cccd to the descriptor to make it notifyable (and then add the code to send out notifications).

    The heart rate monitor service demo code shows this.

Children
No Data
Related