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

getting gatts value with nRF51822

Hi There,

I want the functionality of my device to change when a value is written to a gatt characteristic. I've written an event handler that gets called whenever a write is made to the characteristic. This works correctly, but the problem is that I then can't get the value of the characteristic within this handler. I'm trying to use the sd_ble_gatts_value_get() function, and every time it is called the chip gets reset.

Thanks for any help you can give.

Here's my code:


void hex_evt_handler(ble_hex_t * p_hex, ble_hex_evt_t * p_ble_evt)
{

    uint32_t err_code = NRF_SUCCESS;

    uint8_t new_hex_status = 0;
    uint16_t len = sizeof(uint8_t);

    err_code = sd_ble_gatts_value_get(p_hex->hex_status_handles.value_handle,
	                                      0,
	                                      &len,
	                                      &new_hex_status);

    if (err_code != NRF_SUCCESS)
    {
        return;
    }

    ...
}


Parents
  • Hi Morgan,

    I don't know what the ble_hex_evt_t and ble_hex_t is.

    The best way to get the data from the write event is doing this when receiving the ble_evt_t

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GATTS_EVT_WRITE:
            {
                uint8_t * p_data = p_ble_evt->evt.gatts_evt.params.write.data;
                uint16_t length = p_ble_evt->evt.gatts_evt.params.write.len;
    
                new_hex_status = p_data[0];
            }
            break;
        default:
            break;
    }
    

    Update 18.12.2015: Added pointer declaration to the p_data

Reply
  • Hi Morgan,

    I don't know what the ble_hex_evt_t and ble_hex_t is.

    The best way to get the data from the write event is doing this when receiving the ble_evt_t

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GATTS_EVT_WRITE:
            {
                uint8_t * p_data = p_ble_evt->evt.gatts_evt.params.write.data;
                uint16_t length = p_ble_evt->evt.gatts_evt.params.write.len;
    
                new_hex_status = p_data[0];
            }
            break;
        default:
            break;
    }
    

    Update 18.12.2015: Added pointer declaration to the p_data

Children
Related