tanelih / phonegap-bluetooth-plugin

Bluetooth plugin for PhoneGap version 2.6.0+
MIT License
57 stars 50 forks source link

Need some help reading data (binary) #12

Closed StargazerNC closed 10 years ago

StargazerNC commented 10 years ago

Hi!

I've been trying to use the plugin to read some data from a temperature probe. The problem is that the probe sends a packet, 128 bytes in length, with a bunch of information in each byte. I can't tell what format is the packet, but I'm assuming some kind of stream or byte array.

I'm using an Android (ICS) device.

By the subscribe function, I'm stuck since I do not know how the data ends so I can apply a splitter on it... On the read method, I get the data but It's always a string with no visible text with a length of two...

Any pointers on how to deal with this?

Thanks!

tanelih commented 10 years ago

Hi,

Do you have any sample data? I originally developed this plugin for a device that emitted measurement data with a predefined format in short bursts. The plugin actually receives a byte array, which gets turned into a string in BluetoothPlugin.java and then sent back to the JavaScript API.

I would do some digging in BluetoothPlugin.java Handler, specifically under MSG_READ. Check if you can log the byte array before it gets turned into a string and figure out how you can get in touch with your data. I will probably take a look at it myself and see if I can add options for reading the data in other formats than string.

StargazerNC commented 10 years ago

sample data I can't provide you. But I can tell you the format of the data in the 128byte array, if it helps.

StargazerNC commented 10 years ago

This array as data from several types ranging from strings to integers, doubles and bytes. More to the point, the data coming from the probe is like a JAVA Bundle, meaning that the byte array will be very heterogeneous as well. Is there any way to change the native code to read the Bundle and serialize it as json and then pass it on to the javascript like a JSON string, so the client app can take that data and do as it pleases with it? That would be really cool if it did it...

StargazerNC commented 10 years ago

Ok, this one is cleared. Moving on.