pozzugno
pozzugno

Reputation: 826

How to check AWS IoT Device connection status on the web console?

I just started playing with AWS IoT. I created a thing and use mqtt-spy to connect to AWS server. All is ok.

Now I'd like to check the status of each thing in the web console, however I couldn't find such useful info near the device.

Upvotes: 1

Views: 9415

Answers (2)

mvltshn
mvltshn

Reputation: 255

By enabling AWS IoT Fleet Indexing Service, you can get the connectivity status of a thing. Also, you can query for currently connected/disconnected devices.

First, you have to enable indexing (thingConnectivityIndexingMode) by aws-cli or through the console.

aws iot update-indexing-configuration --thing-indexing-configuration thingIndexingMode=REGISTRY_AND_SHADOW,thingConnectivityIndexingMode=STATUS

Then you can query a thing's connectivity status like the following

aws iot search-index --index-name "AWS_Things" --query-string "thingName:mything1"
{  
    "things":[{  
         "thingName":"mything1",
         "thingGroupNames":[  
            "mygroup1"
         ],
         "thingId":"a4b9f759-b0f2-4857-8a4b-967745ed9f4e",
         "attributes":{  
            "attribute1":"abc"
         },
         "connectivity": { 
            "connected":false,
            "timestamp":1641508937
         }         
    }
}

Note: Fleet Indexing Service index connectivity data with device lifecycle events ($aws/events/presence/connected/). In some cases it may take a minute or so for the service to update indexing after a connect or disconnect event occurs.

EDIT: The javascript version of this:

var iot = new AWS.Iot({
    apiVersion: "2015-05-28"
});
...
var params = {
    queryString: "thingName:" + data.Item.thingName, // using result from DynamoDB
    indexName: 'AWS_Things'
    //   maxResults: 'NUMBER_VALUE',
    //   nextToken: 'STRING_VALUE',
    //   queryVersion: 'STRING_VALUE'
};

iot.searchIndex(params, function(err, data) {
    if (err) {
        console.log("error from iot.searchIndex");
        console.log(err, err.stack); // an error occurred
    } else {
        console.log("success from iot.searchIndex");
        console.log(data.things[0].connectivity.connected); // t/f
    }
});

Upvotes: 11

Narendra Chouhan
Narendra Chouhan

Reputation: 2319

You need to subscribe to the topic on the aws iot console , test section on the right corner of AWS IoT-core. for example you to subscribe to this topic replace your client with the . $aws/events/presence/connected/<Your_clientId> if you have more than one thing then you have to subscribe using your ClientID for reference check this link https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html

Upvotes: 2

Related Questions