Gpy AWS IOT Mqtt



  • Re: UMQTT & AWS IoT

    Hi All,

    I'm new to Pycom.

    I've been trying to understand and set up communication between Gpy and AWS. I followed the guide presented here but could not establish connection between the two.

    I get the error 'Could not establish MQTT connection' in my watch window.

    For clarity,

    1. I am using a Gpy on the expansion board ver 3.0 with the wifi antenna. I've been able to connect to my wifi. I have the correct configurations for the board set up and have pymakr installed on Atom ide.
    2. I have created AWS thing, downloaded all the certificates, created and linked policies and certificates to the AWS thing and to each other as well.
    3. I would like to mention that the certificates I downloaded from AWS have the following extensions : d82XXXX860-certificate.pem.crt and d82XXXX860-private.pem.key. I tried modifying the extensions to d82XXXX860-certificate.crt and d82XXXX860-private.pem as per the example code but ended up with the same error.
    4. During the creation of AWS certificates, all other certificates provide a downloadable file, where as the rootCA certificate download link takes me to this page with 4 options for CA files. I've tried with all the certificates individually but it hasn't helped.

    Any pointers will be really appreciated.



  • This post is deleted!


  • @pranithmichael I had no luck with the Pycom AWS library. I was finally able to get connected to MQTT using simple.py.

    The certificates were a little tricky to figure out (i.e. which root CA cert to use). The certificates should be in PEM format (typically extensions of .crt, .key, and .pem are PEM formatted). The root CA certificate I used was RSA 2048 bit Root CA 1.

    Here's my connect function. I hope this helps.

    from simple import MQTTClient
    
    def mqttConnect():
        global connection
        global state
        global mqtt
        wdt.feed()
        log('mqttConnect')
        while state != config.CONNECTED:
            try:
                gc.collect()
                state = config.CONNECTING
                log("connecting to mqtt")
                mqtt = MQTTClient(config.CLIENT_ID, server=config.AWS_HOST,
                                  port=config.AWS_PORT, keepalive=600, ssl=True,
                                  ssl_params={"certfile": config.AWS_CLIENT_CERT,
                                              "keyfile": config.AWS_PRIVATE_KEY,
                                              "ca_certs": config.AWS_ROOT_CA})
                # if mqtt.connect(600):
                mqtt.connect()
                state = config.CONNECTED
                log('MQTT connection established!')
    
            except Exception as e:
                log(e)
                log('could not establish MQTT connection')
                time.sleep(10)
                continue
        log('end mqttConnect')
    

 

Hello World?

Pylife on Kickstarter - November 2018








Back Us On Kickstarter >

Pycom on Twitter