Bluetooth Implementation

4 views
Skip to first unread message

Charles Norona

unread,
Mar 31, 2010, 12:16:15 PM3/31/10
to Engineering Design II Group 6 Spring 2010
In our efforts to try to establish bluetooth connectivity we will
first try to do PC-to-PC connections. As of yet, we already are able
to to mobile-to-mobile because of the simplicity of the bluetooth API
calls the Android engineers have established. Because we are using a
third-part library, BlueCove, for our PC implementations more work is
involved. Hopefully, by taking the time to achieve the PC/J2SE
implementation we will better understand what is needed for the PC-to-
Mobile implementation. One possible complication that I have found so
far might be the incompatibilities of the UUID's in the J2SE/BlueCove
version and that of the Android platform. I will have to conduct more
research but this is what I have learned of the Android UUID so far:

"UUID is an immutable representation of a 128-bit universally unique
identifier (UUID).

There are multiple, variant layouts of UUIDs, but this class is based
upon variant 2 of RFC 4122, the Leach-Salz variant. This class can be
used to model alternate variants, but most of the methods will be
unsupported in those cases; see each method for details."

Excerpted from http://developer.android.com/reference/java/util/UUID.html

Charles Norona

unread,
Mar 31, 2010, 12:24:57 PM3/31/10
to Engineering Design II Group 6 Spring 2010
The javax.bluetooth.UUID.UUID is also based on the same variant of the
UUID layout. http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html

Charles Norona

unread,
Mar 31, 2010, 11:56:02 PM3/31/10
to Engineering Design II Group 6 Spring 2010
After much confusion from referring to various examples I have decided
to redo the Bluetooth RFCOMM client from scratch...sort of. Anyway, I
have managed to get the application to successfully do an inquiry of
devices and call services search which will be necessary to begin the
datastreaming. I have uploaded the project at
http://groups.google.com/group/engineering-design-ii-group-6-spring-2010/web/Bluetooth_RFCOMM_Client_20100331D.zip?hl=en
but it is not yet completed. I still have to implement the other
listener methods but the implementation is becoming more clear to me;
one must first conduct an inquiry or at least acquire remote device
information, then they must see if there are any available services on
that devices(which is what a BT server would do), and then the
datastreaming must be established and managed. I will revisit this on
Friday when I can meet with Allan.

On Mar 31, 12:24 pm, Charles Norona <cnoro...@gmail.com> wrote:
> The javax.bluetooth.UUID.UUID is also based on the same variant of the

> UUID layout.http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html

> > Excerpted fromhttp://developer.android.com/reference/java/util/UUID.html- Hide quoted text -
>
> - Show quoted text -

Charles Norona

unread,
Apr 2, 2010, 1:52:20 PM4/2/10
to Engineering Design II Group 6 Spring 2010
Today, Allan and I have finally managed to successfully implement the
RFCOMM datastreaming in a PC-to-PC setup. All that is needed is a
front-end GUI complemented by the server interpretation logic Chris
and I have been working on to make the base station implementation
complete. Also, we need to find a way to make ensure that the mobile
devices can now connect to our RFCOMM server that will aggregate into
the basestation app. Last time I tried this it was without success but
then again we were not sure if the server was working at that time.

On our sensor interpretation efforts, Chris and I are slowly but
surely creating some form of pedometer complemented by a compass which
we will use to track the devices' movements. He is pleased that we
were able to get consistent data on the orientation, difference of
time from the last sensor reading and the previous one, as well as
what should have been our scalar calculator. The problem with the
scalar calculator is that it is reading from the wrong sensor so I
have to spend time to get the phone to read from both the
accelerometer and the orientation sensors concurrently and pass the
proper values to their corresponding areas of the algorithm.

All in all, after some questionably stone-walling we have managed to
make quite some progress!


On Mar 31, 11:56 pm, Charles Norona <cnoro...@gmail.com> wrote:
> After much confusion from referring to various examples I have decided
> to redo the Bluetooth RFCOMM client from scratch...sort of. Anyway, I
> have managed to get the application to successfully do an inquiry of
> devices and call services search which will be necessary to begin the

> datastreaming. I have uploaded the project athttp://groups.google.com/group/engineering-design-ii-group-6-spring-2...

> > > Excerpted fromhttp://developer.android.com/reference/java/util/UUID.html-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -

Charles Norona

unread,
Apr 2, 2010, 1:53:59 PM4/2/10
to Engineering Design II Group 6 Spring 2010

allan pinero

unread,
Apr 6, 2010, 6:31:01 PM4/6/10
to Engineering Design II Group 6 Spring 2010
Updated Version2 of client for debugging server (now version5).
- can send and receive string.
Bugs-server side
-need to fix limits of receiving data (there is memory overflow)//
simple loop bug, tired to fix it right now
To do list
-Have string send to file in the format request
x
y
z
timestamp

