Comments (11)
Hi,
So there are 3 options how you can achieve it:
- 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.
- 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).
- 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.
I'll add support for this feature soon.
from android-ble-library.
This should now work with version 2 of the library.
from android-ble-library.
how can I send more that 20 bytes over BLE in swift 3 . I am using write without response .
from android-ble-library.
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.
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.
Hi, please open a new issue. Describe what version of the library are you using.
from android-ble-library.
@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.
Can't be done. Support for higher mtu was added in Lollipop.
from android-ble-library.
Hi,
So there are 3 options how you can achieve it:
- 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.
- 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).
- 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.
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)
- Is there any adaptation for Android 14? HOT 1
- What would cause GATT services to be invalidated on previously bonded peripherals? HOT 2
- Null reference exception when calling disconnect HOT 2
- Sometimes onServiceDiscoverd is not called when connecting. HOT 1
- Samsung Tab S6 Lite: Connection Parameter Negotiation HOT 1
- Catch SecurityException from setCharacteristicNotification HOT 2
- NullPointerException android.bluetooth.BluetoothGattServer.cancelConnection(android.bluetooth.BluetoothDevice)' on a null object reference HOT 3
- Library DefaultMtuSplitter is splitting incorrectly for android OS 14 HOT 8
- How to Catch Exception with RequestFailedException HOT 1
- Ask a question, thank you HOT 1
- Want to get the characteristic on which the data was received for the characteristics I have subscribed to get notified for HOT 2
- Concurrent modification exception while notifying device disconnected
- Disconnect not working on various Samsung devices HOT 2
- No response from writeCharacteristic HOT 5
- Question: Will this allow me to send HCI Level Commands? HOT 1
- I stoped receiving notifications even when i have still not get all data HOT 23
- Sometimes causing system Bluetooth to crash. HOT 4
- Notification does not clear after setup a device HOT 3
- Connection interval changes on its own HOT 3
- OTA upgrade problem HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-ble-library.