# Connect ESP32 MicroPython to AWS IoT

**URL:** <https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475>\
**Category:** Lessons Discussion\
**Created:** [June 19, 2019, 2:25pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475 "2019-06-19T14:25:44Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ReneMolenaar](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/renemolenaar/32/488_2.png) [@ReneMolenaar](https://forum.networklessons.com/u/ReneMolenaar)\
**Post date:** [June 19, 2019, 2:25pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/1 "2019-06-19T14:25:44Z")

</div>

This topic is to discuss the following lesson:  
  
[https://networklessons.comconnect-esp32-micropython-to-aws-iot](https://networklessons.comconnect-esp32-micropython-to-aws-iot)

---

<div class="post-metadata">

**Author:** ![aleemiiui](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@aleemiiui](https://forum.networklessons.com/u/aleemiiui)\
**Post date:** [June 21, 2019, 5:08pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/2 "2019-06-21T17:08:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lagapidis](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/lagapidis/32/4949_2.png) [@lagapidis](https://forum.networklessons.com/u/lagapidis)\
**Post date:** [June 24, 2019, 6:04am UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/3 "2019-06-24T06:04:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![compras](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@compras](https://forum.networklessons.com/u/compras)\
**Post date:** [April 11, 2020, 9:44am UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/4 "2020-04-11T09:44:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ReneMolenaar](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/renemolenaar/32/488_2.png) [@ReneMolenaar](https://forum.networklessons.com/u/ReneMolenaar)\
**Post date:** [April 16, 2020, 12:44pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/5 "2020-04-16T12:44:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mquintanaa.ia](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@mquintanaa.ia](https://forum.networklessons.com/u/mquintanaa.ia)\
**Post date:** [April 28, 2020, 1:27am UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/6 "2020-04-28T01:27:34Z")

</div>

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/](http://micropython.org/download/esp32/)

After installing this, it works just fine!

Thank you for this lesson 🙂

---

<div class="post-metadata">

**Author:** ![christian\_kirst](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/c/839c29/32.png) [@christian\_kirst](https://forum.networklessons.com/u/christian_kirst)\
**Post date:** [May 15, 2020, 3:21pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/7 "2020-05-15T15:21:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ReneMolenaar](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/renemolenaar/32/488_2.png) [@ReneMolenaar](https://forum.networklessons.com/u/ReneMolenaar)\
**Post date:** [May 18, 2020, 2:24pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/8 "2020-05-18T14:24:33Z")

</div>

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](https://www.sslshopper.com/ssl-converter.html).

Rene

---

<div class="post-metadata">

**Author:** ![imyousuf](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/imyousuf/32/2827_2.png) [@imyousuf](https://forum.networklessons.com/u/imyousuf)\
**Post date:** [May 20, 2020, 5:03pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/9 "2020-05-20T17:03:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lagapidis](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/lagapidis/32/4949_2.png) [@lagapidis](https://forum.networklessons.com/u/lagapidis)\
**Post date:** [May 22, 2020, 7:39am UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/10 "2020-05-22T07:39:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kenneth.w.23.98](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/k/91b2a8/32.png) [@kenneth.w.23.98](https://forum.networklessons.com/u/kenneth.w.23.98)\
**Post date:** [August 21, 2021, 4:05am UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/11 "2021-08-21T04:05:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lagapidis](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/lagapidis/32/4949_2.png) [@lagapidis](https://forum.networklessons.com/u/lagapidis)\
**Post date:** [August 24, 2021, 3:30am UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/12 "2021-08-24T03:30:28Z")

</div>

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](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:

> <https://github.com/micropython/micropython/issues/5929>
>
> mbedtls\_ssl\_handshake error: -2880
> I (14912) wifi:Traceback (most recent call l…ast):
> File "main.py", line 99, in \<module\>
> File "main.py", line 96, in \<module\>
> File "main.py", line 69, in mqtt
> File "umqtt/simple.py", line 61, in connect
> OSError: \[Errno 5\] EIO
> 
> Fails on the latest firmware but works on any of the 2019 builds - tried it with esp32-idf3-20191220-v1.12.bin and it works but needed BLE and hence upgraded to 2020 versions and fails on all the March/April releases.

It looks like an update in firmware fixes the problem…

I hope this has been helpful!

Laz

---

<div class="post-metadata">

**Author:** ![daniellavin98](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/d/ecc23a/32.png) [@daniellavin98](https://forum.networklessons.com/u/daniellavin98)\
**Post date:** [March 8, 2022, 3:10pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/13 "2022-03-08T15:10:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lagapidis](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/lagapidis/32/4949_2.png) [@lagapidis](https://forum.networklessons.com/u/lagapidis)\
**Post date:** [March 10, 2022, 5:57am UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/14 "2022-03-10T05:57:18Z")

</div>

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.

> **[Diagnosing connectivity issues - AWS IoT Core](https://docs.aws.amazon.com/iot/latest/developerguide/diagnosing-connectivity-issues.html)**
>
> A successful connection to AWS IoT requires:

> **[Device communication protocols - AWS IoT Core](https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html)**
>
> Use the AWS IoT MQTT protocol to publish and subscribe to messages and the HTTPS protocol to publish messages.

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

---

<div class="post-metadata">

**Author:** ![AkshaySunkara](https://cdn-forum.networklessons.com/letter_avatar_proxy/v4/letter/a/b9bd4f/32.png) [@AkshaySunkara](https://forum.networklessons.com/u/AkshaySunkara)\
**Post date:** [June 12, 2024, 5:18pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/15 "2024-06-12T17:18:05Z")

</div>

```auto
mqtt_client = MQTTClient(client_id = mqtt_client_id, server=mqtt_host, port=mqtt_port, keepalive=5000, ssl=True, ssl_params={"cert":certificate_contents, "key":key_contents, "server_side":False})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unexpected keyword argument 'ssl_params'

```

I keep getting this error for some reason. Is there anyone who can help me? I kinda need to connect the ESP32 to an AWS server urgently

---

<div class="post-metadata">

**Author:** ![ReneMolenaar](https://cdn-forum.networklessons.com/user_avatar/forum.networklessons.com/renemolenaar/32/488_2.png) [@ReneMolenaar](https://forum.networklessons.com/u/ReneMolenaar)\
**Post date:** [June 18, 2024, 2:22pm UTC](https://forum.networklessons.com/t/connect-esp32-micropython-to-aws-iot/7475/16 "2024-06-18T14:22:13Z")

</div>

Hello @AkshaySunkara ,

Can you share your full code? What import statement did you use

MQTTClient doesn’t recognize `ssl_params` as input. It’s possible you use the wrong library.

The mPython library supports ssl\_params as an input:

> **[umqtt.simple — MQTT client function — mPython board 2.2.2 documentation](https://mpython.readthedocs.io/en/v2.2.1/library/mPython/umqtt.simple.html)**

```auto
classumqtt.simple.MQTTClient(client_id, server, port=0, user=None, password=None, keepalive=0, ssl=False, ssl_params={})
client_id
server
port
user
password
keepalive
ssl
ssl_params

```
