Note that there are some explanatory texts on larger screens.

plurals
  1. POBluetooth RFCOMM / SDP connection to a RS232 adapter in android
    primarykey
    data
    text
    <p>I am trying to use the Bluetooth Chat sample API app that google provides to connect to a bluetooth RS232 adapter hooked up to another device. Here is the app for reference:</p> <p><a href="http://developer.android.com/resources/samples/BluetoothChat/index.html" rel="noreferrer">http://developer.android.com/resources/samples/BluetoothChat/index.html</a></p> <p>And here is the spec sheet for the RS232 connector just for reference:</p> <p><a href="http://serialio.com/download/Docs/BlueSnap-guide-4.77_Commands.pdf" rel="noreferrer">http://serialio.com/download/Docs/BlueSnap-guide-4.77_Commands.pdf</a></p> <p>Well the problem is that when I go to connect to the device with:</p> <pre><code>mmSocket.connect(); (BluetoothSocket::connect()) </code></pre> <p>I always get an <code>IOException</code> error thrown by the <code>connect()</code> method. When I do a <code>toString</code> on the exception I get "Service discovery failed". My question is mostly what are the cases that would cause an <code>IOException</code> to get thrown in the connect method? I know those are in the source somewhere but I don't know exactly how the java layer that you write apps in and the C/C++ layer that contains the actual stacks interface. I know that it uses the bluez bluetooth stack which is written in C/C++ but not sure how that ties into the java layer which is what I would think is throwing the exception. Any help on pointing me to where I can try to dissect this issue would be incredible.</p> <p>Also just to note I am able to pair with the RS232 adapter just fine but I am never able to actually connect. Here is the logcat output for more reference:</p> <pre> I/ActivityManager( 1018): Displayed activity com.example.android.BluetoothChat/.DeviceListActivity: 326 ms (total 326 ms) E/BluetoothService.cpp( 1018): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) D/BluetoothChat( 1729): onActivityResult -1 D/BluetoothChatService( 1729): connect to: 00:06:66:03:0C:51 D/BluetoothChatService( 1729): setState() STATE_LISTEN -> STATE_CONNECTING E/BluetoothChat( 1729): + ON RESUME + I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_CONNECTING I/BluetoothChatService( 1729): BEGIN mConnectThread E/BluetoothService.cpp( 1018): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) E/BluetoothEventLoop.cpp( 1018): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/1498/hci0/dev_00_06_66_03_0C_51 I/BluetoothChatService( 1729): CONNECTION FAIL TOSTRING: java.io.IOException: Service discovery failed D/BluetoothChatService( 1729): setState() STATE_CONNECTING -> STATE_LISTEN D/BluetoothChatService( 1729): start D/BluetoothChatService( 1729): setState() STATE_LISTEN -> STATE_LISTEN I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_LISTEN V/BluetoothEventRedirector( 1080): Received android.bleutooth.device.action.UUID I/NotificationService( 1018): enqueueToast pkg=com.example.android.BluetoothChat callback=android.app.ITransientNotification$Stub$Proxy@446327c8 duration=0 I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_LISTEN E/BluetoothEventLoop.cpp( 1018): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/1498/hci0/dev_00_06_66_03_0C_51 V/BluetoothEventRedirector( 1080): Received android.bleutooth.device.action.UUID </pre> <p>The device I'm trying to connect to is the <code>00:06:66:03:0C:51</code> which I can scan for and apparently pair with just fine.</p> <hr> <p>The below is merged from a similar question which was successfully resolved by the selected answer here:</p> <h2><A HREF="http://stackoverflow.com/questions/2443572/how-can-one-connect-to-an-rfcomm-device-other-than-another-phone-in-android">How can one connect to an rfcomm device other than another phone in Android?</A></h2> <p>The Android API provides examples of using <A HREF="http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#listenUsingRfcommWithServiceRecord(java.lang.String,%20java.util.UUID)" rel="noreferrer">listenUsingRfcommWithServiceRecord()</A> to set up a socket and <A HREF="http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createRfcommSocketToServiceRecord(java.util.UUID)" rel="noreferrer">createRfcommSocketToServiceRecord()</A> to connect to that socket.</p> <p>I'm trying to connect to an embedded device with a <A HREF="http://www.sparkfun.com/commerce/product_info.php?products_id=582" rel="noreferrer">BlueSMiRF Gold</A> chip. My working Python code (using the <A HREF="http://code.google.com/p/pybluez/" rel="noreferrer">PyBluez</A> library), which I'd like to port to Android, is as follows:</p> <pre><code>sock = bluetooth.BluetoothSocket(proto=bluetooth.RFCOMM) sock.connect((device_addr, 1)) return sock.makefile() </code></pre> <p>...so the service to connect to is simply defined as channel 1, without any SDP lookup.</p> <p>As the only documented mechanism I see in the Android API does SDP lookup of a UUID, I'm slightly at a loss. Using "sdptool browse" from my Linux host comes up empty, so I surmise that the chip in question simply lacks SDP support.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload