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

Parents Reply Children
  • 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().

  • @Petter ,

    i wanted to read my char value i tried this but it is returning same value even if the char is changed .

    ble_gatts_hvx_params_t hvx_params;
        memset(&hvx_params, 0, sizeof(hvx_params));
        
    
           hvx_params.handle = p_our_service->mycharHandler.value_handle;
            hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
            hvx_params.offset = 0;
            hvx_params.p_len = &len;
            //hvx_params.p_data = (uint8_t *)temperature_value;
            sd_ble_gatts_hvx(p_our_service->conn_handle, &hvx_params);
          
              printf(" new char:  %d\r\n", *hvx_params.p_data);
    

    i wanted to use this function to read my char but not sure how using sd_ble_gattc_read is it possible to use sd_ble_gattc_read by passing "mycharHandler" ? can you provide me a sudo code for this ?

    thanks

Related