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

Sending more than 8bits of data over bluetooth

I'm looking into the service creation portion of BLE, and I've made it pretty far. But one problem that I'm running into is sending more than 8 bits of data at a time back to the board. The service example provided, Immediate Alert Service (IAS), can only send 8 bits at a time. I've dug fairly deep into how they send data, and I hit that 8 bit wall every time. Is this a restriction to all services or only the examples?

So in short, is there an easy way to send more data that I am missing?

Thanks in advance!

  • I found out how to send more data.

    In ble_gatts.h there is this struct:

    /@brief Event structure for BLE_GATTS_EVT_WRITE. */ typedef struct { uint16_t handle; /< Attribute Handle. */ uint8_t op; /< Type of write operation, see @ref BLE_GATTS_OPS. */ ble_gatts_attr_context_t context; /< Attribute Context. */ uint16_t offset; /< Offset for the write operation. */ uint16_t len; /< Length of the incoming data. / uint8_t data[8]; /< Incoming data, variable length. / } ble_gatts_evt_write_t;

    The bolded line is the line that I had to change in order to send more data. They initially had it set to a one element array(data[1]), but I needed to send more data. As far as I can tell you are free to change the size of that array to your needs.

    Hope this helps!

  • Hi Alex,

    First of all, I would like to point out that all headers included in the SoftDevice package, and more specifically those prefixed by ble_, are system headers and should not be modified at all.

    The "data" member of the ble_gatts_evt_write_t is meant as a placeholder for the address in memory where the array containing the data received over the air lives.

    This means that, without modifying the header file, you can simply get the data by accessing:

    ble_gatts_evt_write_t::data[0 .. len-1]

    So assuming that ble_gatts_evt_write_t::len was 10, you could access:

    ble_gatts_evt_write_t::data[0] .. ble_gatts_evt_write_t::data[9]

    Hope that helps,

    Carles

  • I was wary about modifying it, and I didn't understand that the data[1] was just a pointer. Thanks for the info!

  • As you can see in the Core Specification, Volume 3, part F, sections 3.4.4 to 3.4.8, depending on the operation you do, you can transmit up to 20 (write/notify/indicate) or 22 (read) bytes in each operation over BLE.

    The only thing you have to do in your service code to do this is to make sure that the length of your characteristic is set correctly. There is a init_len and max_len field in the ble_gatts_attr_t field that sets the initial and max length of a characteristic, and additionally a vlen field in ble_gatts_attr_md_t that sets whether or not a characteristic has variable length.

    Once you have set these parameters correctly, you can send a notification with length up to 20 bytes. As Carles notes in his answer, if you receive a write event, you can access the remaining bytes without changing the header file by just indexing the data field accordingly.

  • As Carles says above, this is wrong, and should not be done. The softdevice header files should never be modified. Please see my other answer for a better answer.

Related