title: Bluetooth python handle reconnection automatically
body: <p>I made a python program on Raspberry Pi able to connect in classic bluetooth (not BLE) with sensors. To do this, I used socket programming. I can perfectly connect to several sensors simultaneously and exchange data (receive/transmit) between the Raspberry Pi and the sensors.</p>
  <p>Overall, the most important lines in my code are the following:</p>
  <pre><code>import bluetooth
  import socket
  
  addr_sensor1 = xx:xx:xx:xx:xx:xx
  port_sensor1 = 1
  
  sock_sensor1=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
  sock_sensor1.connect((addr_sensor1, port_sensor1))
  
  sock_sensor1.send(&quot;Message\n&quot;)
  
  while True : 
      while char != '\n' :
          char = str(sock_sensor1.recv(1).decode(&quot;utf-8&quot;, &quot;ignore&quot;))
          data = data + char
      print(str(data))
  </code></pre>
  <p>The problem I can't solve is when one of the sensors is out of range of the Raspberry Pi, it ends up disconnecting. I would like it if when the sensor is within range of the Raspberry Pi again, the python script is able to automatically reconnect to the sensor.</p>
  <p>Do you know of any method to solve this problem? Even another method with other libraries?</p>
  <p>Thanks in advance</p>