Let’s assume you manage a building with a temperature sensor per room. You want to find out in which of the rooms the temperature is above 20° because that might be an indicator that the air condition is not working properly.
We will simulate temperature sensors by adding reported temperatures to the device shadows and adding also a room number attribute to devices. We will use the devices that you have created in the bulk provisioning exercise.
You have enabled registry indexing already earlier in this workshop.
To write the temperature of your sensors to the shadow you will use a script that modifies all things matching the thing name
name. Use the devices that you have created in the bulk provisioning exercise. We assume that you have used the thing basename
bulky like described in the exercise. In case you used another namechange the name in the following instructions accordingly.
In a Cloud9 terminal:
# add temperature and room number # to all devices matching the name "bulky*" # if you have named the devices in the bulk provisioning section # differently, choose the appropriate basename fleet-indexing.py -b bulky
Verify that the modification was successful. Every device from the bulk provisioning exercise should have an attribute room_number and a reported temperature in the shadow
aws iot search-index --query-string "thingName:bulky*"
Find all device in the registry which have a room number and where the temperature is greater than 20°
aws iot search-index \ --query-string "shadow.reported.temperature>20 AND attributes.room_number:*"
You can find the shadow document for a device also in the AWS IoT Core console