Skip to content

MQTT Client unable to connect to AWS MQTT broker

0

I am currently working on integrating MQTT communication with AWS IoT Core and would appreciate your assistance with a connectivity issue.

Using an MQTT client application on my Linux PC ( Mosquitto ), I was able to successfully connect to AWS IoT Core and observe messages on the MQTT test client. This confirms that the endpoint and certificates are valid and functional.

I used the same certificates and endpoint on my embedded device, but the device is unable to establish a connection with AWS IoT Core.

For all tests, I monitored logs using both CloudWatch and Device Advisor. When the device connects successfully, I can see detailed logs including event types and other relevant information. However, in the case of MQTT connection failures, I did not find any comprehensive logs or specific error messages indicating the reason for the failure.

Could you please guide me on how to debug this issue? Are there any other way to check the failure logs with complete information in the AWS Console that can help identify why the connection from the embedded device is failing?

I am happy to provide any additional information or logs if needed.

asked a year ago782 views

5 Answers
1

Your device does not provide the clientId when connecting, while the clientId is visible in the Linux connection log. Review your firmware and add the clientId when you establish the MQTT connectivity.

0

To debug the MQTT connection issue with your embedded device, there are several steps you can take:

  1. Verify the endpoint: Double-check that you're using the correct AWS IoT Core endpoint. You can obtain this using the AWS CLI command: aws iot describe-endpoint --endpoint-type iot:Data-ATS. Ensure the endpoint includes "-ats" in the URL.

  2. Certificate and key verification: Confirm that the device certificate, private key, and root CA certificate are correctly configured on your embedded device. Make sure you're using the Amazon Root CA 1 certificate for AWS IoT Core.

  3. Policy permissions: Review the IoT policy attached to your device certificate. It should allow iot:Connect, iot:Publish, iot:Subscribe, and iot:Receive for the required topics.

  4. Time synchronization: Ensure your embedded device has accurate time synchronization. TLS handshakes require correct time settings.

  5. TLS version: Verify that your embedded device supports and is configured to use TLS 1.2 or later, as required by AWS IoT Core.

  6. Memory and buffer sizes: Check if your embedded device has sufficient memory allocated for the MQTT client and TLS operations. Increase buffer sizes if necessary.

  7. Network stability: Verify the network connection on your embedded device is stable and can reach the AWS IoT Core endpoint.

  8. Enable verbose logging: If possible, enable more detailed logging on your embedded device's MQTT client library to get more information about the connection attempt.

  9. Use AWS Device Advisor: This tool can help diagnose connectivity issues between your device and AWS IoT Core by running specific tests.

  10. Consider MQTT over WebSocket: If you continue to face issues, try using MQTT over WebSocket (port 443) as it can bypass certain port restrictions.

  11. Check SDK and dependencies: Ensure you're using the latest version of the AWS IoT Device SDK and that all dependencies are up to date.

If you still can't identify the issue, you may need to implement more granular error reporting in your embedded device code to pinpoint where exactly the connection is failing. This could involve adding debug statements at various stages of the connection process.

Remember that while CloudWatch and Device Advisor are helpful, they may not capture all failure scenarios, especially if the connection isn't being established in the first place. Focus on gathering more detailed logs from your embedded device itself to get a clearer picture of what's happening during the connection attempt.
Sources
ESP32 Fails to Connect to AWS IoT Core via MQTT (TLS Handshake Error) | AWS re:Post
Issue: AWS IoT MQTT Test Client stuck at "Fetching client endpoint" | AWS re:Post

answered a year ago

0

I’ve captured logs from CloudWatch, and while all event types are visible when the device connects successfully, the logs don’t provide any specific reason when the connection to MQTT fails. Could you please guide me on where to find detailed logs or diagnostics in AWS IoT Core that explain the cause of connection failures?

answered a year ago

0

Ensure that your AWS IoT Core logs are set to the DEBUG level.

awsiot

Please share the exact mosquitto invocation and the firmware MQTT code snippet.

Typical reasons for MQTT connectivity issues are incorrect (or omitted) Client ID and TLS configuration.

0

I enabled the debug log level and captured the failure log from CloudWatch, as shown in the attached screenshot which is tested with my embedded device. Enter image description here

However, when I tested the same MQTT credentials on my Linux PCusing some application, the connection was successful. The screenshot of the successful connection is also attached. Enter image description here

Please look into it.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.