Project when deployed raise a subscribeTimeoutException()
sqnidea opened this issue · 3 comments
The project is working fine locally, but when I deployed it in Render It is now raising a subscription error
Hello guys,
I am encountering issue in my project. This project is getting data from my aws iot core via subscribing into topic. It is working fine locally. However, when I deployed it in Render, It is now raising a:
raise subscribeTimeoutException()
AWSIoTPythonSDK.exception.AWSIoTExceptions.subscribeTimeoutException
Expected Behavior
I am expecting that it will connect to my aws cloud after deployment to Render since it is working locally for me.
Current Behavior
Here is the traceback of the error:
Subscribe timed out
Aug 26 07:21:35 AM [2023-08-25 23:21:35,017] ERROR in app: Exception on /_dash-update-component [POST]
Aug 26 07:21:35 AM Traceback (most recent call last):
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 2529, in wsgi_app
Aug 26 07:21:35 AM response = self.full_dispatch_request()
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1825, in full_dispatch_request
Aug 26 07:21:35 AM rv = self.handle_user_exception(e)
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1823, in full_dispatch_request
Aug 26 07:21:35 AM rv = self.dispatch_request()
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1799, in dispatch_request
Aug 26 07:21:35 AM return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/dash/dash.py", line 1264, in dispatch
Aug 26 07:21:35 AM ctx.run(
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/dash/_callback.py", line 437, in add_context
Aug 26 07:21:35 AM output_value = func(*func_args, **func_kwargs) # %% callback invoked %%
Aug 26 07:21:35 AM File "/opt/render/project/src/src/app.py", line 153, in update_output
Aug 26 07:21:35 AM myAWSIoTMQTTClient.subscribe(wincc_Level_Tag, 1, customCallback)
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/AWSIoTPythonSDK/MQTTLib.py", line 703, in subscribe
Aug 26 07:21:35 AM return self._mqtt_core.subscribe(topic, QoS, callback)
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 306, in subscribe
Aug 26 07:21:35 AM raise subscribeTimeoutException()
Reproduction Steps
myAWSIoTMQTTClient = AWSIoTPyMQTT.AWSIoTMQTTClient(CLIENT_ID)
myAWSIoTMQTTClient.configureEndpoint(ENDPOINT, 8883)
myAWSIoTMQTTClient.configureCredentials(PATH_TO_ROOT, PATH_TO_KEY, PATH_TO_CERT)
myAWSIoTMQTTClient.connect()
def customCallback(client, userdata, message):
payload = message.payload
try:
data = json.loads(payload)
raw_date_cloud_ts = str(data["time"])
name = str(data["name"])
value = str(data["value"])
# Convert the raw date string to a datetime object
datetime_obj = datetime.strptime(raw_date_cloud_ts, "%Y-%m-%dT%H:%M:%S.%fZ")
# Add 8 hours to the datetime object
updated_datetime = datetime_obj + timedelta(hours=8)
# Format the updated datetime object as "yyyy-mm-dd hh:mm"
date = updated_datetime.strftime("%Y-%m-%d %H:%M")
except Exception as e:
print(f'Error: {e}')
return
print("Received message on topic:", message.topic)
#print("Name:", name, "Value:", value)
with latest_data_lock:
if name == "Level_Percentage":
latest_data["lp_date"] = date
latest_data["lp_name"] = name
latest_data["lp_value"] = value
elif name == "Counter_5_to_10":
latest_data["c5to10_date"] = date
latest_data["c5to10_name"] = name
latest_data["c5to10_value"] = value
elif name == "Counter_11_to_20":
latest_data["c11to20_date"] = date
latest_data["c11to20_name"] = name
latest_data["c11to20_value"] = value
@app.callback(Output(webTagOutput, 'children'),
Input(webDropdown, 'value'),
Input(webCyclicUpdates, 'n_intervals'),
prevent_initial_call=True
)
def update_output(user_dropdown_input, webCyclicUpdates):
#Declaration of Topic
wincc_Level_Tag = "wincc_thing/WebConnector_Wincc/Level_Percentage"
wincc_Counter5_10 = "wincc_thing/WebConnector_Wincc/Counter_5_to_10"
wincc_Counter11_20 = "wincc_thing/WebConnector_Wincc/Counter_11_to_20"
#Subscription to aws cloud per topic
myAWSIoTMQTTClient.subscribe(wincc_Level_Tag, 1, customCallback)
myAWSIoTMQTTClient.subscribe(wincc_Counter5_10, 1, customCallback)
myAWSIoTMQTTClient.subscribe(wincc_Counter11_20, 1, customCallback)
with latest_data_lock:
if user_dropdown_input == 'tag_lp':
output_value = f" \nDate: {latest_data['lp_date']} \nName: {latest_data['lp_name']} \nValue: {latest_data['lp_value']}"
elif user_dropdown_input == 'tag_c5-10':
output_value = f" \nDate: {latest_data['c5to10_date']} \nName: {latest_data['c5to10_name']} \nValue: {latest_data['c5to10_value']}"
elif user_dropdown_input == 'tag_c11-20':
output_value = f" \nDate: {latest_data['c11to20_date']} \nName: {latest_data['c11to20_name']} \nValue: {latest_data['c11to20_value']}"
#eturn dcc.Markdown(f"```{output_text3}```")
else:
output_value = "Select a valid tag from the dropdown"
#return dcc.Markdown(f"```{output_text}```")
return dcc.Markdown(f"```\n{output_value}\n")
Possible Solution
The Render web service server is in "Oregon (US West)" while my aws iot core is using the "Asia Pacific (Tokyo) ap-northeast-1" could it affect the network connectivity?
Also how can I increase the subscription timeout?
Additional Information/Context
Hello guys,
I am encountering issue in my project. This project is getting data from my aws iot core via subscribing into topic. It is working fine locally. However, when I deployed it in Render, It is now raising a:
raise subscribeTimeoutException()
AWSIoTPythonSDK.exception.AWSIoTExceptions.subscribeTimeoutException
what could be the problem?
-I already changed the policy into like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "arn:aws:iot:ap-northeast-1:187614391418:*"
}
]
}
by the way, the Render web service server is in "Oregon (US West)" while my aws iot core is using the "Asia Pacific (Tokyo) ap-northeast-1" could it affect the network connectivity? but I doubt.
Here is the traceback of the error:
Subscribe timed out
Aug 26 07:21:35 AM [2023-08-25 23:21:35,017] ERROR in app: Exception on /_dash-update-component [POST]
Aug 26 07:21:35 AM Traceback (most recent call last):
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 2529, in wsgi_app
Aug 26 07:21:35 AM response = self.full_dispatch_request()
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1825, in full_dispatch_request
Aug 26 07:21:35 AM rv = self.handle_user_exception(e)
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1823, in full_dispatch_request
Aug 26 07:21:35 AM rv = self.dispatch_request()
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/flask/app.py", line 1799, in dispatch_request
Aug 26 07:21:35 AM return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/dash/dash.py", line 1264, in dispatch
Aug 26 07:21:35 AM ctx.run(
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/dash/_callback.py", line 437, in add_context
Aug 26 07:21:35 AM output_value = func(*func_args, **func_kwargs) # %% callback invoked %%
Aug 26 07:21:35 AM File "/opt/render/project/src/src/app.py", line 153, in update_output
Aug 26 07:21:35 AM myAWSIoTMQTTClient.subscribe(wincc_Level_Tag, 1, customCallback)
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/AWSIoTPythonSDK/MQTTLib.py", line 703, in subscribe
Aug 26 07:21:35 AM return self._mqtt_core.subscribe(topic, QoS, callback)
Aug 26 07:21:35 AM File "/opt/render/project/src/.venv/lib/python3.10/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 306, in subscribe
Aug 26 07:21:35 AM raise subscribeTimeoutException()
SDK version used
1.5.2
Environment details (OS name and version, etc.)
Render Web Service
The Render web service server is in "Oregon (US West)" while my aws iot core is using the "Asia Pacific (Tokyo) ap-northeast-1" could it affect the network connectivity?
I don't think this would prevent your from connecting correctly if you have your settings configured correctly. I don't think increasing the timeout will help (but you can do that with this: myMQTTClient.configureMQTTOperationTimeout(5)
Are you able to connect and publish any messages before you try to subscribe to anything? According to this documentation on Render Web Service:
Only HTTPS requests (port 443) are accepted
As shown on this AWS documentation the IoT Core only supports publishes over HTTPS. I'm not sure if this is the reason that your subscription request is failing, but I would recommend trying to see if you can publish anything first and then we can work from there.
Protocol | Operations supported | Authentication | Port | ALPN protocol name |
---|---|---|---|---|
MQTT over WebSocket | Publish, Subscribe | Signature Version 4 | 443 | N/A |
MQTT over WebSocket | Publish, Subscribe | Custom authentication | 443 | N/A |
MQTT | Publish, Subscribe | X.509 client certificate | 443† | x-amzn-mqtt-ca |
MQTT | Publish, Subscribe | X.509 client certificate | 8883 | N/A |
MQTT | Publish, Subscribe | Custom authentication | 443† | mqtt |
HTTPS | Publish only | Signature Version 4 | 443 | N/A |
HTTPS | Publish only | X.509 client certificate | 443† | x-amzn-http-ca |
HTTPS | Publish only | X.509 client certificate | 8443 | N/A |
HTTPS | Publish only | Custom authentication | 443 | N/A |
Hey guys. Thank you for your response. I have already solved this problem. The problem is in the hosting or the web server. Now my project is now deployed in google cloud. It works well in gcloud.
The problem is in Render, server is in oregon and having a connectivity issue to my aws which is deployed in tokyo server.
Thank you very much
⚠️ COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.