react-native-ble-manager icon indicating copy to clipboard operation
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.}

Open melkayam92 opened this issue 7 years ago • 13 comments

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?

melkayam92 avatar Nov 29 '17 17:11 melkayam92

Probably the value you write is too long.

marcosinigaglia avatar Nov 29 '17 17:11 marcosinigaglia

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.

melkayam92 avatar Nov 29 '17 17:11 melkayam92

Try to debug on xcode, it's strange.

marcosinigaglia avatar Nov 29 '17 17:11 marcosinigaglia

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.}

TaiPhamD avatar Jan 03 '18 07:01 TaiPhamD

I have the same problem. Please suggest a fix

IshwaryaRaja avatar Mar 23 '18 05:03 IshwaryaRaja

Hi, got any fix? @marcosinigaglia

sarangpm18 avatar Jan 29 '19 09:01 sarangpm18

Hi @sarangpm18 , try to debug and solve, I never had this problem.

marcosinigaglia avatar Jan 29 '19 09:01 marcosinigaglia

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.

nehasharma1101 avatar Feb 21 '20 10:02 nehasharma1101

Hi @nehasharma1101 , I can't reproduce your problem.

marcosinigaglia avatar Feb 21 '20 10:02 marcosinigaglia

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);

nehasharma1101 avatar Feb 21 '20 11:02 nehasharma1101

Hi @nehasharma1101 , the example code is not general, you have to know in which service/characteristic to write, the format, etc.

marcosinigaglia avatar Feb 21 '20 11:02 marcosinigaglia

@marcosinigaglia @nehasharma1101 Hello guys any possible to write image on printer Please help me..

FazilMuhammed avatar Oct 12 '20 07:10 FazilMuhammed

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);

acro5piano avatar Aug 17 '21 14:08 acro5piano