Skip to content

reading binary data from bluetooth classic #348

Description

@learncodingforweb

Mobile Device Environment
Provide a list of operating systems on which this issue is relevant.

  • Device: Android 10
  • OS: API 29

Application Environment
Provide information about your development environment:

  • React Native version: 0.78.0
  • RN Bluetooth Classic version: 1.73.0-rc.13

Describe the bug
I have Connected HC-06 device with computer using USB to TTL converter. If i send string data to android device, then i am able to see it correctly on android phone. But if i try to send binary data e.g. [178, 13, 10] on bluetooth device. then on android phone i am not able to see it correctly.

useEffect(() => {
    let sub: BluetoothEventSubscription | undefined;
    if (connectionStatus === 'connect') {
      sub = device?.onDataReceived((event) => {
        const data = event.data;
        const uint8Array = new Uint8Array(
           [...data].map((char) => char.charCodeAt(0)),
         );
        console.log('reieved data', uint8Array, 'len', uint8Array.length);
      });
    }
    return () => {
      sub?.remove();
    };
  }, [device, connectionStatus]);
[00:02:53] I | ReactNativeJS ▶︎ 'reieved data', { '0': 115, '1': 103, '2': 61, '3': 61, '4': 10 }, 'len', 5

[00:02:53] I | ReactNativeJS ▶︎ 'reieved data', { '0': 68, '1': 81, '2': 111, '3': 61, '4': 10 }, 'len', 5

Note I am connecting to bluetooth device using
device.connect()

Expected behavior
Should be able to get data [178, 13, 10], In other words, how to enable binary data reading?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions