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

BLE observer not called for data of more than one byte

Hey all,

Custom service, but my first where I am looking for more than one byte of data written to a characteristic at a time - in this case 8 bytes.  So everything looks good - I see the service and characteristics fine, I can write to the characteristic, but if I use nRF Connect to write anything other than a byte (or BYTE in the app) I get no response at all.  If I write a single BYTE I see it come over and my observer catches it, but nothing for BYTE ARRAY or for UINT32_T, for example.  Have I set something up incorrectly?  Or maybe I'm using nRF Connect wrong?

I see this in ble_gatts.h:

uint8_t                     data[1];            /**< Received data. @note This is a variable length array. The size of 1 indicated is only a placeholder for compilation.
                                                       See @ref sd_ble_evt_get for more information on how to use event structures with variable length array members. */

and I assume that data can be 8 bytes long since it says data is variable length, but maybe that is incorrect?

Here's the code that should get hit (and is hit when I write one byte to the characteristic):

void ble_serv_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
    ble_serv_t * p_serv = (ble_serv_t *)p_context;

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            p_serv->conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            break;

        case BLE_GATTS_EVT_WRITE:
			{
				ble_gatts_evt_write_t const * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;

				if (   (p_evt_write->handle == p_serv->serv_handles.value_handle)
					&& (p_evt_write->len    == SERV_DATA_LENGTH) // == 8
					&& (p_serv->evt_handler  != NULL))
				{
					p_serv->evt_handler(p_ble_evt->evt.gap_evt.conn_handle, p_serv, p_evt_write); // datetime is in p_evt_write->data
				}
			}
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            p_serv->conn_handle = BLE_CONN_HANDLE_INVALID;
            break;

        default:
            break;
    }
}

Related