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

Read custom characteristics value in multilink example [central]

Hello!

I have a problem with getting a value (uint8_t) from a characteristics.

I am using 2 nrf51422 boards, where one is a central and the other is a peripheral. I have modified the multilink example (peripheral) to make an additional characteristic that holds a value that I would like to read at the central unit. How do I do this?

From several posts here at the forum I found something about BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP... but I am not quite sure if that is the right way, and if so where and how to use it.

Help would be much appreciated.

/Christian

  • Let me know if the code from the peripheral is needed, for how I make the characteristic. I'll be happy to provide it.

  • Please have a look at this question.

    If you have the attribute handle of the characteristic value that you want to read you should use sd_ble_gattc_read().

  • Hi Petter, thank you for the respond.

    I've looked at the post you linked me and I have tried to implement it.

    In the client_handling.c file in the client_handling_ble_evt_handler() function i have made to new cases:

    case BLE_GATTC_EVT_CHAR_DISC_RSP: sd_ble_gattc_read(p_ble_evt->evt.gatts_evt.conn_handle,0x0000,0); break;

    case BLE_GATTC_EVT_READ_RSP: //DEBUG z = p_ble_evt->evt.gattc_evt.params.char_disc_rsp.chars[index].handle_value; z = p_client->client_acc_z_value; char buffer[20]; sprintf(buffer,"Value is: %d\n\r",z); debug_printf(buffer); break;

    I get one reading in my UART terminal, so my question is why does this only occur once? And how could I make it repeat it self? I want continuous reading as the value from the peripheral is changing.

    I have set the peripheral characteristic up to notify, so maybe I could utilize that?

    Thank you!

  • Hope that you can read the code. The format is not great. Also I'm the a super strong programmer yet, so the answer might be trivial for you.

    Looking forward to your reply.

  • I'm guessing that you only get the BLE_GATTC_EVT_CHAR_DISC_RSP event once, and because of this sd_ble_gattc_read() is only called once. You can call sd_ble_gattc_read() again when you get the BLE_GATTC_EVT_READ_RSP event. Then it would repeat itself, but you need to make sure that sd_ble_gattc_read() returns NRF_SUCCESS or 0x00000000. If it returns something else, you will not get the BLE_GATTC_EVT_READ_RSP event.

    Notifications are initiated by the server, or peripheral in your case, by calling sd_ble_gatts_hvx() in the server application. Then you will get the BLE_GATTC_EVT_HVX event in the client application. For the server to be able to send notifications, the client first has to enable them by writing 0x0001 to the CCCD of the characteristic you want to send notifications from. In client_handling.c this is done by notif_enable().

Related