1

I'm currently using this library.

I started with Android APP that works correctly. I could send and receive some data. But what I'm going to do is to make communication between Android and Microcontroller with BT module.

On Android to Android I send data like this:

String sequence = "1234";
bt.send(sequence.getBytes(), true);
//or just: 
bt.send(sequence, true);

And on second device I receive data like this:

bt.setOnDataReceivedListener(new OnDataReceivedListener() {
    public void onDataReceived(byte[] data, String message) {
        ...        
}
});

So it seems that data I send is that message, but if I try do something like this:

String received_data = data.toString();

It looks like some random sequence, for example:

[B@1b1f21b4

And [B@ part is always the same. It would be actually no problem if I just want to do Android <-> Android APP, where I can just extract the data I need from message, but I need to read those data on Microcontroller. How can I properly receive those data?

EDIT: Thanks to Isaac, I know I needed to convert on Android bytes to string like that:

String str = new String(bytes, "UTF-8");

And both from message and data I can read my information. But if receiving data on Microcontroller would be correct?

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
serwus
  • 155
  • 1
  • 14
  • I will check that, but why is it every time different? – serwus Sep 06 '16 at 01:50
  • did you even read the other Q/A? – Isaac Sep 06 '16 at 01:50
  • It looks I like didn't know what should I look for. More details in EDIT1, thanks. – serwus Sep 06 '16 at 02:19
  • First, can you confirm that the microcontroller can receive any data? Have you tested with your board? Second, you should know what is the format of data that you receive on the microcontroller. When you know the data format, you should know to read it correctly . – theman Sep 06 '16 at 04:15

1 Answers1

0

try this String receivedData = new String(data);. It should work. For further information looked into this link

Khalid Taha
  • 3,183
  • 5
  • 27
  • 43
  • On Android it works fine with code in EDIT1, but on Microcontroller we use C. I'm sorry guys, if I ask some tiresome questions, but the true problem is that I don't have currently access to the printed circuit board (we make project with a friend who works in a distance) and we try to find out if problem is on java or C part. – serwus Sep 06 '16 at 02:18