ESP AWS IOT SDK for MQTT Mutual Authentication Example Error

Dear Community,
I was Trying to integrate ESP-AWS-IOT SDK to my ESP32-C3-MINI. I have found the following issues in my terminal.

E (467664) coreMQTT: A single byte was not read from the transport: transportStatus=-1.
E (467664) coreMQTT: CONNACK recv failed with status = MQTTRecvFailed.
E (467674) coreMQTT: MQTT connection failed with status = MQTTRecvFailed.
E (467674) coreMQTT: Connection with MQTT broker failed with status MQTTRecvFailed.
E (467684) coreMQTT: Connection to the broker failed, all attempts exhausted.
E (467694) coreMQTT: Failed to connect to MQTT broker a2ymunmj15xks7-ats.iot.ap-south-1.amazonaws.com.

Github link: esp-aws-iot/examples/mqtt/tls_mutual_auth at master · espressif/esp-aws-iot · GitHub
I have created a things and policy in AWS IOT Core and followed the instruction as per the Readme.md file of the project. But unfortunately running into this problem. If anyone already experienced this problem and found a solution, kindly share with me. thank you for your kind feedback.

I looked at that SDK, but it seemed a bit complicated. I was able to do mTLS with AWS IoT with standard Arduino tooling, using the "ArduinoMqttClient" library by Arduino, currently beta at version 0.1.8

You use the AWS wizard to generate a new certificate and private key for a new Thing. You also need the Amazon Root Certificate, which you can grab a few different ways, like through your browser after going to the host. Then plug those three PEM strings into the standard WiFiClientSecure methods

  wifi.setCACert(certs.host_ca);
  wifi.setCertificate(certs.device_cert);
  wifi.setPrivateKey (certs.device_private_key);

This will allow AWS IoT to recognize the Thing when you connect, and apply the corresponding policy (or policies). You should then be able to publish and subscribe to the sample topics. You can even do "provisioning by claim" with not too much custom code, after setting up the provisioning template.

One "exercise for the reader" is how to secure the private key(s). That would depend on what hardware you have available and your risk tolerance.

BTW, the category "Networking, Protocols, and Devices" would seem like a better one for an MQTT topic like this.

1 Like

I will definitely try the Arduino way of integration of AWS IOT core. But Unfortunately, I want to try to build on that AWS IOT SDK. Therefore, I need to know these troubleshooting issue. Thank you for pointing out another method of doing the same, And I definitely agree that the SDK is way too complicated.

I found my problem already. It is related to the AWS policy, not the code itself. In the policy "iot:connect" where "Arn" is fixing the "Client ID", I had to put the same "Client ID" using "idf.py menuconfig" to the configuration. then the problem will be fixed. I hope anyone having this same trouble with ESP-AWS-IOT SDK can fix or look into the AWS policy more carefully. thank

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.