Connect ESP32 MicroPython to AWS IoT

This topic is to discuss the following lesson:

From where we can get the device to practice and whats the cost of device , currently I am in Saudia Arabia

Hello Muhammad

If you do a quick search online, you will see that the device is available on many sites including eBay. I’m not sure what the shipping capabilities are for each of these retailers for Saudi Arabia, but you will have to look at the policies of each provider.

I hope this has been helpful!

Laz

Hi
why do you upload:

/4b7db071de-certificate.pem.crt
/4b7db071de-private.pem.key
/4b7db071de-public.pem.key
/AmazonRootCA1.pem
/AmazonRootCA3.pem

all certifications if you just use private.pem and certificate.pem for the connection?

Thanks

Hello Vic,

In this example, technically, you only need these two files:

/4b7db071de-certificate.pem.crt
/4b7db071de-private.pem.key

You could use the IoT root CA certificates to verify that you are communicating with the actual AWS IoT servers, and some server impersonating them. In this example, I didn’t.

Rene

Hello Everyone,

The code doesn’t work for the new versions of Micropython for ESP32. I got it to work with the following version:
GENERIC : Firmware with ESP-IDF v3.x —> esp32-idf3-20190529-v1.11.bin
From http://micropython.org/download/esp32/

After installing this, it works just fine!

Thank you for this lesson :slight_smile:

The coded does not work for me (ESP-WROOM-32 DevKit V1). Using Firmware version v1.11, the esp just reboots on the connect call. Newer versions tell me “invalid key”. I did some research and I suspect that I have to use a der-encoded key file. Do you know anything about that?

Hi Christian,

Did you also try the one I used?

(esp32-20190611-v1.11-44-g8b18cfede.bin)

Just to make sure it’s a software issue, not a hardware issue.

It is possible to convert certificate types. You could try to convert the AWS IOT X.509 certificates to DER:

openssl x509 -in input.crt -out input.der -outform DER
openssl x509 -in input.der -inform DER -out output.pem -outform PEM

You can convert any certificate with openssl but if you are trying this in a lab and want a more convenient solution, there are online GUI converters.

Rene

I could follow the lesson to the dot and it did work! Thank you. But needed to generate DER version of the certificate and key file using the following commands -
openssl x509 -in -certificate.pem.crt -out -certificate.pem.der -outform DER
openssl rsa -in -private.pem.key -out -private.pem.der -outform DER
I am using ESP8266 with esp8266-20191220-v1.12.bin and did successfully connected to AWS IOT.

Hello Imran

Thanks for sharing that! It’s so important for the community to share information that will make it easier for others to implement the lessons.

Thanks again!

Laz

Hi, in trying to follow the lesson but in the step of connecting to the MQTT client, when i use the command : mqtt_client.connect() i get for response a 0. Then when i try to send the test message nothing happens, and in the third time it is giving me now this error: mbedtls_ssl_handshake error: -2880. Im using an ESP32 with the esp32-idf3-20190529-v1.11.bin and i convert both the certificate and the private key to DER.

Thanks.

Now i get this error in the aws iot console “disconnectReason”: “CLIENT_ERROR”, , can someone help me with this?

Hello Kenneth

A response code of 0 means that the connection is accepted, so you’re good there. For additional return codes, take a look at this:

https://notes.networklessons.com/mqtt-return-codes

Concerning the error you mention, it seems to be related to firmware. Others have faced a similar error, and you can find out more about it here:

It looks like an update in firmware fixes the problem…

I hope this has been helpful!

Laz

Hi
I am able to connect to the cloud using mqtt_client.connect() but when I try sending the test message, nothing happens. It seems to be working as there are no errors being thrown but the message never shows in the topic.
Can someone help me with this please?

Hello Daniel

Hmm, that’s interesting. The first thing I would say is to make sure your MQTT parameters are the same as those in the lesson. I know it sounds obvious, and you’ve probably already done so, but I’m just reiterating for clarity. Secondly, ensure that the certificate is installed and that all other parameters are as shown in the lesson.

Beyond this, I can suggest some troubleshooting resources that are available from AWS for the IoT core that may be helpful.

If you’re unable to resolve this, let us know and I’ll have Rene take a look as well…

I hope this has been helpful!

Laz