dotintent / react-native-ble-plx

React Native BLE library
Apache License 2.0
3.06k stars 513 forks source link

Write failed for device: errorCode: 401 attErrorCode: 128 #1145

Closed webjay closed 11 months ago

webjay commented 11 months ago

Prerequisites

Question

I have a Moko M1 based on nRF52810 which I am trying to write to. I can write to it successfully via the "nRF Connect" app.

I know that the error 401 means "Couldn't write to specified characteristic", however isWritableWithResponse: true. I don't know what the error attErrorCode: 128 indicates?

In both nRF Connect and via console.log I only see one service and one characteristic.

I have the content stored as a string for now, from this: const fileContent = readFileSync('/Users/jacob/Downloads/EA140CF93E0D.zip', { encoding: 'base64' });

What might I be doing wrong?

const isConnected = await device.isConnected();
if (!isConnected) await device.connect();
await device.discoverAllServicesAndCharacteristics();
const services = await device.services();
const characteristics = await device.characteristicsForService(services[0].uuid);
await characteristics[0].writeWithResponse(fileContent).catch((error) => {
  console.log(JSON.stringify(error));
});
webjay commented 11 months ago

It turns out I needed to use react-native-nordic-dfu: https://github.com/Pilloxa/react-native-nordic-dfu/issues/171#issuecomment-1758051806