nexussays / ble.net

Cross-platform Bluetooth Low Energy (BLE) library for Android, iOS, and UWP
Mozilla Public License 2.0
189 stars 51 forks source link

Automatically negotiate requestMtu on Android #42

Open callon22 opened 6 years ago

callon22 commented 6 years ago

Hi!

Is it possible to implement posibility to request MTU-size for android? See link below.

https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#requestMtu(int)

Best regards Niklas Carlberg

nexussays commented 6 years ago

Unfortunately this isn't a cross-platform API, e.g., iOS does this automatically under the covers.

I could perhaps do it automatically for Android or try to find some other way to expose the API, but I don't think it would be high priority. Are you having issues transferring large amounts of data?

callon22 commented 6 years ago

Hi! I see it as very important to be able to optimize transfer speeds when dealing with larger amount of data, on iOS its optimizes as you say but on Android its not.

If iOS do this automatic, could it not be nice if you do it automatic for Android?

prajaktashindeSilicus commented 5 years ago

Hi, Is this requestMtu on Android available now? I didn't find this method anywhere in the package. In my case, I'm getting 59 bytes length in the ios and 20 bytes in the android for the same BLE packet. I'm having issues transferring large amounts of data on android. Same is working on iOS. Need help in this urgently.

JoeBakalor commented 5 years ago

@prajaktashindeSilicus Just request a larger MTU from the peripheral side and Android will accept. This will work the same for iOS. What are you connecting to?

prajaktashindeSilicus commented 5 years ago

@prajaktashindeSilicus Just request a larger MTU from the peripheral side and Android will accept. This will work the same for iOS. What are you connecting to?

Hello JoeBakalor, Will you please explain me in more detailed? An example or syntax is appreciated.

JoeBakalor commented 5 years ago

@prajaktashindeSilicus What device are you connecting to? Nordic, cypress, etc? Did you write the firmware?

If you were using Nordic:

https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__ble__gatt.html?cp=5_1_6_2_12_9#ga4fd7e5c4607cba63f00b8bf9711c3ca3

https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__ble__gatt.html?cp=5_1_6_2_12_11#ga857b95d31c1b2454eb3ac70b96e096fd

Edit:

Some additional context. Either device (peripheral or central) involved in a BLE connection can request an update to the MTU. An MTU update doesn't need to be requested from the mobile phone, it can be requested by the peripheral side and the phone will typically accept as long as the requested length is supported by the device.

prajaktashindeSilicus commented 5 years ago

@JoeBakalor We don't have access to the peripheral device. We have not written the firmware. Our client has explicitly told us to raise the MTU on an Android device. I am looking for an implementation of request MTU-size for android from this ble.net package. @nexussays Will you please provide me with the details about request MTU-size for android?

ganesh-gawande commented 5 years ago

@JoeBakalor I am working with @prajaktashindeSilicus . Here are some more details which might help to get insights and help us.

BluetoothGatt class in .NET provides method RequestMtu to change the MTU from android code. Here is link for it. https://docs.microsoft.com/en-us/dotnet/api/android.bluetooth.bluetoothgatt.requestmtu?view=xamarin-android-sdk-9

As we have used this ble.net package, we are looking for exposed method from this package to change the MTU.

Another thing is - we can change the MTU only after connected with BLE device. We can write custom code for Xmarin android application, but as we are developing hybrid application we are looking to have same code for android and iOS.

Would it be possible that - this ble.net package support to change the MTU? If not - can you please guide for any other workaround?

As @prajaktashindeSilicus mentioned - for now it wont be possible to make changes in the firmware.

JoeBakalor commented 5 years ago

@ganesh-gawande There is no API access to change the MTU on iOS. iOS uses an MTU of 185 by default and when making a connection, automatically negotiates the MTU (Android does not - reason for this request) and uses the lesser of the supported MTU on the devices involved in the connection. In order to increase the MTU beyond 185 on iOS, the peripheral must request a larger size.

Would it be possible that - this ble.net package support to change the MTU? If not - can you please guide for any other workaround?

Not for iOS. You would need to write custom code for the Xamarin Android app as you mentioned.

As @prajaktashindeSilicus mentioned - for now it wont be possible to make changes in the firmware.

You should tell your client, there is no access to any API on the iOS side to request a larger MTU. They should consider this when writing the firmware. I would say it is your clients responsibility to manage the MTU on the firmware side since it is the only way to control the MTU size for both Android and iOS.