fabiberlin / android-bluetooth

Automatically exported from code.google.com/p/android-bluetooth
0 stars 0 forks source link

Connecting to device out of range - no Exception #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Connect to ANY Bluetooth device (previously paired or unknown/fake MAC).
remoteBluetoothDevice = localBluetoothDevice.getRemoteBluetoothDevice
("01:23:45:67:89:AB");
bluetoothSocket = remoteBluetoothDevice.openSocket(i);
inputStream = bluetoothSocket.getInputStream();
2. Exectution continues, no exception is thrown.

What is the expected output? What do you see instead?
Currently there is no obvious way how to find if the chosen device is in 
range. I guess openSocket method should throw IOException or something in 
case selected device is unreachable.

What version of the product are you using? On what operating system?
BT API 0.2 in Eclipse on Windows 7

Original issue reported on code.google.com by smartmad...@gmail.com on 7 Sep 2009 at 7:03

GoogleCodeExporter commented 8 years ago
Actually, I can't reproduce the error. Running the following code in an 
Activity:

try {
  LocalBluetoothDevice local = LocalBluetoothDevice.initLocalDevice(this);

  RemoteBluetoothDevice remoteBluetoothDevice =
local.getRemoteBluetoothDevice("01:23:45:67:89:AB");

  BluetoothSocket bluetoothSocket = remoteBluetoothDevice.openSocket(12);

} catch (Exception e) {
  System.out.println("THERE WAS AN ERROR WITH BLUETOOTH!");
}

The exception is thrown by the openSocket() method and the string "THERE WAS AN 
ERROR
WITH BLUETOOTH!" is printed. 

Original comment by gerda...@gmail.com on 12 Sep 2009 at 11:37

GoogleCodeExporter commented 8 years ago
Here's attached test project in Eclipse cause I'm not sure if I'm missing 
something.

openSocket() just doesn't throw anything. (Running FW CyanogenMod-4.0.4. on G1)

Original comment by smartmad...@gmail.com on 13 Sep 2009 at 2:37

Attachments:

GoogleCodeExporter commented 8 years ago
hi smartmadsoft.com:

Are you sure you also don't get any error message in logs? If you use logcat to 
monitor output message, there should be something to indicate you it can not 
connect 
to remote device.

BTW: have you ever really connected to other device and did data communication 
by 
using this API? I got problem on this but am not sure if it's due to my code or 
my 
Hero device or something else

Original comment by likunarm...@gmail.com on 14 Sep 2009 at 8:21

GoogleCodeExporter commented 8 years ago
I have the same issue. No execption is thrown when I call openSocket(port) to a 
device which is switched off. 

I run HTC Dream and HTC Magic both with latest original T-Mobile build (1.5r3) 
CRC1.

Original comment by bonifaz....@gmail.com on 14 Sep 2009 at 8:50

GoogleCodeExporter commented 8 years ago
I tried the test project uploaded by smartmadsoft, the error information will 
be 
showed in lagcat: 

No route to host (113)

which means although there is no exeception thrown, the connection is still not 
correct. 

To bonifaz.kaufmann: can you connect to online device normally? 

Original comment by likunarm...@gmail.com on 14 Sep 2009 at 9:25

GoogleCodeExporter commented 8 years ago
Yes everything works fine when I connect to a online device.

Original comment by bonifaz....@gmail.com on 14 Sep 2009 at 9:54

GoogleCodeExporter commented 8 years ago
I get this error in Logcat when I try to connect to an offline device.

09-14 18:03:14.921: ERROR/bluetooth_RfcommSocket.cpp(1889): connect error: Host 
is 
down (112)

but no exception which I could catch.

Original comment by bonifaz....@gmail.com on 14 Sep 2009 at 10:04

GoogleCodeExporter commented 8 years ago
Emmm......bonifaz.kaufmann, would you mind to share more information, like 
talking 
about online device, you mean another android phone, or any device supporting 
SDD 
profile? I am using Hero and did exact procedure as the example project, but 
always 
get 
connect error: No route to host (113) 

did you do it like this?

