If you want to get the connectivity status of your device you can use connectivity indexing.
You have enabled connectivity indexing already earlier in this workshop.
Use one of the things that you have created in the bulk provisioning exercise and publish some messages. mosquitto_pub
which is used for publishing messages connects to AWS IoT, publishes a message and disconnects.
Lookup the device in the registry
# XX represents the number for the device that you used, e.g. 11
aws iot search-index --index-name "AWS_Things" --query-string "thingName:bulkyXX"
The key connected
in the connectivity
section should be set to false
Now let’s connect a device to AWS IoT that stays connected by using a subscriber. Certificates and keys from the bulk provisioning exercise are stored in the directory ~/provisioning/$THING_NAME-YYYY-mm-dd_H-M-S
. Change into that directory before using the following commands.
THING_NAME=bulky11
mosquitto_sub --cafile ~/root.ca.bundle.pem \
--cert $THING_NAME.crt --key $THING_NAME.key \
-h $IOT_ENDPOINT -p 8883 -q 0 -t iot/ws \
-i $THING_NAME --tls-version tlsv1.2 -d
Lookup the device (in another terminal) that you just used as subscriber and the value for connected
should be set to true
. It could take some moments until the connectivity index has been updated.
The connectivity entry also contains a timestamp
that let’s you determine when the value for the connected
key has been set.
To convert the timestamp to a date the following command could be used:
date -d @$(([YOUR_TIMESTAMP] / 1000))
If the timestamp has a value of 1596720368135
you would get the following result:
date -d @$((1596720368135 / 1000))
Thu Aug 6 13:26:08 UTC 2020
Some more queries to try:
Find all connected devices:
aws iot search-index --index-name "AWS_Things" --query-string "connectivity.connected:true"
Find all disconnected devices:
aws iot search-index --index-name "AWS_Things" --query-string "connectivity.connected:false"