Note that there are some explanatory texts on larger screens.

plurals
  1. POBluetooth connection between Android and Linux (RPi) lost on first write action
    primarykey
    data
    text
    <p>So I have been working on a project in which a device running Android (API level = 14) must connect to a server running Linux (to be specific: a Raspberry Pi) via Bluetooth. When a connection is established, the app sends an encrypted XML string to the RPi. The RPi must decrypt this string, parse the XML and perform the corresponding action. The result of the action is send back to the Android device.</p> <p>So far, I have managed to create a connection between the app and the RPi (which runs the latest version of the <a href="http://www.bluez.org/" rel="nofollow noreferrer">Bluez package</a>). The RPi has a Bluetooth 4.0 dongle from Targus. The point where I'm stuck at, is when I try to send a string from the app to the RPi. The Bluetooth socket appears to be closed by then. Logcat gives the message <code>Connection reset by peer</code>.</p> <p>The code used to create the socket is as follows: </p> <pre><code>Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); tmp = (BluetoothSocket) m.invoke(device, 1); </code></pre> <p>Logcat output is as follows:</p> <pre><code>06-20 14:29:42.224: DEBUG/RPiService(24273): ---------- [ CONNECTION ESTABLISHED ] ---------- 06-20 14:29:42.224: DEBUG/RPiService(24273): connected, Socket Type:Secure 06-20 14:29:42.229: DEBUG/RPiService(24273): create ConnectedThread: Secure 06-20 14:29:43.734: DEBUG/RPiService(24273): setState() 2 -&gt; 3 06-20 14:29:43.739: DEBUG/RPiService(24273): Connection reset by peer 06-20 14:29:43.744: WARN/System.err(24273): java.io.IOException: Connection reset by peer 06-20 14:29:43.754: WARN/System.err(24273): at android.bluetooth.BluetoothSocket.writeNative(Native Method) 06-20 14:29:43.759: WARN/System.err(24273): at android.bluetooth.BluetoothSocket.write(BluetoothSocket.java:398) 06-20 14:29:43.764: WARN/System.err(24273): at android.bluetooth.BluetoothOutputStream.write(BluetoothOutputStream.java:85) 06-20 14:29:43.769: WARN/System.err(24273): at com.example.BluetoothTest.RPiService$ConnectedThread.run(RPiService.java:344) </code></pre> <p>On the side of the RPi, I am essentially running the following example server script from the <a href="http://code.google.com/p/pybluez/source/browse/trunk/examples/simple/rfcomm-server.py" rel="nofollow noreferrer">PyBluez</a> package: </p> <pre><code>from bluetooth import * server_sock=BluetoothSocket( RFCOMM ) server_sock.bind(("",PORT_ANY)) server_sock.listen(1) port = server_sock.getsockname()[1] uuid = "00001101-0000-1000-8000-00805F9B34FB" advertise_service( server_sock, "SampleServer", service_id = uuid, service_classes = [ uuid, SERIAL_PORT_CLASS ], profiles = [ SERIAL_PORT_PROFILE ] ) print "Waiting for connection on RFCOMM channel %d" % port client_sock, client_info = server_sock.accept() print "Accepted connection from ", client_info try: while True: data = client_sock.recv(1024) if len(data) == 0: break print "received [%s]" % data except IOError: pass print "disconnected" client_sock.close() server_sock.close() print "all done" </code></pre> <p>I've tried various UUIDs suggested by posts I read on SO including <code>00001101-0000-1000-8000-00805F9B34FB</code>, <code>94f39d29-7d6d-437d-973b-fba39e49d4ee</code> and <code>00000003-0000-1000-8000-00805F9B34FB</code> (always the same on both ends of the connection). It appears to be that the first one is correct as I can't even make a connection when using an other UUID.</p> <p>What may be the cause for the connection to be reset by the RPi? If anyone would be able to point me in the right direction, I'd be grateful.</p>
    singulars
    1. This table or related slice is empty.
    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