This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Write to variable length characteristic

Hello,

I have some code running that transfers binary data from an iPhone to a nRF51822 device (used for firmware upgrade).

I have used a variable length characteristic with a maximum length of 20 bytes. I then write "as often as possible" from an iOS application using CBCharacteristicWriteWithoutResponse to avoid having to wait for data before sending the next packet.

This is working ok on iPhone 4S, but on newer models the connection interval seems to be longer which means I need a long delay between each packet causing the transfer speed to drop significately.

I'm now trying to send bigger packets. I started by reconfiguring my characteristic to allow bigger writes (knowing that these would still be divided into the MTU size) and allowing write (with response).


    char_md.char_props.write_wo_resp = 1;
    char_md.char_props.write = 1;

    attr_md.vloc = BLE_GATTS_VLOC_USER;
    attr_md.vlen = 1;

    attr_char_value.init_len     = 1;
    attr_char_value.init_offs    = 0;
    attr_char_value.max_len      = 512;
    attr_char_value.p_value      = m_stream_buffer;

The problem is that iOS gets an error message when I try to write more than 20 bytes of data (using a CBCharacteristicWriteWithResponse).

Has anyone else tried this?

  • Current S110 does not support bigger MTU sizes, and to make writes of more than 20 bytes work, you'll therefore have to implement GATT Write Long as a GATT Server, for instance following this MSC. However, beware that this will not give you higher throughput in any way.

    You should note that (at least) iPhone 5S has an issue causing it to transfer at most 1 packet per interval, and this is most likely the cause of your slowdown, as you can see from this question. This issue should be fixed in a future version of iOS, but I can't really promise anything. Unfortunately, I'm not aware of any workaround for this problem.

  • Hi Ole,

    I am a bit confused. I saw here that S110 SoftDevice 6.0.0 supports long writes: devzone.nordicsemi.com/.../will-the-master-emulator-support-long-writes

    1. Is this not correct? And, how is this configured using the nRF51822 API?

    2. (However, I read somewhere else that Android 4.3 BLE API does not support long writes. Is that true of 4.4.x as well?)

    OTOH, I have been able to perform a read on a characteristic and successfully received data that is longer than 20 bytes (nRF51822 -> Android 4.4.2).

    1. Finally, do you have a concrete example on how to implement the queued write scheme you referenced in your previous post?

    Sorry if this question is redundant -- the information on some of these limitations isn't clearly spelled out either in a single post here or in the documentation.

    Thanks in advance, Paarvai

  • I'm not quite sure I understand what you're confused about. It's correct that S110 version 6.0.0 supports long writes, and such support can be implemented as shown in the MSC I linked to above. GATT Long Writes is basically just about doing multiple writes up to ATT_MTU-5 bytes each, and then executing all those writes with a single operation. As I said above, the ATT_MTU is fixed for current S110, at 23 B, so an actual Write Long operation would be multiple 18 B writes followed by one execute to "commit" them all. I'd recommend you to take a look at the Core Specification to understand how this works, specifically Volume 3, Part G, section 4.9.4.

    As far as I know, Android doesn't currently support long writes. Unfortunately, I also don't have a full example of implementing a long write, but please give it a go, and post a separate question if you have trouble. If so, I can try to look into making a quick example.

  • Hi Ole,

    Thanks for your quick response! I was confused because you had referenced a link on how to implement long writes at the application, while (based on other posts) I was under the impression S110 v6.0.0 supported this through some higher-level API mechanism. I will look into this more as needed and post in a separate thread if I have any problems.

    Thanks again, Paarvai

Related