react-native-ble-manager
react-native-ble-manager copied to clipboard
iOS: Error Domain=CBATTErrorDomain Code=13 "The value's length is invalid." UserInfo={NSLocalizedDescription=The value's length is invalid.}
Tell us which versions you are using:
- react-native-ble-manager v6.2.1
- react-native v0.42.3
- iOS/Android v - iOS 11
Expected behaviour
Try to write to device, The iOS device should write to the ble device.
Actual behaviour
I get an error:
Error Domain=CBATTErrorDomain Code=13 "The value's length is invalid." UserInfo={NSLocalizedDescription=The value's length is invalid.}
Same writes work well on Android, and also worked well on iOS 10..
any idea?
Probably the value you write is too long.
Hey,
I just write the value 0, so i don't think that's the case. also the same thing worked well in iOS 10 + working now in Andorid.
Try to debug on xcode, it's strange.
I am having a similar issue it used to work on our previous version of the code (since then we have updated to ios11 and new Xcode so i am not sure which caused it to break). I am not even using react and just standard BLE core bluetooth api so i think something changed in the BLE software stack.
Error Domain=CBATTErrorDomain Code=13 "The value's length is invalid." UserInfo={NSLocalizedDescription=The value's length is invalid.}
I have the same problem. Please suggest a fix
Hi, got any fix? @marcosinigaglia
Hi @sarangpm18 , try to debug and solve, I never had this problem.
I am also facing same issue. Please suggest some solution. I think because of this issue, I am not able to transfer data to my ble device.
Hi @nehasharma1101 , I can't reproduce your problem.
This is the code and im getting this error var data = this.convertStringToByteArray("Hello");
setTimeout(() => {
BleManager.startNotification(
peripheral.id,
peripheral.advertising.serviceUUIDs[0],
charactersitic[0].characteristic
)
.then(() => {
console.log(
"Started notification on " + peripheral.id,
peripheral.advertising.serviceUUIDs[0],
charactersitic[0].characteristic
);
setTimeout(() => {
BleManager.write(
peripheral.id,
peripheral.advertising.serviceUUIDs[0],
charactersitic[0].characteristic,
data
// ["01100110", "01101111", "01101111"]
// data1.length
).then(() => {
console.log("Writed NORMAL crust");
BleManager.write(
peripheral.id,
peripheral.advertising.serviceUUIDs[0],
charactersitic[0].characteristic,
data
// ["01100110", "01101111", "01101111"]
// data1.length
).then(() => {
console.log(
"Writed 351 temperature, the pizza should be BAKED"
);
});
});
}, 500);
})
.catch(error => {
console.log("Notification error", error);
});
}, 200);
Hi @nehasharma1101 , the example code is not general, you have to know in which service/characteristic to write, the format, etc.
@marcosinigaglia @nehasharma1101 Hello guys any possible to write image on printer Please help me..
I found a solution: I must decode UTF8 string before writing out.
so, change
const { stringToBytes } = require('convert-string');
const data = stringToBytes('myText')
await BleManager.write(connectedDeviceId, serviceUUID, characteristicUUID, data, 1_000_000);
to
import utf8 from 'utf8';
const { stringToBytes } = require('convert-string');
const data = stringToBytes(utf8.encode('myText'))
await BleManager.write(connectedDeviceId, serviceUUID, characteristicUUID, data, 1_000_000);