question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sporadic 'Writing characteristic failed' on BleClient.write()

See original GitHub issue

Hello, thank you for the creation and support of this plugin.

I have a ionic cordova application I ported to capacitor. The app does continuous BleClient.write()s with the expected result to come from an indication.

What I am seeing with this plugin is sporadic ‘Writing characteristic failed’ from the BleClient.write(). The app might be able to do writes and get the associated indication back for say 5 minutes before this error occurs. The next time it might run for 10 seconds before the error occurs.

Below is what I have captured in Android Studio.

GOOD CASE
File: http://localhost/main.js - Line 2114 - Msg: WRITE
V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 63189254, pluginId: BluetoothLe, methodName: write
V/Capacitor: callback: 63189254, pluginId: BluetoothLe, methodName: write, methodData: {"deviceId":"CC:3B:3E:81:45:6B","service":"832ae7fe-d3c5-11e4-b9d6-1681e6b88ec1","characteristic":"737bea54-d3c5-11e4-b9d6-1681e6b88ec1","value":"2b 01 01 0b 00 04 00 00 00 00"}
D/Device: resolve: write|832ae7fe-d3c5-11e4-b9d6-1681e6b88ec1|737bea54-d3c5-11e4-b9d6-1681e6b88ec1 Characteristic successfully written.
I/Capacitor/Console: File: http://localhost/ - Line 204 - Msg: undefined
V/Capacitor/BluetoothLe: Notifying listeners for event notification|CC:3B:3E:81:45:6B|832ae7fe-d3c5-11e4-b9d6-1681e6b88ec1|93c7a770-ddff-11e4-b9d6-1681e6b88ec1
I/Capacitor/Console: File: http://localhost/main.js - Line 2191 - Msg: rx [0x2b,0x00,0x01,0x01,0x0b,0x00,0x04,0x00,0x00,0x00,0x00]
I/Capacitor/Console: File: http://localhost/main.js - Line 2191 - Msg: tx [0x2b,0x01,0x01,0x0b,0x00,0x04,0x00,0x00,0x00,0x00]
BAD CASE
File: http://localhost/main.js - Line 2114 - Msg:-WRITE
V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 63189255, pluginId: BluetoothLe, methodName: write
V/Capacitor: callback: 63189255, pluginId: BluetoothLe, methodName: write, methodData: {"deviceId":"CC:3B:3E:81:45:6B","service":"832ae7fe-d3c5-11e4-b9d6-1681e6b88ec1","characteristic":"737bea54-d3c5-11e4-b9d6-1681e6b88ec1","value":"2b 01 01 0b 00 04 00 00 00 00"}
D/Device: reject: write|832ae7fe-d3c5-11e4-b9d6-1681e6b88ec1|737bea54-d3c5-11e4-b9d6-1681e6b88ec1 Writing characteristic failed.
D/Capacitor: Sending plugin error: {"save":false,"callbackId":"63189255","pluginId":"BluetoothLe","methodName":"write","success":false,"error":{"message":"Writing characteristic failed."}}
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=9 device=CC:3B:3E:81:45:6B
V/Capacitor/BluetoothLe: Notifying listeners for event disconnected|CC:3B:3E:81:45:6B
D/Capacitor/BluetoothLe: No listeners found for event disconnected|CC:3B:3E:81:45:6B
D/BluetoothGatt: close()
    unregisterApp() - mClientIf=9
D/Device: Disconnected from GATT server.
W/Device: Resolve callback not registered for key: disconnect

For whatever reason I do not see this issue with the cordova plugin.

What are some potential causes behind ‘Writing characteristic failed.’? Is there anything I can check or look into?

Thanks for any insight.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ASHBAWcommented, Jan 10, 2022

Thank for looking at this.

I was actually in the process of responding. I am thinking there was something up with my development environment. The plugin seems to be working well.

You can close this issue.

Thanks for your time supporting this plugin.

0reactions
pwespicommented, Jan 10, 2022

Let me know if you find anything. I am unfortunately still not able to reproduce this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BleClient.write: Writing characteristic failed on WebView ...
My solution is creating a similar object with only the required functionalities implemented and assigning it to navigator.bluetooth . Other ...
Read more >
ESP32 BLE Exception when trying to connect to Characteristics
I wrote the following program to scan for devices and connect based on ... Then accessing the characteristic leads to the Exception error....
Read more >
Writing characteristic failed error when writing to ESP32 GATT ...
Get "Writing characteristic failed" error message when executing BLEClient.write and can't understand why it's failing.
Read more >
Writing characteristic failed error when writing to ESP32 GATT ...
Resolved this issue by using Google's protocol buffer code for javascript. Couldn't figure out how to create the correct message format ...
Read more >
BLE in ESP32: Bluetooth Low Energy connection
The bluetooth low energy (BLE) connection method will allow you to reduce the consumption of the ESP32, in addition to advanced characteristics.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found