AWS IoT Core MQTT Connection Timeout Error

0

I am working on a project that involves connecting an MQTT client to AWS IoT Core. I am using the AWSIoTPythonSDK and paho.mqtt.client libraries in Python. The client is intended to subscribe to two topics and publish the received data to AWS IoT Core.

However, I am encountering a "AWSIoTPythonSDK.exception.AWSIoTExceptions.connectTimeoutException" error after a few seconds of successful operation. The client connects to the MQTT broker (IP: 140.114.89.210, Port: 1883) and subscribes to the topics "wt/generator" and "wt/ws3."

The code successfully connects to the broker and receives data from both topics. However, after a few seconds, it throws the mentioned "connectTimeoutException." I've checked my network settings, security groups, and IAM role permissions, and they seem to be correctly configured. The AWS IoT Core endpoint and credentials are also accurate.

Could someone help me identify the possible reasons for this timeout exception and suggest potential solutions? Are there any additional troubleshooting steps I can take to resolve this issue?

Any guidance or insights would be greatly appreciated. Thank you!

Here's the relevant part of my code:

# [Include code snippet from data_fetcher.py where the MQTT client is initialized and on_connect, on_message functions are defined]

mqttServer = "140.114.89.210"
generator_topic = "wt/generator"
ws3_topic = "wt/ws3"

# AWS IoT Core endpoint (replace with your actual endpoint)
IOT_CORE_ENDPOINT = "xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com"
# [Other relevant configurations]

client.connect(mqttServer, 1883, 120)
client.loop_forever()

已提問 10 個月前檢視次數 1321 次
2 個答案
1
profile pictureAWS
專家
Greg_B
已回答 10 個月前
0

Hi, Check a few things:

  • Do you have an active certificate attached to your "thing"?
  • Do you have a policy attached to the certificates?
  • What does your policy look like? Does it allow the correct permissions to the correct topics?

Cheers! Oscar.

AWS
已回答 10 個月前
  • Hello Sir, Thank You so much for your response,

    I want to mention some points about this suggestion

    All the certificates which are attached in the code are active.

    I also have attached the policy which looks something like this:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:", "Resource": "" } ] }

    I think this policy will allow all the permissions required for both the topics

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南