On Apr 2, 1:53 pm, Charles Norona <cnoro...@gmail.com> wrote:
> By the way, the updated Bluetooth PC server and clients are available:
>

> Server:http://engineering-design-ii-group-6-spring-2010.googlegroups.com/web...
>
> Client:http://engineering-design-ii-group-6-spring-2010.googlegroups.com/web...

> > > > Excerpted fromhttp://developer.android.com/reference/java/util/UUID.html-Hidequoted text -

Charles Norona

unread,
Apr 6, 2010, 7:51:40 PM4/6/10
to Engineering Design II Group 6 Spring 2010
Good work, Allan!

Keep in mind you will want a field that differentiates what sensor the
values belong to(either the accelerometer or the orientation sensor).
Here is a parse function I use in the mobile version until we get the
base station app up and running. This code should eventually get
adopted into the base station. I will work on it some more tomorrow
and upload the latest version.

/**
* Takes message and extracts information from it and stores values
in respective data types.
* @param message
* String that is passed from message handler that contains the
contents of the bluetooth transmission.
*/
private void parseBTMessage(String message)
{
//String variables
sensorName = "";
sensorType = "";
sensorVendor = "";
sensorVersion = "";
maxRange = "";
powerDissipation = "";
resolution = "";
accuracy = "";
timeStamp = "";
values[0] = "";
values[1] = "";
values[2] = "";


Scanner scanner = new Scanner(message);//java.util.scanner
scanner.useDelimiter("\n");
if ( scanner.hasNext() )
{
sensorName = scanner.next();
sensorType = scanner.next();
sensorVendor = scanner.next();
sensorVersion = scanner.next();
maxRange = scanner.next();
powerDissipation = scanner.next();
resolution = scanner.next();
accuracy = scanner.next();
timeStamp = scanner.next();
values[0] = scanner.next();
values[1] = scanner.next();
values[2] = scanner.next();
Log.d(TAG,"Name: "+ sensorName.trim()
+ " Type: " + sensorType
+ " Vendor: " + sensorVendor
+ " Version: " + sensorVersion
+ " Max Range: " + maxRange
+ " Power: " + powerDissipation
+ " Resolution: " + resolution
+ " accuracy: " + accuracy
+ " Timestamp: " + timeStamp
+ " Values[0]: " + values[0]
+ " Values[1]: " + values[1]
+ " Values[2]: " + values[2]);
}
else
{
Log.d(TAG,"Sensor parser: Empty or invalid line. Unable to
process.");
}

scanner.close();
}

> > > > > Excerpted fromhttp://developer.android.com/reference/java/util/UUID.html-Hidequotedtext -

Charles Norona

unread,
Apr 7, 2010, 1:07:35 PM4/7/10
to Engineering Design II Group 6 Spring 2010
Here is an updated parseBTMessage function. It turns out that some of
the messages do not have the last two elements of the sensor values
appended and, in turn, Scanner will throw an exception and halt your
program. In this case, we will have to simply discard the information.

/**
* Takes message and extracts information from it and stores values
in respective data types.

* NOTE: Meant to be used by base station application.


* @param message
* String that is passed from message handler that contains the
contents of the bluetooth transmission.
*/
private void parseBTMessage(String message)
{

if(message != null)
{
if(message.length() > 105)
{


Scanner scanner = new Scanner(message);

scanner.useDelimiter("\n");
if ( scanner.hasNext() )
{

try


{
sensorName = scanner.next();
sensorType = scanner.next();
sensorVendor = scanner.next();
sensorVersion = scanner.next();
maxRange = scanner.next();
powerDissipation = scanner.next();
resolution = scanner.next();
accuracy = scanner.next();
timeStamp = scanner.next();
values[0] = scanner.next();
values[1] = scanner.next();
values[2] = scanner.next();
}

catch (NoSuchElementException e)
{

e.printStackTrace();
}

Log.d(TAG,"Name: "+ sensorName.trim()
+ ", Type: " + sensorType
+ ", Vendor: " + sensorVendor
+ ", Version: " + sensorVersion
+ ", Max Range: " + maxRange
+ ", Power: " + powerDissipation
+ ", Resolution: " + resolution
+ ", accuracy: " + accuracy
+ ", Timestamp: " + timeStamp
+ ", Values[0]: " + values[0]
+ ", Values[1]: " + values[1]
+ ", Values[2]: " + values[2]);

scanner.close();
}
}

}

> > > > > > Excerpted fromhttp://developer.android.com/reference/java/util/UUID.html-Hidequoted...-

Reply all
Reply to author
Forward
0 new messages