Publish and Subscribe Time out in my code while sample project is working

0

Hi,
Im created my own AWS client class that i am using in one of my python project.
The sample project connect_device_package is working perfectly and i can see the message coming on the aws iot console but when i'm trying to subscribe and publish in my code i have time out exception

Any help would be greatly appreciated!

def __init__(self, host, rootCA, cert,key):
        #for websocket use 443
        port = 8883  
        clientId = "basicPubSub"
        self.topic = "Telemetry"
        mode = "both"
        useWebsocket = False

        # Init AWSIoTMQTTClient
        self.myAWSIoTMQTTClient = None
        if useWebsocket:
            self.myAWSIoTMQTTClient = AWSIoTMQTTClient(clientId, useWebsocket=True)
            self.myAWSIoTMQTTClient.configureEndpoint(host, port)
            self.myAWSIoTMQTTClient.configureCredentials(rootCA)
        else:
            self.myAWSIoTMQTTClient = AWSIoTMQTTClient(clientId)
            self.myAWSIoTMQTTClient.configureEndpoint(host, port)
            self.myAWSIoTMQTTClient.configureCredentials(rootCA, key, cert)

        # AWSIoTMQTTClient connection configuration
        self.myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20)
        self.myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1) 
        self.myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
        self.myAWSIoTMQTTClient.configureConnectDisconnectTimeout(15)  # 10 sec
        self.myAWSIoTMQTTClient.configureMQTTOperationTimeout(15)  # 5 sec

        self.myAWSIoTMQTTClient.connect()
        if mode == 'both' or mode == 'subscribe':
           self.myAWSIoTMQTTClient.subscribe(self.topic, 1, self.customCallback)
        time.sleep(2)
           self.myAWSIoTMQTTClient.publish(self.topic, 'This is a test Publish', 1)

Exceptions:

INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:MqttCore initialized
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Client id: basicPubSub
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Protocol version: MQTTv3.1.1
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Authentication type: TLSv1.2 certificate based Mutual Auth.
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Configuring endpoint...
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Configuring certificates...
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Configuring reconnect back off timing...
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Base quiet time: 1.000000 sec
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Max quiet time: 32.000000 sec
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Stable connection time: 20.000000 sec
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Configuring offline requests queueing: max queue size: -1
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Configuring offline requests queue draining interval: 0.500000 sec
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Configuring connect/disconnect time out: 15.000000 sec
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Configuring MQTT operation time out: 15.000000 sec
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Performing sync connect...
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Performing async connect...
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Keep-alive: 600.000000 sec
INFO:AWSIoTPythonSDK.core.protocol.mqtt_core:Performing sync subscribe...
ERROR:AWSIoTPythonSDK.core.protocol.mqtt_core:Subscribe timed out
Traceback (most recent call last):
  File "main.py", line 75, in <module>
    main(args)
  File "main.py", line 44, in main
    client = NetworkQueue(local_dump, AWSNetworkClient(mqttHost,rootCA,cert,key))
  File "AWSNetworkClient.py", line 45, in __init__
    self.myAWSIoTMQTTClient.subscribe(self.topic, 0, self.customCallback)
  File "AWSIoTPythonSDK/MQTTLib.py", line 668, in subscribe
    return self._mqtt_core.subscribe(topic, QoS, callback)
  File "AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 302, in subscribe
    raise subscribeTimeoutException()
AWSIoTPythonSDK.exception.AWSIoTExceptions.subscribeTimeoutException

Same thing for the Publish:

File "AWSIoTPythonSDK/MQTTLib.py", line 600, in publish
    return self._mqtt_core.publish(topic, payload, QoS, False)  # Disable retain for publish by now
  File "AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 269, in publish
    raise publishTimeoutException()
AWSIoTPythonSDK.exception.AWSIoTExceptions.publishTimeoutException

Did someone had the same issue ?
If yes, How did you solve that ?
Thanks

Edited by: Doombqr on Feb 17, 2019 12:27 PM

Doombqr
asked 5 years ago600 views
1 Answer
0

It was just a policy issue.

I followed this article and it fixes it.
http://www.fhilitski.com/2016/09/connecting-mqtt-fx-to-aws-iot/

Thanks anyway

Edited by: Doombqr on Feb 17, 2019 2:56 PM

Doombqr
answered 5 years ago
profile picture
EXPERT
reviewed 17 days 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.

Guidelines for Answering Questions