This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Receiving data using BLE in Android

Hi All,

Am developing an app that communicates with an embedded device through Bluetooth low energy.

The embedded device is sending the data in hex format say "35AE51BA44". The device sends the data in byte[], Eg: (byte[0]=0x35, byte[1]=0xAE, byte[2]=0x51)

In app side am receiving the data in string format, when i tried print the data it was in unsupported format like below,

������5�*��QD^�t+ �,8

I tried to read each character in the string and print its hex value using the below code, Log.d(TAG,String.format("%02x", (int)data.charAt(i)));

am getting the values like,

35

fffd

51

fffd

44

If the hex value crosses 7 i.e(8,9,A,B,C,D,E,F) am getting the hex value as ff. Since am grouping two characters for all hex values starting with 80,81,....,FF am getting the value as fffd. I assume its garbage value as we get the same value for all these bytes and its not varying.

Am assuming when the byte value is 8 (1000), this problem occurs only when the first digit is 1. After 8 all the hex value comes with the MSB as 1.

Can anyone help me what wrong am doing?

It may be something to do with either Extended ASCII character set or numbers are taken as negative number because of the 8th bit. We are not sure of the problem.

Related