Managing devices using AWS IoT
We have already seen what is IoT and how they help our everyday devices, so in order to make use of these devices efficiently, we need to manage them efficiently. For this, AWS IoT will help. AWS IoT provides a registry kind of stuff that helps to manage things. Here the devices are called "things" in AWS IoT. It is actually a representation of a particular device or logical entity, including both physical like sensor, etc., and logical entities like an instance in an AWS application.
The registry is basically a JSON collection of meta-information about your device. For example, for a LightBulb type thing, the thing has properties like its version, name, Id, model, wattage, etc. This particular meta information is stored in JSON format as shown below:
{
"version": 3,
"thingName": "MyLightBulb",
"defaultClientId": "MyLightBulb",
"thingTypeName": "LightBulb",
"attributes": {
"model": "123",
"wattage": "75"
}
}
Any type of "thing" in AWS will be identified by its name. They can have their own attributes (defined in key-value pairs).
You don't actually need to create a thing in the registry to connect a device to AWS IoT; adding things to the registry just enables you to manage and search for devices more easily.
Managing things with the registry
Naming the things is the first important step in creating a registry. You should not use personally identifiable information in your device name, and we should not use a (:) colon in device names. It has a specific purpose in AWS.
Creating a thing
- >CreateThing: this Command to create a thing:
$ aws iot create-thing --thing-name "MyLightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"
The output of this command will contain the name and the ARN (Amazon Resource Name of your newly created thing.
Output:
{
"thingArn": "arn:aws:iot:us-east-1:123456789012:thing/MyLightBulb",
"thingName": "MyLightBulb",
"thingId": "12345678abcdefgh12345678ijklmnop12345678"
}
Listing your created things
- >ListThings: Command for listing all the things:
$ aws iot list-things
- >ListThings: Command for listing to search for all things of a specific thing type:
$ aws iot list-things --thing-type-name "LightBulb"
- >ListThings: Command for searching for all things that have an attribute with a specific value:
$ aws iot list-things --attribute-name "wattage" --attribute-value "75"
Note: This command will only search for only searchable attributes, this can be known by using fleet indexing.
For Describing the things
- >DescibeThing: Command to display all the detailed information about the thing you wanted:
$ aws iot describe-thing --thing-name "MyLightBulb"
Updating a thing
- > UpdateThing: Command to update a thing, especially this will only the thing’s attributes, not other thing information. This command won’t return anything as an output, and you need to use the DescribeThing command to see the changed result.
$ aws iot update-thing --thing-name "MyLightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"150\", \"model\":\"456\"}}"
Deleting a thing
- >DeleteThing: Command to delete a thing.
$ aws iot delete-thing --thing-name "MyThing"
Attaching and Detaching the principal to a thing in AWS IoT
Principal: Every physical device that is communicating with AWS IoT must have an X.509 certificate. This can be considered a principal.
- > AttachThingPrincipal: Command to attach a certificate/principal.
$ aws iot attach-thing-principal --thing-name "MyLightBulb" --principal "arn:aws:iot:us-east-1:123456789012:cert/a0c01f5835079de0a7514643d68ef8414ab739a1e94ee4162977b02b12842847"
- > DetachThingPrincipal: Command to detach a certificate from a thing.
$ aws iot detach-thing-principal --thing-name "MyLightBulb" --principal "arn:aws:iot:us-east-1:123456789012:cert/a0c01f5835079de0a7514643d68ef8414ab739a1e94ee4162977b02b12842847"
Note: These two commands won’t return any output.
Click here to read more : What is arduino uno
Thing Types
To create a group-like thing that contains all the things that share all common descriptions and configurations. This can be done using Thing Types. These types can help to manage things in a simple way. But this type of creation is obviously an optional thing in AWS IoT.
Benefits of Thing Types:
- Things with a thing type can have about 50 attributes, whereas the things without a thing type can only have up to 3 attributes.
- You can create any number of thing types in your account, and a thing can only be associated with a thing type. These thing types are immutable.
Similar to creating, listing, and deleting a thing, we can also do these functions on Thing Types.
Creating Thing type
- > CreateThingType: Command to create a thing type.
$ aws iot create-thing-type
--thing-type-name "LightBulb" --thing-type-properties "thingTypeDescription=light bulb type, searchableAttributes=wattage,model"
We will get thing type and its ARN similar to thing output as an output.
Listing all things types
- > ListThingTypes: Command to list all the thing types.
$ aws iot list-thing-types
The output comprises all the thing types created.
Describing the thing type
DescribeThingType: Command to describe all the thing types.
$ aws iot describe-thing-type --thing-type-name "LightBulb"
The output for this will contain all the detailed information of the thing type mentioned in the command.
Associate a thing type with a thing
After creating a thing, we need to add it to a thing type. For that, we have the following commands.
- > CreateThing: Command to add a thing to a particular thing type.
$ aws iot create-thing --thing-name "MyLightBulb" --thing-type-name "LightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"
- > UpdateThing: For deleting a thing’s association with a thing type, we need to use the UpdateThing command.
$ aws iot update-thing --thing-name "MyLightBulb"
--thing-type-name "LightBulb" --attribute-payload "{\"attributes\": {\"wattage\":\"75\", \"model\":\"123\"}}"
And Finally, we need to deprecate the thing if we don’t need that thing type anymore.
To do that, we have DeprecateThingType Command.
- > DeprecateThingType: Command to deprecate a thing.
$ aws iot deprecate-thing-type --thing-type-name "myThingType"
To see the results, we can use DescribeThingType.
To Undo the Deprecated thing, we can make use of the –undo-deprecate flag.
$ aws iot deprecate-thing-type --thing-type-name "myThingType" --undo-deprecate
There is another major benefit that the AWS IoT provides us to create a group of things so that we can easily apply changes to all things at once.
There are majorly two types of groups that are allowed in AWS IoT.
- Static Thing Groups
- Dynamic Thing Groups.
We will learn all the important stuff relating to these groups in the upcoming articles.
Check out this article - Components Of IOT
Frequently Asked Questions
What is AWS IoT?
AWS IoT is an AWS cloud platform that provides facilities for managing both either physical and also logical entities. It provides bidirectional and secure communication between connected devices and between connected devices and the cloud.
What is a thing in AWS IoT?
A “thing” in IoT is a representation of a particular physical device or a logical entity. A thing in AWS IoT comprises of a name, id, ARN, and some attributes belonging to that thing. We will identify things in AWS IoT using their names.
How to manage things in AWS IoT?
AWS IoT provides or creates a registry to save all the things or devices’ meta information. It contains all the details regarding the thing that is connected to the AWS IoT Platform. It supports so many commands to manage the devices using the registry.
What is meant by thing type in AWS IoT?
A thing type is a collective representation of all things that have the same description and configurations. A thing associated/added with a thing type can have so many advantages over things that are not associated. We can manage thing types similar to that of things.
Can we undo our deprecated thing type in AWS IoT?
Yes, we can undo our deprecated thing type in AWS IoT, we can use --undo flag to undo our deprecated thing type, we just need to add this --undo flag to our deprecated command.
Conclusion
This article extensively discussed the concept of Device Management Using AWS IoT. We start with a brief introduction, then discuss how it can be used in our applications.
After reading this article, are you not feeling excited to read/explore more articles on similar discussions? Don't worry; Coding Ninjas has you covered. Refer to our Guided Path on Coding Ninjas Studio to improve yourself in Competitive Programming, Data Structures and Algorithms, JavaScript, System Design, and many more! If you want to test your confidence in coding, you may check out the contests and participate in the mock test series hosted on Coding Ninjas Studio! But suppose you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problems, interview bundle, and interview experiences for placement preparations. Nevertheless, you can consider our paid courses to give your career improvement an edge over others! Do upvote our blogs and articles if you find them helpful and engaging!
Happy Learning!