I'm using:
Android 2.2.6 Gingerbread
leJOS 0.9.0
HOLOX BT-541 (gps device)
Windows 7 x64
What I am doing is this:
Connecting to a remote BT GPS device:
- Code: Select all
//Try find the GPS device. Returns true if found and false if not...
public boolean BTDeviceDetected() {
boolean GPSDetected = false;
try {
RemoteDevice rd = Bluetooth.getKnownDevice(GPS_Device_Name);
if (rd != null) {
GPSDevice = rd;
GPSDetected = true;
} else {
GPSDetected = false;
}
} catch (Exception ex) {
}
return GPSDetected;
}
//Attempt to connect to the GPS device. Returns true for success and false for a fail.
public boolean ConnectGPS() {
try {
Bluetooth.addDevice(GPSDevice);
btGPS = Bluetooth.connect(GPSDevice.getDeviceAddr(), NXTConnection.RAW, pin);
if (btGPS == null) {
result = false;//No connection
} else {
result = true;//Connection Successful
//Tried using openInputStream too. What's the difference?
in = btGPS.openDataInputStream();
gps = new GPS(in);
}
} catch (Exception ex) {
}
return result;
}
Next, once the BT GPS is connected, I attempt to have an Android phone connect:
- Code: Select all
public boolean connect() {
boolean success = false;
while (!success) {
btc = Bluetooth.waitForConnection(0, NXTConnection.RAW);
DIS = btc.openDataInputStream();
DOS = btc.openDataOutputStream();
if (btc != null) {
success = true;
connected = true;
}
}
return success;
}
The BT GPS in an outbound connection and the Android to NXT connection is an inbound one. For some reason It's really difficult to connect via android. The connection attempt made by the Android fails about 9 out of 10 times, although, sometimes I do manage to connect and everything works.
If I attempt to have the Android connect first and then the BT GPS, upon connecting to the BT GPS, a nullPointerException is thrown. It does connect to the BT GPS.
I thought that maybe I could put one of the connections to "sleep" and so tried using:
- Code: Select all
//called before we attempt to await for the Android to connect
BTConnection.closeStream();
and...
- Code: Select all
//called when the android has connected
BTConnection.openStream();
... but still not working.
Another thing I've tried is having the Android connect and then only later on once some data has been sent via Android to the NXT, connect the BT GPS - this seems to work.
I'm not sure, but is it possible that the streams are getting mixed up?
Does anyone have any advice or a solution?
Thanks,
Rich.
PS: I've got the dGPS sensor from Dexter Industries, but it takes ages to connect to a satellite and is impossible to connect a satellite when there are clouds in the sky, which from me living in London, is impossible to avoid. Anyone else have the same problem with the dGPS sensor?
