0

Trying to write from phone to a device using the method below. We have three packets of data to transmit. The first packet transmits, then our phones disconnect with error Response Characteristic Error: Error: Device disconnected.

Can anyone shed light on how to troubleshoot this response characteristic error? We're using the react-native-ble-plx library.

   writeToDevice = async (fullMessage, machineID) => {
      let subMessagesToSend = [];
      let subMessagesToSendCounter = 0;
      let i, j;
      let maxBytes = 19;
      for (i = 0, j = fullMessage.length; i < j; i += maxBytes) {
        subMessagesToSend.push(fullMessage.slice(i, i + maxBytes));
      }
      const sequenceNum = Buffer.alloc(1);
      sequenceNum.writeUInt8(subMessagesToSendCounter, 0);
      const subMessage = subMessagesToSend[0];
      const buffer = Buffer(subMessage, 'utf8');
      const fullBuffer = Buffer.concat([sequenceNum, buffer]);
      const message = fullBuffer.toString('base64');
      ble.writeCharacteristicWithResponseForDevice(
        machineID, 
        hUUID,
        rxUUID, 
        message)
        });
      subMessagesToSendCounter++; 
    }
John
  • 521
  • 1
  • 7
  • 23

1 Answers1

0

Well, the writeCharacteristic call isn’t inside a for loop so it won’t send more than 1 message...

No idea why it then disconnects but it may simply be a time out...