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.



  • @pranithmichael said in Gpy AWS IOT Mqtt:

    Just to be sure. The CLIENT_ID is the AWS thing name, AWS_HOST is my host location at xxsomethingxx.iot.us-east-2.amazonaws.com and AWS_PORT is 8883. right?

    That is correct.



  • @pranithmichael Did you try the AWS example from Pycom?
    https://docs.pycom.io/tutorials/all/aws
    After some guesswork which certificate is what and enabling the certificate upload in pymakr, it worked right away (Wipy).



  • Thank you for having taken the time to reply @reidfo

    I downloaded the Python SDK for Linux and OSx that AWS provides while creating a 'aws thing'. There is a start.sh script file that generates a root CA file. It matches the Root CA 1 certificate that you have pointed to.

    I set the following of extensions: .crt for certificate file, .key for the private file and .pem for the RootCA file, but didnt have any luck connecting to AWS.

    Global settings for the project on the ATOM IDE allows us to mention the type of files that can be uploaded on to the pycom module.
    I tried including 'ca' files in order to upload rootCA.ca file but that didn't seem to work either.

    Just to be sure. The CLIENT_ID is the AWS thing name, AWS_HOST is my host location at xxsomethingxx.iot.us-east-2.amazonaws.com and AWS_PORT is 8883. right?

    All the more confusing to me is the AWS example found in the documentation config.py , where CLIENT_ID and THING_NAME are mentioned as two separate entities.



  • 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