Transport endpoint is not connected error
<p>I'm developing a Python interface to a robot via Bluetooth. I'm getting a "Transport endpoint is not connected error".</p>

<p>Traceback error:</p>

<pre><code>jigsaw@UbuntuPublic:~$ python mobot2.py
step 1
step 2
Traceback (most recent call last):
  File "mobot2.py", line 51, in &lt;module&gt;
    mobot = Mobot()
  File "mobot2.py", line 9, in __init__
    self.socket.connect((mac_address, 1))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 112] Host is down
sending command
Exception socket.error: (107, 'Transport endpoint is not connected') in &lt;bound method Mobot.__del__ of &lt;__main__.Mobot object at 0x8d7c2ac&gt;&gt; ignored
</code></pre>

<p>The code is a class that connects to the robot and sends various commands:</p>

<pre><code>import socket
import time

class Mobot(object):
    def __init__(self, mac_address="00:06:66:46:41:FA"):
        print 'step 1'
        self.socket = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
        print 'step 2'        
        self.socket.connect((mac_address, 1))
        print 'step 3'

    def _write(self, data_bytes):
        print 'sending command'
        self.socket.send(bytes(data_bytes))
        print 'command sent'
        print 'receiving'
        data= self.socket.recv(1)
        if data== '':
          print "Socket broken"
        else:
          print "data ", data
    def ping(self):
        print 'pinging'
        self._write([0x30, 0x03, 0x00])
        print 'sent ping'

    def drive(self, command, duration=1.0):
        self._write(command)
        time.sleep(duration)
        self.stop()

    def forwards(self, duration=1.0):
        self.drive(0x16, duration)

    def reverse(self, duration=1.0):
        self.drive(0x26, duration)

    def left(self, duration=1.0):
        self.drive(0x57, duration)

    def right(self, duration=1.0):
        self.drive(0x67, duration)

    def stop(self):
        self._write(0x00)

    def __del__(self):
        self.stop()

if __name__ == "__main__":
    mobot = Mobot()
    mobot.ping()
</code></pre>
