Cannot create MQTT connection LoPy: Socket create error: -17168



  • Hi, I am trying to connect to AWS IoT using aws-pycom library found on this github repo.

    However the program does not succeed in creating a connection.
    I got the output "Socket create error: -17168"
    The part "Socket create error" is printed by the lib itself. I cannot find any info about the error code. Also no results when converting this number to hex 0x4310

    Here is a snippet of the code that fails. This code can be found in MQTTMsgHandler.py

    def createSocketConnection(self):
            self._conn_state_mutex.acquire()
            self._connection_state = mqttConst.STATE_CONNECTING
            self._conn_state_mutex.release()
            try:
                if self._sock:
                    self._poll.unregister(self._sock)
                    self._sock.close()
                    self._sock = None
    
                self._sock = socket.socket()
                if self._cafile:
                    self._sock = ssl.wrap_socket(
                        self._sock,
                        certfile=self._cert,
                        keyfile=self._key,
                        ca_certs=self._cafile,
                        cert_reqs=ssl.CERT_REQUIRED)
    
                print('Program fails on the next line')
                self._sock.connect(socket.getaddrinfo(
                    self._host, self._port)[0][-1])
    
                self._poll.register(self._sock, select.POLLIN)
            except socket.error as err:
                print("Socket create error: {0}".format(err))
    
                self._conn_state_mutex.acquire()
                self._connection_state = mqttConst.STATE_DISCONNECTED
                self._conn_state_mutex.release()
    
                return False
    
            return True
    

    Some extra context:

    • Port: 8883
    • Device: LoPy
    • All configuration i used (host, port, certificates, clientId) are valid since I tested this with another MQTT client and it worked

    Any help or info is much appreciated


Log in to reply
 

Pycom on Twitter