localDevice = LocalBluetoothDevice.initLocalDevice(this); 
remoteDevice = localDevice.getRemoteBluetoothDevice(address_kkli); 
RemoteBluetoothDeviceEventHandler listener = new 
RemoteBluetoothDeviceEventHandler(); 
listener.device = remoteDevice; 
remoteDevice.setListener(listener); 
remoteDevice.pair(); 

In pair:

RemoteBluetoothDevice device 
device.openSocket(port); 

I would be very appreciate if you can help!

Original comment by likunarm...@gmail.com on 15 Sep 2009 at 3:38

GoogleCodeExporter commented 8 years ago
Well, I use basically RFCOMM and SDP and I connect an Android phone to another 
Bluetooth Device with SPP. When I say online-device I mean a bluetooth device 
which 
is turned on and ready to receive pairing and connection requests.

I figured out that if you have paired your device once, you don't need to pair 
it 
again, since the localbluetooth device still remembers the last paired device.
So I just call isPaired() and I only pair again if this is false, if it is true 
I 
immidiately call openSocket() otherwise I pair and then call openSocket().

I tried both, openSocket(port) within the callback method paired() and 
openSocket 
without pairing before, but with an already paired device. In either case it 
raises 
no exception, but says "Host is down (112)" but this comes from the C-Library 
itself 
and can not be caught by a try-catch block.

The error you got (113) is only if you don't have a paired device but try to 
call 
openSocket I suppose.

Nevertheless, I can't say if I am connected or not, since I can't catch the 
"host is 
down" error. I just will try to catch an error instead of an exception next. 
Hopefully this will do the trick but not very convinced about that.

Original comment by bonifaz....@gmail.com on 15 Sep 2009 at 4:24

GoogleCodeExporter commented 8 years ago
The reason I said it's weird is, I did pair the two device and apparently the 
pairing 
is successful, I can see the paired device, which is Hero, from my custom 
device. But 
still get this error.

The critical point is, did you ever try to communicate DATA between the device 
and 
your phone, and succeed in it?

Original comment by likunarm...@gmail.com on 15 Sep 2009 at 4:31

GoogleCodeExporter commented 8 years ago
Yes definitely. I can send and receive data over RFCOMM using inputStream and 
outputStream.

Original comment by bonifaz....@gmail.com on 15 Sep 2009 at 4:32

GoogleCodeExporter commented 8 years ago
What if it requires the pin? Do you input it by the dialog from notification 
bar or 
you implement a special pin pair function?

BTW, for the port number in openSocket function, I thought it doesn't matter, 
am I 
correct or it does matter?

Original comment by likunarm...@gmail.com on 15 Sep 2009 at 5:39

GoogleCodeExporter commented 8 years ago
I see the same Error in log as bonifaz.kaufmann (but no 
Error/Throwable/Exception is 
thrown): ERROR/bluetooth_RfcommSocket.cpp(1889): connect error: Host is 
down (112)

Here's attached stack trace if it's any help.

Original comment by smartmad...@gmail.com on 15 Sep 2009 at 6:36

Attachments:

GoogleCodeExporter commented 8 years ago
Port number does matter, I use port 1.
setPin(pin) does not work for me really (for some reason it just ignores it), I 
have 
to use the notification bar with the dialog to enter a pin when I pair the 
first 
time.

Original comment by bonifaz....@gmail.com on 15 Sep 2009 at 1:11

GoogleCodeExporter commented 8 years ago
Emmmmm, then I don't know now, I tried many times but always get 

connect error: No route to host (113) 

Regardless of connecting to laptop(support SPP) or my custom device

One quick question, why do you use port 1, is it the configuration in Android? 
Or some 
other reasons?

Original comment by likunarm...@gmail.com on 15 Sep 2009 at 4:33

GoogleCodeExporter commented 8 years ago
I use port 1 since my device I am connecting to uses that port.

Original comment by bonifaz....@gmail.com on 15 Sep 2009 at 5:31

GoogleCodeExporter commented 8 years ago
Hello everybody.

