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.

Data formatting for write

See original GitHub issue

I’m trying to write, and getting this error: BleError: Characteristic * write failed for device * and service *

I believe it’s an issue with the formatting of the write data. The bluetooth device is expecting a data array, specifically something like this:
[ 0, 0, 173, 0, 129, 164, 116, 121, 112, 101, 170, 100, 105, 97, 103, 110, 111, 115, 116, 105 ]

It seems the lib wants the above to converted to a string. When I convert it to a base64 string, the bluetooth device fails to write. Anyone know how to write a data array?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
mazenchamicommented, Nov 6, 2019

@heatherSnepenger my hardware is also initially expecting a byte array, and I haven’t had any issues with my example below. Here is how i’m doing mine (keep in mind this could be specific to my device):

import { Buffer } from 'buffer';
...
const readSingleWifiShortHex = [parseInt('0xAB', 16), parseInt('0x01', 16), parseInt('0x01', 16)];
const readSingleWifiShortBase64 = new Buffer(readSingleWifiShortHex).toString('base64');
return await device.writeCharacteristicWithResponseForService(serviceUUID, characteristicUUID, readSingleWifiShortBase64, singleWifiShortTransactionId)
            .then(async characteristic => await console.log('characteristic', characteristic))
...

for readSingleWifiShortHex, index 0 = the command, 1 = length, 2 = payload.

does that help?

0reactions
mazenchamicommented, Feb 8, 2021

@ayberkgerey I am creating my own transactionId that way I can use it to read later on in my code/file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Read and write formatted data - 4Js
write () Writes a list of data delimited by a separator to the channel. methods ... follow the same formatting rules as the...
Read more >
Data Formatting In Excel: A Complete Guide - Simplilearn
Formatting in Excel is a simple process of modifying or manipulating data in spreadsheets from one form to another. Formatting can be done ......
Read more >
Data and File Formatting — documentation
Data Formats¶ · Containers: TAR, GZIP, ZIP · Databases: CSV, XML · Tabular data: CSV · Geospatial vector data: SHP, GeoJSON, KML, DBF,...
Read more >
Format numbers as dates or times - Microsoft Support
In the Category list, click Date or Time. Format Cells dialog box. In the Type list, click the date or time format that...
Read more >
Writing Data to Files
Data is written to a file using the PRINTF statement. The statement may include the FORMAT keyword to control the specific structure of...
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