<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Failed to connect Lopy with AWS and MQTT.]]></title><description><![CDATA[<p dir="auto">Hello, good day to all.</p>
<p dir="auto">I am trying to connect my LoPy device with AWS through the MQTT client, when I connect through MQTTfx with the certificates I have no problem, however when I do the tests with the device I get errors.</p>
<pre><code>import time #Importamos la libreria para los delay
from mqttclient import MQTTClient #Importamos la libreria para la solicitud

#MQTT Configuration
DISCONNECTED = 0
CONNECTING = 1
CONNECTED = 2
DEVICE_ID = &quot;12345&quot;
HOST = &quot;a1uva9z7kasg52.iot.us-west-2.amazonaws.com&quot;
TOPIC_DOWNLOAD = &quot;Download&quot;
TOPIC_UPLOAD = &quot;my/topic&quot;

state = DISCONNECTED
connection = None

def _recv_msg_callback(topic, msg):
    print(&quot;Received: {} from Topic: {}&quot;.format(msg, topic))

def _send_msg(msg):
    global connection
    connection.publish(TOPIC_UPLOAD, msg)

def run():
    global state
    global connection

    while True:
        # Wait for connection
        while state != CONNECTED:
            try:
                state = CONNECTING
                connection = MQTTClient(DEVICE_ID, server=HOST, port=8883)
                connection.connect(ssl=True, certfile='/flash/cert/certificate.pem.crt', keyfile='/flash/cert/private.pem.key', ca_certs='/flash/cert/certificate.pem.ca.crt')
                state = CONNECTED
            except:
                print('Error connecting to the server')
                time.sleep(0.5)
                continue

        print('Connected!')

        # Subscribe for messages
        connection.set_callback(_recv_msg_callback)
        connection.subscribe(TOPIC_DOWNLOAD)

        while state == CONNECTED:
            connection.check_msg()
            msg = '{&quot;Name&quot;:&quot;Pycom&quot;, &quot;Data&quot;:&quot;Test&quot;}'
            print('Sending: ' + msg)
            _send_msg(msg)
            time.sleep(2.0)
</code></pre>
<p dir="auto">The error goes here:</p>
<pre><code>connection.connect(ssl=True, certfile='/flash/cert/certificate.pem.crt', keyfile='/flash/cert/private.pem.key', ca_certs='/flash/cert/certificate.pem.ca.crt')
</code></pre>
<p dir="auto">It is as follows:</p>
<pre><code>Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/flash/lib/mqttclient.py&quot;, line 79, in connect
OSError: -1
</code></pre>
<p dir="auto">I hope you can help me. Thank you.</p>
]]></description><link>https://forum.pycom.io/topic/1465/failed-to-connect-lopy-with-aws-and-mqtt</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 19:04:50 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/1465.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 07 Jul 2017 14:45:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Failed to connect Lopy with AWS and MQTT. on Fri, 07 Jul 2017 14:45:16 GMT]]></title><description><![CDATA[<p dir="auto">Hello, good day to all.</p>
<p dir="auto">I am trying to connect my LoPy device with AWS through the MQTT client, when I connect through MQTTfx with the certificates I have no problem, however when I do the tests with the device I get errors.</p>
<pre><code>import time #Importamos la libreria para los delay
from mqttclient import MQTTClient #Importamos la libreria para la solicitud

#MQTT Configuration
DISCONNECTED = 0
CONNECTING = 1
CONNECTED = 2
DEVICE_ID = &quot;12345&quot;
HOST = &quot;a1uva9z7kasg52.iot.us-west-2.amazonaws.com&quot;
TOPIC_DOWNLOAD = &quot;Download&quot;
TOPIC_UPLOAD = &quot;my/topic&quot;

state = DISCONNECTED
connection = None

def _recv_msg_callback(topic, msg):
    print(&quot;Received: {} from Topic: {}&quot;.format(msg, topic))

def _send_msg(msg):
    global connection
    connection.publish(TOPIC_UPLOAD, msg)

def run():
    global state
    global connection

    while True:
        # Wait for connection
        while state != CONNECTED:
            try:
                state = CONNECTING
                connection = MQTTClient(DEVICE_ID, server=HOST, port=8883)
                connection.connect(ssl=True, certfile='/flash/cert/certificate.pem.crt', keyfile='/flash/cert/private.pem.key', ca_certs='/flash/cert/certificate.pem.ca.crt')
                state = CONNECTED
            except:
                print('Error connecting to the server')
                time.sleep(0.5)
                continue

        print('Connected!')

        # Subscribe for messages
        connection.set_callback(_recv_msg_callback)
        connection.subscribe(TOPIC_DOWNLOAD)

        while state == CONNECTED:
            connection.check_msg()
            msg = '{&quot;Name&quot;:&quot;Pycom&quot;, &quot;Data&quot;:&quot;Test&quot;}'
            print('Sending: ' + msg)
            _send_msg(msg)
            time.sleep(2.0)
</code></pre>
<p dir="auto">The error goes here:</p>
<pre><code>connection.connect(ssl=True, certfile='/flash/cert/certificate.pem.crt', keyfile='/flash/cert/private.pem.key', ca_certs='/flash/cert/certificate.pem.ca.crt')
</code></pre>
<p dir="auto">It is as follows:</p>
<pre><code>Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/flash/lib/mqttclient.py&quot;, line 79, in connect
OSError: -1
</code></pre>
<p dir="auto">I hope you can help me. Thank you.</p>
]]></description><link>https://forum.pycom.io/post/9173</link><guid isPermaLink="true">https://forum.pycom.io/post/9173</guid><dc:creator><![CDATA[scg94]]></dc:creator><pubDate>Fri, 07 Jul 2017 14:45:16 GMT</pubDate></item></channel></rss>