AWS-MQTT Connection

0 votes
Hello.
I'm using Amazon Web Services and I need to send/receive information from the AWS IoT Platform. But I'm unable to send or receive messages. It seems to me that there some issue with my connection to the platform. And, after double-checking my codes, I finally narrowed my problem down to the MQTT. Since I'm relatively new to the Internet of Things and Networking, I could've messed that part of the code. Could anybody help me with the script for the message broker connecting to the platform?
TIA!
Aug 23, 2018 in IoT (Internet of Things) by Bharani
• 4,550 points
242 views

2 answers to this question.

0 votes

Well, this is a code I had running for my connection to the AWS IoT Platform. I think it might be what you're looking for. Should solve your problem, try it:  

credentialsProvider = new CognitoCachingCredentialsProvider(
            getApplicationContext(), // context
            COGNITO_POOL_ID, // Identity Pool ID
            MY_REGION // Region);

    Region region = Region.getRegion(MY_REGION);

    // MQTT Client
    mqttManager = new AWSIotMqttManager(clientId, CUSTOMER_SPECIFIC_ENDPOINT);

    // Set keepalive to 10 seconds.  Will recognize disconnects more quickly but will also send
    // MQTT pings every 10 seconds.
    mqttManager.setKeepAlive(10);
    mIotAndroidClient = new AWSIotClient(credentialsProvider);
    mIotAndroidClient.setRegion(region);
    try {
            mqttManager.connect(clientKeyStore, new AWSIotMqttClientStatusCallback() {
                @Override
                public void onStatusChanged(final AWSIotMqttClientStatus status,
                        final Throwable throwable) {
                    Log.d(LOG_TAG, "Status = " + String.valueOf(status));

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (status == AWSIotMqttClientStatus.Connecting) {
                                                               } else if (status == AWSIotMqttClientStatus.Connected) {
                                tvStatus.setText("Connected");

                            } else if (status == AWSIotMqttClientStatus.Reconnecting) {
                                if (throwable != null) {
                                    Log.e(LOG_TAG, "Connection error.", throwable);
                                }
                                tvStatus.setText("Reconnecting");
                            } else if (status == AWSIotMqttClientStatus.ConnectionLost) {
                                if (throwable != null) {
                                    Log.e(LOG_TAG, "Connection error.", throwable);
                                }
                                                                                    }
                        }
                    });
                }
            });
        } catch (final Exception e) {
                }
answered Aug 24, 2018 by DataKing99
• 8,130 points
0 votes

Link --> https://docs.aws.amazon.com/greengrass/latest/developerguide/module3-I.html

This is Very Helpful to you.If Your Coding is in Python.Its too much easy to You.

answered Apr 3 by KanaguRaj
• 160 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer
0 votes
1 answer

MQTT protocol connection error

Ok so you need two libraries to ...READ MORE

answered Jul 6, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points

reshown Jul 6, 2018 by Vardhan 540 views
0 votes
0 answers

MQTT-Google Cloud pub/sub connection status!

Please help! So, I have a couple of ...READ MORE

Jul 19, 2018 in IoT (Internet of Things) by Bharani
• 4,550 points
171 views
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,900 points
217 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
206 views
0 votes
1 answer

Changing message format in KURA MQTT cloud client

The Eclipse Kura communicates with a MQTT ...READ MORE

answered Jul 29, 2018 in IoT (Internet of Things) by DataKing99
• 8,130 points
176 views