Details on bluetooth connection with android app

68 views
Skip to first unread message

Justinas Gasparovičius

unread,
Aug 27, 2012, 4:08:44 PM8/27/12
to smart_scale_...@googlegroups.com
Hello.
Firstly, realy nice project! I would like to know details about  how bluetooth module communicates with smart scale android app. What kind of data bluetooth is sending. Maybe you can give an output example. Does baudrate is fixed for android app? What about pairing pin code,should it be disabled? I am doing something similar using avr, and i made quick test sending one char (number) over and over again, then i paired module with android phone but but after i press "scale" on app it responds "not bluetooth device". I also failed to find these answers in your source code. Thanks.

Casainho

unread,
Aug 27, 2012, 7:00:26 PM8/27/12
to smart_scale_...@googlegroups.com
2012/8/27 Justinas Gasparovičius <baltaspopi...@gmail.com>:
> Hello.
> Firstly, realy nice project!

Hello.

Thanks.

I would like to know details about how
> bluetooth module communicates with smart scale android app. What kind of
> data bluetooth is sending. Maybe you can give an output example.

/* Update Android */
sersendf("a %d\n", weight);

/* Send final value to Android */
sersendf("b %d\n", weight);

sersendf is a kind of printf.
See more here: https://github.com/casainho/Smart-Scale/blob/master/firmware/fagor_bb_90/main.c


Does
> baudrate is fixed for android app? What about pairing pin code,should it be
> disabled? I am doing something similar using avr, and i made quick test
> sending one char (number) over and over again, then i paired module with
> android phone but but after i press "scale" on app it responds "not
> bluetooth device". I also failed to find these answers in your source code.

The Android app try to connect to a bluetooth device with name "maria":
<string name="bluetooth_device_name">maria</string>
See here: https://github.com/casainho/Smart-Scale/blob/master/software/smart_scale_weight_chart/res/values/strings.xml

Why "maria"? well, I had configured my bluetooth module with that name
on the time. Probably I should configure with name "smartscale" and
use it.

So, the name of your bluetooth device should be "maria" or you can
change that string on the Android app to the one you use and build
again the application.

--
Cumprimentos,
Jorge Pinto
E-mail: casa...@gmail.com
Telemóvel: 927145983

Incubadora da Universidade de Aveiro
Edifício I, Sala 82
Campus Universitário de Santiago
3810-193 Aveiro
+351 234 380 314
www.bitbox.pt

Justinas Gasparovičius

unread,
Aug 28, 2012, 8:51:20 AM8/28/12
to smart_scale_...@googlegroups.com
Hello again,
Thanks for quick reply. Information was very helpful, but i'm still unable to connect. I renamed device to "maria" and after i press "scale" android notifies "connected to maria" but app is showing "Searching for the Smart Scale..." and nothing happens. I tried to connect in different ways: while sending only a 70, only b 70, sending both with 100 ms delays and while sending nothing. Nothing happens and app keeps showing "Searching for the Smart Scale..." in all these ways.
My script is like yours:
unsigned int weight=70;
printf("a %d\n", weight);
printf("b %d\n", weight);
Tests on Hyper Terminal are showing that everything looks good (attached file). I also tested using android app SenaBTerm (android bluetooth terminal) and app was able to connect also showed that bt module is sending correct data (a 70 and b 70). Any ideas what to try next ? My bt module is settings are: baud rate - 19200 bps,  Data bits 8, pairity - None, Stop bits - 1, Flow control - None. Module is working on Master mode. Maybe fault is in settings, can you describe yours ?
Thanks.
hyper.png

Casainho

unread,
Aug 29, 2012, 5:08:26 AM8/29/12
to smart_scale_...@googlegroups.com
2012/8/28 Justinas Gasparovičius <baltaspopi...@gmail.com>:
> Hello again,
> Thanks for quick reply. Information was very helpful, but i'm still unable
> to connect. I renamed device to "maria" and after i press "scale" android
> notifies "connected to maria" but app is showing "Searching for the Smart
> Scale..." and nothing happens. I tried to connect in different ways: while
> sending only a 70, only b 70, sending both with 100 ms delays and while
> sending nothing. Nothing happens and app keeps showing "Searching for the
> Smart Scale..." in all these ways.
> My script is like yours:
> unsigned int weight=70;
> printf("a %d\n", weight);
> printf("b %d\n", weight);
> Tests on Hyper Terminal are showing that everything looks good (attached
> file). I also tested using android app SenaBTerm (android bluetooth
> terminal) and app was able to connect also showed that bt module is sending
> correct data (a 70 and b 70). Any ideas what to try next ?

Hey, great advance!!

Seems you are doing all correctly. I did very well to test with
terminal program and other Bluetooth app!

