cordova-plugin-bluetoothle icon indicating copy to clipboard operation
cordova-plugin-bluetoothle copied to clipboard

Android: "Unable to write on return" with status 129 when reconnecting

Open MalikDrako opened this issue 6 years ago • 3 comments

I am working on OTA updating a BLE device, and am having problems with some phones. The device has a service with two characteristics: a write-only characteristic for commands, and a subscribable characteristic for replies.

On some phones, the update works fine, but on others it fails to reconnect, giving "Unable to write on return". When I attach Android Studio, I see status 129 (GATT_INTERNAL_ERROR) in onCharacteristicWrite

Update process:

  • Write Start Update command
  • Device sends ACK reply then resets into bootloader (If no data is received, the bootloader exits after 5s)
  • Phone disconnects and closes, waits ~1s to be sure device has reset (I tried increasing to ~3s with no change)
  • Phone connects, discovers, subscribes (I tried scanning while this is happening on Android)
  • Phone starts handshake ("Unable to write on return" with status 129 on the first write here, then ~15s later I get "Device is disconnected")
  • Phone sends firmware packets
  • If successful, phone sends completion command

I looked at the HCI log, but it looked like the phone didn't actually connect to the device, just Set Scan Enable and related, then Disconnect Complete ~19s later

Strangely, "Recovery Mode" updates work fine (the device resets into the bootloader for 5s when it is plugged in):

  • Disconnect and close if connected
  • Scan for a device in recovery mode
  • Go to "Phone connects, discovers, subscribes" in the normal update process

Update: I got firmware versions that increased just the delay between receiving the Start Update command and rebooting, just the timeout for the bootloader, and both. The version with the increased delay after the Start Update command worked fine, but the increased bootloader timeout did not work. I am guessing the phone has sub-par BLE drivers and isn't able to complete disconnection before the device resets, then doesn't know what to do.

MalikDrako avatar Jan 29 '19 00:01 MalikDrako

Did you fix this issue?

untilbit avatar Jun 03 '19 11:06 untilbit

same, any update on this?

Funkelfetisch avatar Aug 19 '21 15:08 Funkelfetisch

I am seeing the same issue as well, but i am using 2 android phone, 1 acting as a peripheral device. The device that write to the phone is showing Unable to write on return in the error message, and when i do a read(), its also showing unable to read.

clarklight avatar Sep 14 '21 09:09 clarklight