This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Executing sd_ble_gatts_value_set will result in BLE_ERROR_INVALID_CONN_HANDLE

Hello.

I'm using nrf52832 (S132 v7.0.1, SDK v17.0.0) to develop peripheral roles.

I want to create a characteristic with the Read settings assigned and set the data to it. Therefore, I am using sd_ble_gatts_value_set, but it becomes BLE_ERROR_INVALID_CONN_HANDLE. The following code is the code that causes an error.ble_write_req is called after the characteristic is created.

// UUID Setting
#define ADV_UUID_BASE     {0x77, 0x77, 0x66, 0x66, 0x55, 0x55, 0x44, 0x44, 0x33, 0x33, 0x22, 0x22, 0x11, 0x11, 0x00, 0x00}
#define SERVICE_UUID_BASE {0xHH, 0xHH, 0xGG, 0xGG, 0xFF, 0xFF, 0xEE, 0xEE, 0xDD, 0xDD, 0xCC, 0xCC, 0xBB, 0xBB, 0xAA, 0xAA}

// Characteristic params
static ble_add_char_params_t add_char_params = 
{
    .uuid            = 0xYYYY,
    .uuid_type       = NULL,
    .max_len         = 248,
    .init_len        = 248,
    .is_var_len      = false,
    .char_props.read = 1,
    .read_access     = SEC_OPEN,
};

static uint16_t                 m_service_handle; /**< Handle of local service (as provided by the BLE stack).*/
static ble_gatts_char_handles_t m_char_handles;   /**< Handles of local characteristic (as provided by the BLE stack).*/

// Write Request
static void ble_write_req(void)
{
    ret_code_t        err_code;
    ble_gatts_value_t char_value;
    char *            test_value;

    test_value = "test";

    char_value.len     = sizeof(test_value);
    char_value.offset  = 0;
    char_value.p_value = (uint8_t *)&test_value;

    err_code = sd_ble_gatts_value_set(m_service_handle, m_char_handles.value_handle, &char_value);
    APP_ERROR_CHECK(err_code);
    
    return;
}

I don't know why it's an error. Can you tell me?

Best regards.

Related