My bt module is
> settings are: baud rate - 19200 bps, Data bits 8, pairity - None, Stop bits
> - 1, Flow control - None. Module is working on Master mode. Maybe fault is
> in settings, can you describe yours ?

The settings of serial port of bt module should be only important for
communicating from microcontroller adn bt module. Since you were able
to correctly communicate over bt, your baud rate should be corretly.

Could you please tell what is your bt module? please share a picture also.

I belive the problem is now on Android app that is not able to "open"
your bluetooth module. I suggest you to use the Eclipse and debug the
code, by putting breakpoints on the code and find where the code
hangs.

My bet is that you need to put break points on "ScaleActivity.java"
file. "setContentView(R.layout.scale);" code should print the
"Searching for the Smart Scale...".

But I guess it hangs just after at:

// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

// Start activity find and return the device bluetooth address
Intent intent = new Intent(this, FindDeviceActivity.class);
startActivityForResult(intent, RESULT_FIND_DEVICE);

Maybe the problem is the activiy "FindDeviceActivity". Please try to
"clear" the pairing of you bt module on Android and make again the
pairing.

Justinas Gasparovičius

unread,
Aug 29, 2012, 4:10:14 PM8/29/12
to smart_scale_...@googlegroups.com
Hey,
My bt module looks the same as yours, i saw people naming it HC06 (attached pictures) and it is based on BC417143. I also applied  so called "Serial Bluetooth RF Transceiver Module Interface Board". I used it basically to provide relieble dip connection pins for this module. I also attached schematics of this extra board. There is led on this board indicating status of connection - it blinks then device is pairable and lights steady then bt is connected (then android app freezes led is showing that bt module connected). I dont know what transistor on that board is doing but i think it just stabilises voltage or maybe saves energy. I dont think this board causes problems since other apps appcepted module. I seen newer and older preaty similar looking HC bt modules on ebay (HC05 and HC07) but i'm not sure which one is mine, seller did't provide that information. You were right about bt module settings, i tried to change them all and situation was the same. I also tried to connect with even unpaired bt module and app successfuly inquired pairing pin code and after that anroid showed the same status "connected to maria" and froze. If i push back it usually writes that connection was lost, minimizing app by pressing home key and maximazing it again did not help too. I also tried both older and newer versions of this app you uploaded. I'm almost sure this is app problem. I already tried to debug it on eclipse but its very hard even to import project because eclipse environment is completely new for me as well as java language and android sdk with adt plugin. I took me long even to install these but eclipse still shows thousand errors (i think becouse of missing libraries). So i will keep trying to debug or modify program and i  update status here if in case of finding something. If you will have some more remarks about app or my module it would be wonderful to hear them too.

On Monday, 27 August 2012 23:08:44 UTC+3, Justinas Gasparovičius wrote:
board.jpg
IMG_20120829_191602.jpg
IMG_20120829_094316.jpg

Justinas Gasparovičius

unread,
Aug 29, 2012, 5:40:03 PM8/29/12
to smart_scale_...@googlegroups.com
Quick update:
Finally managed to cope with eclipse android emulation and first thing i noticed was intresting warning at ScaleActivity.java line 112 [mCommService = new BluetoothCommService(this, mHandler);] saying: "This Handler class should be static or leaks might occur (net.casainho.smartweightchart.ScaleActivity.1)". Comments saying that: this should :// Initialize the BluetoothCommService to perform bluetooth connections.
               I googled this error and found out that: This may lead to memory leaks, for some time at least - as long as the messages stay int the queue.( link on this text).   It is also As i said my knowledge in java is 0, so i will ask stupid question is it possible that app freezes because of this? I tried to rebuild code like in the link but i did not understand where should i put "this" from "BluetoothCommService(this, mHandler);". So far i dont know how to debug connection with bluetooth because emulator does not provide any bluetooth emulation.

Casainho

unread,
Aug 29, 2012, 6:14:56 PM8/29/12
to smart_scale_...@googlegroups.com
Please use your Android phone connected to your PC and debug with
Eclipse. Please focus on the FindDeviceActivity.java code.

Justinas Gasparovičius

unread,
Aug 29, 2012, 6:21:48 PM8/29/12
to smart_scale_...@googlegroups.com
One more quick update.
Just fuond out cool eclpise feature that  i can track program with my own phone. Logged everything whats happening after app freezes. Maybe you will find something you understand more than me. Added screenshots and log in txt (comment on first screen in the left).
error1.png
error_part2.png
error_part3.png
error_part4.png
error_part5.png
log.txt
session_filter.png

Casainho

unread,
Aug 31, 2012, 6:39:24 AM8/31/12
to smart_scale_...@googlegroups.com
Hello.

Any good news?

Can you please share some pictures of your hardware/scale? What are
you trying to do?
Reply all
Reply to author
Forward
0 new messages