title: Check for successful connection using rfcomm
body: <p>I am trying to connect my phone to my RaspberryPi using a blue tooth dongle (not trying to do anything earth shattering, just determine when my phone is in the area). If I turn my phone's blue tooth <strong>on</strong> and issue the following command, I get the following output (before anyone starts preaching to me about how this is a breach of security, let me remind you that that is <strong>not</strong> my actual phone bluetooth id):</p>
  
  <p><strong>command:</strong></p>
  
  <pre><code>sudo rfcomm connect 0 AA:BB:CC:DD:EE:FF 10
  echo $?
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <pre><code>Connected /dev/rfcomm0 to AA:BB:CC:DD:EE:FF on channel 10
  Press CTRL-C for hangup
  0
  </code></pre>
  
  <p>Now if I turn my phone's bluetooth <strong>off</strong>, and issue the same command, I get the following output (again, all id's have been changed to protect the innocent).</p>
  
  <p><strong>command:</strong></p>
  
  <pre><code>sudo rfcomm connect 0 AA:BB:CC:DD:EE:FF 10
  echo $?
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <pre><code>Can't connect RFCOMM socket: Host is down
  0
  </code></pre>
  
  <p>Since I am trying to determine when the phone is in the room and when it leaves, I need some way (some other way) of detecting when the dongle can and can not connect to it. How can I go about achieving this? (NOTE: I tried removing the phone from the building and even turning it off completely)</p>
  
  <p><strong>EDIT:</strong> I have considered catching the <code>stderr</code> message and testing it like so</p>
  
  <pre><code>error=$`sudo rfcomm connect 0 AA:BB:CC:DD:EE:FF 10 &gt;/dev/null` &amp;
  if [ $error=="Can't connect RFCOMM socket: Host is down" ]
  then
      ...
  fi;
  </code></pre>
  
  <p>But the problem is that rfcomm has to run in the background.</p>