• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Bluetooth Receive message from BlueSmirf/Arduino

nanolab

Lurker
Apr 19, 2010
1
0
I am new to coding but anxious to learn. I have been struggling for a while now trying to receive messages from an arduino board connected to a bluesmirf. The arduino board is simply outputting a byte over bluetooth and I'm trying to read it in the debug.

Here is my android code:

Code:
Log.i(TAG, "BEGIN run and receive message");
       byte[] buffer = new byte[1024];
       int bytes;
       
       Log.i(TAG, "The original buffer string is " + buffer);
       
       //Keep listening to the Input Stream while connected
       while(true){
           try{
               //Read from the InputStream
               bytes = inStream.read(buffer); 
               Log.i(TAG, "Message is: " + buffer);
           }
           catch(IOException e){
               Log.e(TAG, "disconnected", e);
               break;
           }
       }
I know I am connecting to the device fine because the green light on the board lights up. The debug message that I am getting though is garbage:

04-19 15:58:26.264: ERROR/BluetoothChat(8558): ON RESUME: BT connection established, data transfer link open.
04-19 15:58:26.264: ERROR/BluetoothChat(8558): + ABOUT TO SAY SOMETHING TO SERVER +
04-19 15:58:26.264: INFO/BluetoothChat(8558): BEGIN run and receive message
04-19 15:58:26.264: INFO/BluetoothChat(8558): The original buffer string is [B@4471f770
04-19 15:58:26.408: INFO/BluetoothChat(8558): Message is: [B@4471f770
04-19 15:58:27.406: INFO/BluetoothChat(8558): Message is: [B@4471f770
04-19 15:58:27.406: INFO/BluetoothChat(8558): Message is: [B@4471f770
04-19 15:58:28.411: INFO/BluetoothChat(8558): Message is: [B@4471f770
So as you can see, the buffer string isn't even changing (even though I have tried multiple types of strings from arduino code).

But I know it is connected because the "Message is: ..." Dialog inputs every time a message should be coming.

What is going on here? Does anyone have an idea? I might not be giving you enough code, let me know, I just don't want to overwhelm you.

PS I have also tried transmitting "hello world" to the arduino board with success. It is receiving messages that I cannot do yet.
 
I too am trying to learn how to program my android phone and the first app that i have in mind would communicate with my arduino. I have not purchased the blue smirf yet, but i am eager to pick one up one i have done a few android tutorials.

i was wondering if you have been able to connect yet? i have a book that helped me out quite a bit with arduino development, Making Things Talk. This book goes into quite a bit of detail on bluetooth communication.
 
Upvote 0
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones