title: PyBluez 'Connection reset by peer' on a Raspberry Pi
body: <p>I'm trying to get the PiTooth example <a href="http://www.linuxuser.co.uk/tutorials/emulate-a-bluetooth-keyboard-with-the-raspberry-pi" rel="nofollow" title="from here">from here</a> working. I'm able to get the devices to pair successfully, but whenever I transmit data after approximately 5 seconds, I see the following:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./PiTooth.py", line 120, in &lt;module&gt;
      kb.event_loop(bt)
    File "./PiTooth.py", line 107, in event_loop
      bt.send_input(self.state)
    File "./PiTooth.py", line 80, in send_input
      self.cinterrupt.send(hex_str)
    File "&lt;string&gt;", line 5, in send
  bluetooth.btcommon.BluetoothError: (104, 'Connection reset by peer')
  </code></pre>
  
  <p>Any idea what I'm doing wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here's what <code>hcidump -a</code> shows:</p>
  
  <pre><code>&gt; HCI Event: Command Complete (0x0e) plen 4
      Write Class of Device (0x03|0x0024) ncmd 1
      status 0x00
  &gt; HCI Event: Command Complete (0x0e) plen 4
      Write Local Name (0x03|0x0013) ncmd 1
      status 0x00
  &gt; HCI Event: Command Complete (0x0e) plen 252
      Read Local Name (0x03|0x0014) ncmd 1
      status 0x00 name 'PiToothFsr'
  &gt; HCI Event: Command Complete (0x0e) plen 4
      Write Scan Enable (0x03|0x001a) ncmd 1
      status 0x00
  &gt; HCI Event: Command Complete (0x0e) plen 5
      Read Scan Enable (0x03|0x0019) ncmd 1
      status 0x00 enable 3
  &gt; HCI Event: Command Complete (0x0e) plen 4
      Write Extended Inquiry Response (0x03|0x0052) ncmd 1
      status 0x00
  &gt; HCI Event: Connect Request (0x04) plen 10
      bdaddr 28:CF:DA:D7:98:F3 class 0x38010c type ACL
  &gt; HCI Event: Command Status (0x0f) plen 4
      Accept Connection Request (0x01|0x0009) status 0x00 ncmd 1
  &gt; HCI Event: Connect Complete (0x03) plen 11
      status 0x00 handle 12 bdaddr 28:CF:DA:D7:98:F3 type ACL encrypt 0x00
  &gt; HCI Event: Command Status (0x0f) plen 4
      Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
  &gt; HCI Event: Command Complete (0x0e) plen 10
      Link Key Request Reply (0x01|0x000b) ncmd 1
      status 0x00 bdaddr 28:CF:DA:D7:98:F3
  &gt; HCI Event: Read Remote Supported Features (0x0b) plen 11
      status 0x00 handle 12
      Features: 0xff 0xff 0xcf 0xfe 0x9b 0xff 0x79 0x83
  &gt; HCI Event: Command Status (0x0f) plen 4
      Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
  &gt; HCI Event: Read Remote Extended Features (0x23) plen 13
      status 0x00 handle 12 page 1 max 1
      Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
  &gt; HCI Event: Command Status (0x0f) plen 4
      Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
  &gt; HCI Event: Remote Name Req Complete (0x07) plen 255
      status 0x00 bdaddr 28:CF:DA:D7:98:F3 name 'Macbook Pro'
  &gt; HCI Event: Encrypt Change (0x08) plen 4
      status 0x00 handle 12 encrypt 0x01
  &gt; HCI Event: Command Complete (0x0e) plen 4
      Write Extended Inquiry Response (0x03|0x0052) ncmd 1
      status 0x00
  &gt; HCI Event: Command Status (0x0f) plen 4
      Disconnect (0x01|0x0006) status 0x00 ncmd 1
  &gt; HCI Event: Disconn Complete (0x05) plen 4
      status 0x00 handle 12 reason 0x16
      Reason: Connection Terminated by Local Host
  </code></pre>