4

I'm trying to communicate with a bluetooth LE device, but have been told I need to "authenticate" before being able to read / write data. The hardware dev has told me that the device sends a key to the recipient, and I need to reply with 12000000000000000000000000. He has tested this successfully with the NRF Connect desktop app (but I need to replicate this in react native).

I've tried sending 12000000000000000000000000 (converted to base64) to the device's notify characteristic as soon as I connect to it using the code below:

const Buffer = require("buffer").Buffer;
const loginString = "12000000000000000000000000";
const hexToBase64 = Buffer.from(loginString).toString("base64");

characteristics[0].writeWithResponse(hexToBase64).then(()=>...)

However, I keep getting "GATT exception from MAC address C7:7A:16:6B:1F:56, with type BleGattOperation{description='CHARACTERISTIC_WRITE'}" even though the code executes properly (no catch error).

I've looked through the react-native-ble-plx docs and still haven't found a solution to my problem, any help would be apreciated!

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
AWE
  • 64
  • 4
  • 14

2 Answers2

0

In case the BLE device runs a Authorization Control Service(ASC)(UUID 0x183D), your application would play a Client-role. In ACS, there are two characteristics that a client is able to write to: "ACS Data In"(UUID 0x2B30) and "ACS Control Point"(UUID 0x2B3D), while only the "ACS Data Out Notify" characteristic(UUID 0x2B31) has a Notify-property which would be initiated by the Server but enabled by the Client. Basically, the data structure in these characteristics are little-endian in the payload, and converting the key to little-endian before the write operation may work. These are what I known from my recently studying on BLE documents and may these help.

user6099871
  • 131
  • 1
  • 4
-1

The data type for writing to a characteristic is typically an array of bytes.

Try converting the string to a byte array, something like this:

const loginString = "12000000000000000000000000";
const byteArray = Array.from(loginString, c => c.charCodeAt(0));
characteristics[0].writeWithResponse(byteArray).then(() => ...)
Lucas Oliveira
  • 668
  • 6
  • 22