(self, addr)
return data
Send MQTT magic packet to addr
        this is 0xf0 (mqtt reserved) 0x05(data length) 0xefcc3b2900 (data)
        Should receive 37 bytes containing the password for roomba at addr
        This is is 0xf0 (mqtt RESERVED) length (0x23 = 35) 0xefcc3b2900 (magic packet), 
        followed by 0xXXXX... (30 bytes of password). so 7 bytes, followed by 30 bytes of password
        total of 37 bytes
        Uses 10 second timeout for socket connection
Send MQTT magic packet to addr
        this is 0xf0 (mqtt reserved) 0x05(data length) 0xefcc3b2900 (data)
        Should receive 37 bytes containing the password for roomba at addr
        This is is 0xf0 (mqtt RESERVED) length (0x23 = 35) 0xefcc3b2900 (magic packet), 
        followed by 0xXXXX... (30 bytes of password). so 7 bytes, followed by 30 bytes of password
        total of 37 bytes
        Uses 10 second timeout for socket connection
Send MQTT magic packet to addr this is 0xf0 ( mqtt reserved ) 0x05 ( data length ) 0xefcc3b2900 ( data ) Should receive 37 bytes containing the password for roomba at addr This is is 0xf0 ( mqtt RESERVED ) length ( 0x23 = 35 ) 0xefcc3b2900 ( magic packet ) followed by 0xXXXX ... ( 30 bytes of password ) . so 7 bytes followed by 30 bytes of password total of 37 bytes Uses 10 second timeout for socket connection
def get_password_from_roomba(self, addr):
        '''
        Send MQTT magic packet to addr
        this is 0xf0 (mqtt reserved) 0x05(data length) 0xefcc3b2900 (data)
        Should receive 37 bytes containing the password for roomba at addr
        This is is 0xf0 (mqtt RESERVED) length (0x23 = 35) 0xefcc3b2900 (magic packet), 
        followed by 0xXXXX... (30 bytes of password). so 7 bytes, followed by 30 bytes of password
        total of 37 bytes
        Uses 10 second timeout for socket connection
        '''
        data = b''
        packet = bytes.fromhex('f005efcc3b2900')
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(10)
        
        #context = ssl.SSLContext(ssl.PROTOCOL_TLS)
        context = ssl.SSLContext()
        #context.set_ciphers('DEFAULT@SECLEVEL=1:HIGH:!DH:!aNULL')
        wrappedSocket = context.wrap_socket(sock)
        
        try:
            wrappedSocket.connect((addr, 8883))
            self.log.debug('Connection Successful')
            wrappedSocket.send(packet)
            self.log.debug('Waiting for data')
        
            while len(data) < 37:
                data_received = wrappedSocket.recv(1024)
                data+= data_received
                if len(data_received) == 0:
                    self.log.info("socket closed")
                    break
                
            wrappedSocket.close()
            return data
            
        except socket.timeout as e:
            self.log.error('Connection Timeout Error (for {}): {}'.format(addr, e))
        except (ConnectionRefusedError, OSError) as e:
            if e.errno == 111:      #errno.ECONNREFUSED
                self.log.error('Unable to Connect to roomba at ip {}, make sure nothing else is connected (app?), '
                               'as only one connection at a time is allowed'.format(addr))
            elif e.errno == 113:    #errno.No Route to Host
                self.log.error('Unable to contact roomba on ip {} is the ip correct?'.format(addr))
            else:
                self.log.error("Connection Error (for {}): {}".format(addr, e))
        except Exception as e:
            self.log.exception(e)

        self.log.error('Unable to get password from roomba')
        return data
def get_password_from_roomba ( self , addr ) : data = b'' packet = bytes . fromhex ( 'f005efcc3b2900' ) sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) sock . settimeout ( 10 ) #context = ssl.SSLContext(ssl.PROTOCOL_TLS) context = ssl . SSLContext ( ) #context.set_ciphers('DEFAULT@SECLEVEL=1:HIGH:!DH:!aNULL') wrappedSocket = context . wrap_socket ( sock ) try : wrappedSocket . connect ( ( addr , 8883 ) ) self . log . debug ( 'Connection Successful' ) wrappedSocket . send ( packet ) self . log . debug ( 'Waiting for data' ) while len ( data ) < 37 : data_received = wrappedSocket . recv ( 1024 ) data += data_received if len ( data_received ) == 0 : self . log . info ( "socket closed" ) break wrappedSocket . close ( ) return data except socket . timeout as e : self . log . error ( 'Connection Timeout Error (for {}): {}' . format ( addr , e ) ) except ( ConnectionRefusedError , OSError ) as e : if e . errno == 111 : #errno.ECONNREFUSED self . log . error ( 'Unable to Connect to roomba at ip {}, make sure nothing else is connected (app?), ' 'as only one connection at a time is allowed' . format ( addr ) ) elif e . errno == 113 : #errno.No Route to Host self . log . error ( 'Unable to contact roomba on ip {} is the ip correct?' . format ( addr ) ) else : self . log . error ( "Connection Error (for {}): {}" . format ( addr , e ) ) except Exception as e : self . log . exception ( e ) self . log . error ( 'Unable to get password from roomba' ) return data