How to fetch the device connected and disconnected status from AWS IoT Core?

0

Hi there!

We have built an Internet of Things web application using AWS IoT Core APIs and libraries. This application can control our connected lights and also update them using OTA updates or jobs. We also have many other details and features built in.

We want to have a new column in the table for our list of devices that shows the connected status of the device. We tried to fetch it from the list of things and describe things APIs but couldn't find it.

Can somebody help us with this? We tried an alternative approach by subscribing to connect or disconnect lifecycle events using the rules engine and publishing the data into a DynamoDB table. But this approach is not so clean. We require this data to show the device heartbeat status.

1 Answer
2

If you need to query on a per-thing status or are looking for aggregate numbers, Fleet Indexing Connectivity can be used to provide connectivity status (connected or disconnected) and the timestamp for the reported status. In order to use, you do need to enable fleet indexing for connectivity which will incur charges for Index Updates which is metered for every device connect and disconnect, and the for Search Queries when you query the index.

We find that some customers need more granular data or wish to query it based on ways that Fleet Indexing doesn't provide. In that case, the approach you have taken with processing lifecycle events is the recommended approach. If Fleet Indexing doesn't suit your needs, please reply and we'll find a solution!

AWS
Gavin_A
answered 3 months ago
profile pictureAWS
EXPERT
Greg_B
reviewed 3 months ago
  • Here's a sample of using the lifecycle events: https://github.com/aws-samples/connectivity-management-example-for-aws-iot-core. You might also choose to store the status in shadows rather than DynamoDB. And this previous question and answer might be of interest if you do make use of fleet indexing: https://repost.aws/questions/QUp6B-SMa4SFavCfq4nT-EcQ/how-does-one-use-the-thingconnectivity-class-in-the-sdks-there-is-no-way-to-set-the-thing-name

  • Hi Galvin, thanks a lot for the response. By reading the posts shared by Greg, I found the SearchIndex API that allows us to list the things with their connected status. Before finding this, we tried the lifecycle events approach to populate a DynamoDB table and use clientId as the partition key. But many unnecessary entries are populated with random clientId that start with the prefix "iotconsole" or "mqttjs". We are still testing our approach. How do we make sure that the database entries are clean? Concerning Fleet Indexing on the thing registry, I couldn't run a search query. I ran an example query such as connectivity.connected:false, but it returned an error "A query is required to perform a search". How do I write queries in the search box?

  • Hi Greg, could you please enlighten me on how to store the connectivity status in device shadows? Should the device be programmed to use classic shadows? What else is required besides turning on fleet indexing in the settings and enabling thing shadows? Can we fetch the status using the GetThingShadow API?

  • Hi Sandeep. The "iotconsole" clientId is from you or your team using the MQTT test client. That is the client ID it uses. "mqttjs" is from perhaps your application connecting to the broker? You could modify the rule action or the Lambda to filter out clients you're not interested in.

  • Just as that sample uses a Lambda to write into DynamoDB, you could modify it to write to different storage. Shadows is just one possibility. The Lambda could use UpdateThingShadow if you did want to write to the shadow. You would not need to modify the device.

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