Serial Data Transfer via Bluetooth

by AnthonyB » Wed, 17 Mar 2010 04:18:43 GMT


Sponsored Links
 I'm trying to get serial data from a USB Weather Board from Sparkfun
Electronics using one of their SPP Bluetooth Modems.  This device will
be able to send serial data over bluetooth and all I wan't to do is
read and store the data.  I'm pretty sure this is possible but I'm
still not great at writing code for an android device yet. After that
I want to take that data and put it into a human-readable way for
instance for temperature have ("Temperature= 70F"). The value of 70
will come from the serial ascii string of bytes and I'll probably be
able to work with the data after I get it and save it.  So can anyone
give me a little bit of code on how to read and store the ascii string
or give me a good example to look at?  Also the string is 46 bytes and
starts with a # sign and ends with a $ sign and I'd like to use that
to make sure I just get one string of data.  Any help or insight would
be greatly appreciated.

Thanks
Tony

--



Serial Data Transfer via Bluetooth

by DonFrench » Wed, 17 Mar 2010 09:27:06 GMT


 Look at the Bluetooth Chat example and change the UUID to
"00001101-0000-1000-8000-00805F9B34FB".  That should get you going.




--


Sponsored Links


Serial Data Transfer via Bluetooth

by BobG » Thu, 18 Mar 2010 03:05:43 GMT


 Hi Don. I think you need 2.0 or higher to run the bluetooth chat
example.. wish it wasnt so... I have a dev phone 2 (Google Ion? Does
it have other names? HTC something? TI something?) with 1.6. Someone
know how to use the bt backport examples? What dir do I put the jar
file in?

--



Serial Data Transfer via Bluetooth

by DonFrench » Thu, 18 Mar 2010 06:14:21 GMT


 Then we are out of my comfort zone.  You might check this site though,
 http://www.amarino-toolkit.net/documentation.html.  According to 
Bonifaz Kaufmann, the developer of Amarino, they are communicating via
Bluetooth SPP with   the following devices, all pre 2.0.

    * HTC Dream (aka T-Mobile G1, firmware 1.1, 1.5 and 1.6)
    * HTC Magic (firmware 1.5 and 1.6)
    * HTC Tattoo (firmware 1.6)
    * Huawei U8220 (aka T-Mobile Pulse, firmware 1.5)
    * (partially tested) Samsung Galaxy (firmware 1.5)

You can find the entire source code of Amarino here: 
 http://code.google.com/p/amarino/ 
and it includes all the Bluetooth related stuff as well.  Good luck.







--



Serial Data Transfer via Bluetooth

by Ben » Fri, 19 Mar 2010 05:43:37 GMT


 I've attempted to use the unofficial Bluetooth API for 1.6, got
through finding the adapter and the remote device, but could not open
an RFCOMM socket.  You should be able to put the Jar anywhere as long
as Eclipse--if that is what you are developing on--points to it.
There are instructions on how to external libraries on the android
developer site:

 http://developer.android.com/guide/appendix/faq/commontasks.html 

Though google advises against using these to future proof your app.




--



Serial Data Transfer via Bluetooth

by Lovers v. Haters » Fri, 19 Mar 2010 05:44:56 GMT


 I agree-- Amarino is pretty useful.  I'm doing a project that uses
Amarino to transmit strings of data over XMPP.  (Google put the kibosh
on making your own jabber client, but I found a useful JAR to get
around it.)  Put Amarino together with XMPP and your device becomes a
great transmitter for broadcasting microcontroler status anywhere
instantly.

If you're interested in going that route, check out (in addition to
Amarino)
1) Asmack (Jabber hack for 1.5 and 1.6-- not sure about 2.0)
 http://github.com/rtreffer/asmack 
2) ChatStar (which I wrote cobbling Amarino and Asmack together)
 http://github.com/harlo/ChatStarr/ 

Thanks,
Harlo/Lovers v. Haters





--



Serial Data Transfer via Bluetooth

by BobG » Sun, 21 Mar 2010 03:00:45 GMT


 Thanks Ben... your message was the clue I needed... I put the backport
jar file in a dir in the package, went to the package properties and
added the jar under 'link external jars', and the bt chat compiled
right up. Lots of details need to be right to get this stuff to work,
huh?

--



Serial Data Transfer via Bluetooth

by Ben » Sun, 21 Mar 2010 23:25:15 GMT


 No problem Bob.  Let me know if you are able to open an RFCOMM socket
it never worked for me.  I checked the Amarino source code, and it
looks like I am doing basically the same thing that they are, but for
some reason they can get it open and I can't.  So for now I've
modified my app to use a broadcast receiver to receive data from the
amarino like the examples.  Though I don't have my Bluetooth antenna
hooked up to an Arduino, it's hooked up to a Blackfin DSP, so
hopefully there is nothing about Amarino that actually requires the
thing on the other end of the UART to be an Arduino.  Looking through
the source I can't find anything that would limit it like that, but
I'll see.




--



Serial Data Transfer via Bluetooth

