Skip to content

Cant publish to aws mqtt broker over websockets #241

@anubhav-jhalani

Description

@anubhav-jhalani

Confirm by changing [ ] to [x] below:

Platform/OS/Device
Ubuntu 20.06 , x86-64 arch

Describe the question
I am following aws api to connect to mqtt over websockets. Below is my code:

credentials_provider = AwsCredentialsProvider.new_static(
            access_key_id = auth_response_dictionary['user']['accessKeyId'],
            secret_access_key = auth_response_dictionary['user']['secretKey'],
            session_token = auth_response_dictionary['user']['sessionToken']
            )
       
    
    event_loop_group = io.EventLoopGroup(1)
    host_resolver = io.DefaultHostResolver(event_loop_group)
    client_bootstrap = io.ClientBootstrap(event_loop_group, host_resolver)    
    
    mqtt_connection = mqtt_connection_builder.websockets_with_default_aws_signing(
            endpoint=auth_response_dictionary['user']['iotEndpoint'],
            region=auth_response_dictionary['user']['region'],
            credentials_provider=credentials_provider,
            client_bootstrap=client_bootstrap,
            client_id=clientId
            )

    print("Connecting to aws")
    # Make the connect() call
    connect_future = mqtt_connection.connect()
    # Future.result() waits until a result is available
    print('connect_future ' + str(connect_future))
    x= connect_future.result()
    print('connect_future ' + str(x))
    print("Connected!")
    
    future, packet_id = mqtt_connection.publish(topic=TOPIC, payload=json.dumps(message), qos=mqtt.QoS.AT_LEAST_ONCE)
    future, packet_id = mqtt_connection.publish(topic='test/po', payload=json.dumps(message), qos=mqtt.QoS.AT_LEAST_ONCE)
    print('future ' + str(future))
    print('future ' + str(packet_id))
    print('Publish End')

I am not getting any error while connecting and while publishing but I am not receiving any msgs on my aws mqtt broker when I subscribe to that topic in aws iot console in 'Test' section. I think that i have configured something wrong in either credentials_provider or client_bootstrap or both but dont know what.

Here are the printed logs

Connecting to aws
connect_future<Future at 0x7f605f942af0 state=pending>
connect_future{'session_present': False}
Connected!
future <Future at 0x7f605f8e54f0 state=pending>
future 3
Publish End

Can somebody please help?

Metadata

Metadata

Assignees

Labels

guidanceQuestion that needs advice or information.response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 2 days.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions