Hi, I've the need to write a characteristic value of 65 bytes, from my central device (iPhone/iPad) to a nRF51822 peripheral device, so I was looking at this document for how to implement the write long characteristic on nRF51822.
So in my service implementation file I have added:
void ble_actrl_on_ble_evt(ble_actrl_t * p_actrl, ble_evt_t * p_ble_evt)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
on_connect(p_actrl, p_ble_evt);
break;
case BLE_GAP_EVT_DISCONNECTED:
on_disconnect(p_actrl, p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
printf("GATTS_EVT_WRITE\r\n");
on_write(p_actrl, p_ble_evt);
break;
case BLE_EVT_USER_MEM_REQUEST:
err_code = sd_ble_user_mem_reply(p_actrl->conn_handle, &m_dhc_mem_block);
if (err_code != NRF_SUCCESS) {
printf("ERROR sd_ble_user_mem_reply: %u\r\n", (unsigned int)err_code);
} else {
printf("USER_MEM_REQUEST OK\r\n");
}
break;
case BLE_EVT_USER_MEM_RELEASE:
printf("USER_MEM_RELEASE\r\n");
break;
default:
// No implementation needed.
break;
}
}
And inside the on_write function, I check which characteristic has been written using the value_handle like this:
static void on_write(ble_actrl_t * p_actrl, ble_evt_t * p_ble_evt)
{
uint32_t err_code;
ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
if(p_evt_write->handle == p_actrl->dhc_handles.value_handle)
{
printf("LONG CHARACTERISTIC WRITTEN!\r\n");
}
}
On the output console I get:
USER_MEM_REQUEST OK GATTS_EVT_WRITE USER_MEM_RELEASE
so it seems that the attribute validation has been passed, but I don't get the "LONG CHARACTERISTIC WRITTEN" printed on the console, maybe the handle that I check is not correct? Which handle should I check when dealing long characteristic writes?
Thanks for any answer. Samuele.