def reconnect(self):
        try:
            self.conn.expect(r'Disconnected', timeout=0.1)
            self.conn.sendline('connect')
            try:
                self.conn.expect(r'Connection successful', timeout=10)
                print("Reconnected to device: " + self.address)
            except pexpect.TIMEOUT:
                # Continue and try to reconnect next time
                print("Lost connection to device: " + self.address)
            return True
        except pexpect.TIMEOUT:
            # No need to reconnect
            return False
Check and attempt to reconnect to device if necessary
dataset/ETHPy150Open ALPSquid/thebutton-monitor/src/gatt.py/connect.reconnect