Sending more than 8bits of data over bluetooth

Lynchosky gravatar image

asked 2013-06-28 16:24:58 +0100

updated 2013-06-28 18:57:27 +0100

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!

edit retag flag offensive close delete report spam


By the way, we'd be happy if you could mark one of the answers as accepted, instead of just marking the discussion resolved. :)

Ole Morten ( 2013-06-29 12:42:16 +0100 )editconvert to answer

4 answers

Sort by ยป oldest newest most voted
introiboad gravatar image

answered 2013-06-28 19:06:46 +0100

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,


edit flag offensive delete publish link more


I have two somethings that confused me: what will happen if I didn't send packets for a while and the chip didn't sleep then I send again packets will it write starting from data[0] or will complete on the array?

the same case but the chip in this case go to sleep and then I started to send again.

mohamed ( 2015-07-09 06:40:24 +0100 )editconvert to answer

I'm also asking about how to make the chip to erase the array of the data received from air every time it start receiving packets from air?

mohamed ( 2015-07-09 06:40:51 +0100 )editconvert to answer

Hi mohamed,

Please start a new thread with this question, since this does not seem to be related to the issue covered in this thread.

Carles ( 2015-07-09 10:08:22 +0100 )editconvert to answer
olha gravatar image

answered 2013-06-29 12:37:36 +0100

updated 2013-06-29 12:40:37 +0100

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.

edit flag offensive delete publish link more


Is there any way to check how many bytes were sent?

spizzak ( 2017-11-01 22:06:18 +0100 )editconvert to answer

NVM- I found it in p_evt_write->len

spizzak ( 2017-11-01 22:13:35 +0100 )editconvert to answer
Lynchosky gravatar image

answered 2013-06-28 19:22:54 +0100

nick2206 gravatar image

updated 2016-03-20 13:33:27 +0100

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

edit flag offensive delete publish link more
Lynchosky gravatar image

answered 2013-06-28 18:57:07 +0100

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!

edit flag offensive delete publish link more

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.

Ole Morten ( 2013-06-29 12:38:30 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Recent questions

Question Tools

1 follower


Asked: 2013-06-28 16:24:58 +0100

Seen: 1,935 times

Last updated: juni 28 '13