Giter VIP home page Giter VIP logo

Comments (11)

philips77 avatar philips77 commented on August 16, 2024 2

Hi,
So there are 3 options how you can achieve it:

  1. You may request higher MTU from the phone using this method. MTU (Maximum Transfer Unit) is the size of the packet that can be sent using one write operation (it may be split into multiple packets on lower layer if DLE (Data Length Extension) is not uses, but that's transparent for the application). Highest MTU supported by Android (Lollipop and newer only) is 517 (you always deduct 3 bytes from MTU to get the max packet size), but it actually depends on the target device whether it supports higher MTUs, or not, and what is the max value. Usually max MTU is around 180-250 if they are supported by peripherals. What you can do is you can request 517 and you'll get the max supported value using this callback. The default MTU is 23 - that means you may send 20 bytes per packet.
  2. If you are using Write With Response (write type WRITE_TYPE_DEFAULT in Android), and your device supports Long Write (that means it reserves more bytes in a buffer for each write), you may just write longer packet despite having shorter MTU. Android will automatically chunk data into at-most-MTU-size packets and will sent it to the peripheral. For you it will be transparent. This, however, does not work with Write Without Response (WRITE_TYPE_NO_RESPONSE).
  3. If your device does not support higher MTUs, or you are using Write Without Response, or Long Write is not possible, you have to split your data into at most 20-bytes chunks. Have a look at this example. In nRF Toolbox UART sample, when the data are to be written using Write Without Response, they are chunked. After each chunk is sent the buffer window is moved MTU-bytes right and next part is sent (see here).

Right now the BLE library does not support sending longer packets automatically, but I guess it should, so I'll add this functionality soon. I also plan to add some more related features (callbacks, etc).

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024 2

I'll add support for this feature soon.

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

This should now work with version 2 of the library.

from android-ble-library.

sreechary avatar sreechary commented on August 16, 2024

how can I send more that 20 bytes over BLE in swift 3 . I am using write without response .

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

Hmm... It's an Android library, not iOS. But to answer your question, your device needs to support longer mtu. iOS will automatically request high mtu immediately after connecting. Use CBPeripheral.maximumWriteValueLength(for:) to get the maximum supported length.

from android-ble-library.

bytewired avatar bytewired commented on August 16, 2024

Hi, I send 2 packages but after the first package, flag mOperationInProgress became true and when I send the second package, package doesn't sending because mOperationInProgress == true. How I can fix it?

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

Hi, please open a new issue. Describe what version of the library are you using.

from android-ble-library.

balazsnemeth avatar balazsnemeth commented on August 16, 2024

@philips77 , even with the latest vestion of the lib, the MTU exchange is not supported for Android 4 (like KitKat), right?

Here is a exchange flow of Nordic SoftDevice S132 , the requestMtu does implement this? Do you know any way to support large MTU for devices running Android 4.4 or lower (basically for SDK 19 and 20)?

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

Can't be done. Support for higher mtu was added in Lollipop.

from android-ble-library.

vamshik113 avatar vamshik113 commented on August 16, 2024

Hi,
So there are 3 options how you can achieve it:

  1. You may request higher MTU from the phone using this method. MTU (Maximum Transfer Unit) is the size of the packet that can be sent using one write operation (it may be split into multiple packets on lower layer if DLE (Data Length Extension) is not uses, but that's transparent for the application). Highest MTU supported by Android (Lollipop and newer only) is 517 (you always deduct 3 bytes from MTU to get the max packet size), but it actually depends on the target device whether it supports higher MTUs, or not, and what is the max value. Usually max MTU is around 180-250 if they are supported by peripherals. What you can do is you can request 517 and you'll get the max supported value using this callback. The default MTU is 23 - that means you may send 20 bytes per packet.
  2. If you are using Write With Response (write type WRITE_TYPE_DEFAULT in Android), and your device supports Long Write (that means it reserves more bytes in a buffer for each write), you may just write longer packet despite having shorter MTU. Android will automatically chunk data into at-most-MTU-size packets and will sent it to the peripheral. For you it will be transparent. This, however, does not work with Write Without Response (WRITE_TYPE_NO_RESPONSE).
  3. If your device does not support higher MTUs, or you are using Write Without Response, or Long Write is not possible, you have to split your data into at most 20-bytes chunks. Have a look at this example. In nRF Toolbox UART sample, when the data are to be written using Write Without Response, they are chunked. After each chunk is sent the buffer window is moved MTU-bytes right and next part is sent (see here).

Right now the BLE library does not support sending longer packets automatically, but I guess it should, so I'll add this functionality soon. I also plan to add some more related features (callbacks, etc).

Hi,
As you mentioned if DLE is not in use the long packet will be broken down in fragments in link layer. Is there a way to enable LE DLE in android or is there any phones that come with DLE enabled? Peripheral is however requesting for LL_Length_Req and android is responding with Unknown Request.

from android-ble-library.

philips77 avatar philips77 commented on August 16, 2024

No, this can't be enabled on Android. DLE support was added in Android 6, as far as I remember, and most newer phones do use it. Phones updated to 6 may not support this feature. There is also no API to check if DLE is working or now, other than just trying to calculate the bandwidth and estimating based on that.

from android-ble-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.