-
-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request MTU weird behaviour #1212
Comments
Weird, i see you're using version ^11.3.2 which can be any version newer than that, can you make sure to install version react-native-ble-manager version: "11.5.2" and do a ./android/gradlew clean for a full library refresh and check if the issue is still happening? |
Done, same results. if (this.discoveredDevicesIDs.size === 0) {
throw new Error('No devices discovered');
}
const deviceID = Array.from(this.discoveredDevicesIDs)[0];
await BleManager.connect(deviceID);
console.log('Connected to', deviceID);
await new Promise(resolve => setTimeout(resolve, 2000));
await BleManager.requestMTU(deviceID, 232);
console.log('MTU requested');
Alert.alert('MTU requested'); and it works like a charm. |
Issue Description: When I run my app on devices with Android 13 or lower, I receive the full data from my Bluetooth device. However, when running the same app on an Android 14 device, the data received from the Bluetooth device is truncated. Despite seeing "MTU size changed to 517 bytes" in the logs on both Android 13 and Android 14, the issue persists only on Android 14. I'm using "react-native-ble-manager": "^11.5.3". Please provide a solution urgently. Code Example: import BleManager from 'react-native-ble-manager'; const connectPeripheral = async (peripheral, connect, save) => {
} catch (error) { |
@akiannillo There is some performance issue in this module. It cannot work as expected. I think you should create your own module. I am stuck at a point too. Where nrf connect app performs well and is able to receive data in 100ms. Whereas, in this module, it sends disconnects. This module total **** me up. |
Thats a behavior that changed on Android Bluetooth since 14.
Thats a behavior change in the bluetooth not in the library itself, take a look on https://developer.android.com/about/versions/14/behavior-changes-all for further details. Something that i had to fix in order to work with Android 14 devices. |
@rahulp9538 that fixes your MTU negotiation size. |
Can you provide a minimal repro that shows this perfomance issue? |
const connectPeripheral = async (peripheral: Peripheral, connect: boolean, save: boolean) => {
}; LOG Peripheral exists in the list. I am using "react-native-ble-manager": "^11.5.3" and Google Pixel 5 phone with Android 14 |
Not sure why you're having this problem, i have a Android 14 device and can safely operate MTU size. /**
* Adds a notification listener.
* @param value
* @param peripheral
* @param characteristic
* @param service
*/
onNotification(id, serviceId, characteristicId, onNotify, onSuccess, onError) {
console.info(
`[BLE] Starting GATT notification ${serviceId}/${characteristicId}`
);
serviceId = serviceId.toLowerCase();
characteristicId = characteristicId.toLowerCase();
const shortServiceId = serviceId.split("-")[0].substr(-4);
const shortCharacteristicId = characteristicId.split("-")[0].substr(-4);
/**
* When characteristic changes.
* @param value
* @param peripheral
* @param characteristic
* @param service
*/
function onCharacteristicChange({
value,
peripheral,
characteristic,
service,
}) {
if (peripheral === id) {
let isSameCharacteristic = false;
let isSameService = false;
// Characteristic
if (characteristic.length === 4) {
isSameCharacteristic =
characteristic.toLowerCase() === shortCharacteristicId;
} else {
isSameCharacteristic =
characteristic.toLowerCase() === characteristicId;
}
// Service
if (service.length === 4) {
isSameService = service.toLowerCase() === shortServiceId;
} else {
isSameService = service.toLowerCase() === serviceId;
}
if (isSameService && isSameCharacteristic) {
onNotify(value);
}
}
}
if (Platform.OS !== "ios") {
BleManager.requestMTU(id, 185)
.then(function (mtu) {
console.log("MTU size changed to " + mtu + " bytes");
})
.catch((error) => {
console.log(error);
});
}
let listener = BleManagerEmitter.addListener(
"BleManagerDidUpdateValueForCharacteristic",
onCharacteristicChange
);
BleManager.startNotification(id, serviceId, characteristicId)
.then(function () {
onSuccess();
})
.catch(function (err) {
console.error(err);
onError(err);
});
return function () {
console.info(
`[BLE] Stopping notification ${serviceId}/${characteristicId}`
);
BleManager.stopNotification(id, serviceId, characteristicId);
listener.remove();
};
}
// When notification needed
const unsubscribe = onMonitor(id, serviceId, characteristicId, onNotify, onSuccess, onError);
// Afterwards
unsubscribe(); // Stops notification safely |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
I saw there are some closed issues about this but they have been closed before an actual solution.
Bug Description
await BleManager.requestMTU("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", 512)
never returns.BleManager.requestMTU("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", 512).then(...
works on Android 14 but not Android 13.To Reproduce
Code used to reproduce the error
on either Android 13 or 14
on Android 13
Expected behavior
on either Android with await: 'MTU requested' printed on console
on Android 13 with then: either 'MTU size changed to' or 'Error requesting MTU' printed on console
Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: