Closed myyellowshoe closed 8 years ago
Ok i've figured out a bit more. It looks like the byte array is getting returned properly from the device. In my case i'm looking for a number returned from the device.
I debugged the actual function running on the java side.
public void onCharacteristicRead(BluetoothGatt g, BluetoothGattCharacteristic c, int status)
{
Log.d("DEBUG", "#~#~#~# characteristic read: " + c.getValue()[0]);
if (status == BluetoothGatt.GATT_SUCCESS) {
mCurrentOpContext.success(c.getValue());
} else {
mCurrentOpContext.error(status);
}
mCurrentOpContext = null;
process();
}
Gives me:
#~#~#~# characteristic read: 100
Just what I need. So in since this is the proper value, its a problem with how I'm reading the buffer in javascript.
Shouldn't the following be more than needed?
var data = evothings.ble.fromUtf8(buffer);
console.log(data);
@myyellowshoe Hello, what is the format of the data in the buffer? Is it a utf8 string?
@mikaelkindborg It should just be a 1 byte array. Not sure on the specifics of the format. I just know it returns a number.
Woot! So as I figured it was all about handling the buffer in the proper way. My poor understanding of buffers was the culprit.
In my case doing the following got me the value I needed.
(new Int8Array(buffer)).toString();
@myyellowshoe Great to hear you solved the problem!
Hey Fellas, and ladies :)
For some odd reason I'm getting an empty string and other seamingly random characters when I do a read on a characteristic. Running android with crosswalk on 4.3.
I've used nrfmastercontrolpanel ( https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=en) and things work great with a do a read on the characteristic.
So far I've see "d", "2", "8", "5" "." "+" I copied my logs and mashed them together not sure if they hold any significance. but somthing is definitely up. %225.385.5225.2.858 2252.525.8285.5.235858+8583.+8.+5.522.29d2dd222+
Here's my code as well as some low level logs looking at the calls into readCharacteristic. Thoughts?