by Shane » Sat, 27 Mar 2010 04:57:15 GMT


 Hi guys,
Im new to android and im trying to use the bluetooth backport. Could
someone explain what the step "put
backport_android_bluetooth.properties in to your src directory. "
means? Do i create a file and paste in the code or is there something
im missing. Ive followed the other steps and its not working for me so
i think the problem lies here.

Thanks





--



Other Threads

1. Theme.Dialog bug in 2.1?

Hello,

I have found some weird behaviour which might be a bug. I found it
while developing a quite large application but I've been able to
reproduce the behaviour in a minimal approach so that I can provide
source code.

I have a service that is constantly running and at certain times it
pops up an activity with Theme.Dialog as theme for the user.
Everything works fine if the main activity of the program has been
destroyed (via back button) or if the main activity is currently
running.

However, if the main activity of the app has been created and then
minimized (e.g. via Home button), the main activity shows up. It is
not possible to click the buttons of the main activity because it
seems to be hidden behind an invisible dialog activity. It is possible
to click the buttons of the dialog if you know where they are and if
you click the back button, you can see the dialog flashing by as it
disappears and it is then possible to click the main activity buttons.

I've tested this on HTC Desire 2.2, HTC Wildfire 2.1, HTC Legend 2.1,
Sony x10 mini pro 2.1 and on emulators 2.1 and 2.2. The behaviour
described happens on all 2.1 devices and emulator but not on emulator
2.2 nor on the Desire with 2.2.


Source code is provided below. There are 2 buttons in the main
activity, the first, called "Finish" asks the service to popup the
dialog in 3 seconds and then finishes the main activity. This button
is for illustrative purposes only, it works fine. The second button,
called "Post later" just asks the service to popup the dialog in 3
seconds. If the second button is clicked and before the 3 seconds have
passed, the home button is clicked, the bug appears.

Source code:
Main.java:
--------------------------------------------------------------
package com.myapp.DialogBugTest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

public class Main extends Activity
{
    private Handler handler = new Handler();

    private final Runnable runnable = new Runnable()
    {
        public void run()
        {
            DialogBugTestService.getInstance().showDialog();
        }
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        startService(new Intent(this, DialogBugTestService.class));
    }

    public void onFinishButton(View aView)
    {
        handler.postDelayed(runnable, 3000);
        finish();
    }

    public void onLaterButton(View aView)
    {
        handler.postDelayed(runnable, 3000);
    }
}
--------------------------------------------------------------
main.xml:
--------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <Button
                android:id="@+id/finish_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Finish"
            android:onClick="onFinishButton"
            />
        <Button
                android:id="@+id/later_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Post later"
            android:onClick="onLaterButton"
            />
</LinearLayout>
--------------------------------------------------------------
DialogBugTestService.java:
--------------------------------------------------------------
package com.myapp.DialogBugTest;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class DialogBugTestService extends Service
{
    private static DialogBugTestService instance = null;
    @Override
    public void onCreate()
    {
        super.onCreate();
        instance = this;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        return START_STICKY;
    }


    public static DialogBugTestService getInstance()
    {
        if (instance == null)
        {
            Log.e("service", "instance is null!");
        }
        return instance;
    }

    public void showDialog()
    {
        Intent intent = new Intent(this, DialogBugDialog.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    @Override
    public IBinder onBind(Intent arg0)
    {
        return null;
    }
}
--------------------------------------------------------------
DialogBugDialog.java:
--------------------------------------------------------------
package com.optimobile.DialogBugTest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;


public class DialogBugDialog extends Activity
{

    @Override
    protected void onCreate(Bundle aSavedInstanceState)
    {
        super.onCreate(aSavedInstanceState);
        setContentView(R.layout.dialog);
    }

    public void onOk(View aView)
    {
        finish();
    }

}
--------------------------------------------------------------
dialog.xml:
--------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <Button
                android:id="@+id/ok_button"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="OK"
            android:onClick="onOk"
            />
</LinearLayout>
--------------------------------------------------------------

I've also tried this without the Theme.Dialog as theme and it then
works fine. I also tried it with custom styles and the bug seems to
appear whenever windowIsFloating is set to true.

Is this a known bug? Are there any workarounds? I really need this
functionality in my app and doing it without a floating window looks
really ugly.

-- 

2. Android Browser and filtering URLs

I'm essentially resurrecting a thread in this same forum from back in
2009:

http://tinyurl.com/4hc7uj7

(it no longer allows posts). In it, the OP asked:


At the time, the consensus was that this was not possible with the SDK
or NDK.

I'm wondering now if anything in that regard has changed. In
particular, I'm aware of one or more apps that claim to provide "safe
browsing" (e.g. parental controls) and I'm wondering how they can do
this without being able to intercept the URLs that are being requested
by the browser. Is there a way to hook into the android browser events
now?

-- 
.

3. Can "package installer" access private file of an app

4. Separate assets - multiple apks

5. Testing an Android App

6. Code analysis, anyone?

7. Froyo build error WifiConfiguration