When I call sd_ble_gatts_hvx() it returns 0x3400 and I'm not sure why. The error indicates the sum of these three errors:
NRF_ERROR_STK_BASE_NUM (0x3000)
NRF_GATTS_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x400)
BLE_ERROR_GATTS_INVALID_ATTR_TYPE (NRF_GATTS_ERR_BASE + 0x000)
so I think it's telling me "Invalid attribute type." I'm not sure why?
set_temp() is called on a one second timer, but only if connected (tracked by the BLE_GAP_EVT_DISCONNECTED and BLE_GAP_EVT_CONNECTED events).
One thing I wasn't sure about was setting up the characteristic. The char_props for indicate and notify are both set to false, but if I set either one of them to true I get an app exception on initialization. I checked the blinky app, though, and the don't set those fields at all (meaning the memset() sets them to zero).
This is with SDK 17.0.2 and a DK board.
void rv_char_init(rv_service_t *service) {
uint32_t err_code;
ble_add_char_params_t add_char_params;
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = BLE_UUID_RV_TEMP;
add_char_params.uuid_type = service->uuid_type; /* BLE_UUID_TYPE_BLE (16 bit) or BLE_UUID_TYPE_VENDOR_BEGIN (128 bit) */
add_char_params.init_len = sizeof(uint8_t);
add_char_params.max_len = sizeof(uint8_t);
add_char_params.char_props.read = true;
add_char_params.char_props.write = true;
add_char_params.char_props.notify = false;
add_char_params.char_props.indicate = false;
add_char_params.is_value_user = false;
add_char_params.read_access = SEC_OPEN;
add_char_params.write_access = SEC_OPEN;
err_code = characteristic_add(service->service_handle, &add_char_params, &service->temp_char_handle);
APP_ERROR_CHECK(err_code);
}
ret_code_t set_temp(uint16_t conn_handle, rv_service_t * service, uint8_t newValue)
{
ble_gatts_hvx_params_t params;
uint16_t len = sizeof(newValue);
ret_code_t err_code;
memset(¶ms, 0, sizeof(params));
params.type = BLE_GATT_HVX_NOTIFICATION;
params.handle = service->temp_char_handle.value_handle;
params.p_data = &newValue;
params.p_len = &len;
err_code = sd_ble_gatts_hvx(conn_handle, ¶ms);
return err_code;
}