I've checked that some errors where not captured by the API. In fact, some 
errors are
reported as booleans instead of exceptions by the Bluetooth service. 

Next week I'll check in the new version.

Stefano.

Original comment by gerda...@gmail.com on 1 Oct 2009 at 12:39

GoogleCodeExporter commented 8 years ago
How to find and connect the RFCOMM service? Like j2me.

Original comment by zxpp...@gmail.com on 5 Oct 2009 at 1:19

GoogleCodeExporter commented 8 years ago
Hi Stefano,

I tried your new version 0.3b1, which is great. A lot of stupp seems to be 
added.
However, 

try {
  bluetoothSocket = remoteBluetoothDevice.openSocket(port);
  output = bluetoothSocket.getOutputStream();
  input = bluetoothSocket.getInputStream();
}
catch (BluetoothException be) {
  Log.e(TAG, "BluetoothException. Device not online!");
} 
catch (Exception e) {
  Log.e(TAG, "Device not found!");
}

still throws no Exception when the device is not online.

By the way, will you try to support Android 1.6? Or does this version 0.3b1 
already 
work with Donut?

Original comment by bonifaz....@gmail.com on 7 Oct 2009 at 5:47

GoogleCodeExporter commented 8 years ago
Hello Bonifaz.

Please, check the 0.3b2. 

The library has been tested on HTC Dream and HTC Tatoo, both with official Donut
firmware, and it works.

Please, let me know if now it works on you stuff.

Original comment by gerda...@gmail.com on 17 Oct 2009 at 8:38

GoogleCodeExporter commented 8 years ago

Original comment by gerda...@gmail.com on 17 Oct 2009 at 8:38

GoogleCodeExporter commented 8 years ago
I will test it tomorrow when I am at the Lab.

Original comment by bonifaz....@gmail.com on 19 Oct 2009 at 12:31

GoogleCodeExporter commented 8 years ago
BluetoothException is thrown now, finally this gives us a way to find out if a 
device 
is connected or not.

Thanks a lot Stefano

p.s. tested on 1.5 and 1.6 (HTC Magic and G1)

Original comment by bonifaz....@gmail.com on 20 Oct 2009 at 4:06

GoogleCodeExporter commented 8 years ago
Thank you Bonifaz for your feedback, really appreciated.

Original comment by gerda...@gmail.com on 20 Oct 2009 at 4:45

GoogleCodeExporter commented 8 years ago
Hi guys, with HTC Hero or HTC Magic, I get 
connect error: No route to host (113) 

Everytime. but the device can connect to it no problem through settings.

Something wrong in the API? Or something I do wrong?

The device is paired:
        try 
        {
            LocalBluetoothDevice.initLocalDevice(this);
            mLocalBluetoothDevice = LocalBluetoothDevice.getLocalDevice();
            if (mLocalBluetoothDevice == null)
            {
                log("Device does not support Bluetooth", RED);
                return;
            }
            mJabraDevice = mLocalBluetoothDevice.getRemoteBluetoothDevice("00:07:A4:BD:AC:51");
            if (mJabraDevice == null)
            {
                log("Jabra device was not found", RED);
                return;
            }
            log("Jabra device was found", GREEN);
            mJabraDevice.setPin("0000");
            mBluetoothSocket = mJabraDevice.openSocket(1);
        } 
        catch (BluetoothException e) 
        {
            log(e.getMessage(), RED);
            e.printStackTrace();
            return;
        } 
        catch (Exception e) 
        {
            log(e.getMessage(), RED);
            e.printStackTrace();
            return;
        }
        log("Connected", GREEN);

Original comment by daivuk@gmail.com on 24 Feb 2010 at 9:14

GoogleCodeExporter commented 8 years ago
Hi daivuk,

did you solve the problem? I also get a "No route to host (113)" on a HTC 
Tattoo.

regards

Stefan

Original comment by stefanpa...@googlemail.com on 17 Mar 2010 at 2:29

GoogleCodeExporter commented 8 years ago
Can you tell us how it is fixed?

Original comment by smartine...@gmail.com on 24 Feb 2012 at 10:19