Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of clients connected to AWS IoT MQTT topic

We developed an iOS application and configured the app to listen to all the messages published on a particular MQTT topic on AWS IoT.

All I want to know is, is there a way where I can pull a list of connected devices who are listening on that topic ? (I checked the cloudWatch logs and I couldn't find the detailed info like the MAC address of the device connected etc).

Also, I want to know if there is limit on the no. of devices that can be subscribed to a topic.

like image 790
kskiran Avatar asked Oct 19 '22 03:10

kskiran


1 Answers

There is no limit to the number of devices on a single topic. One of the major pros for the service - it scales virtually infinitely. Here's a full list of all the AWS IoT Limits.

There's no easy way to query the number of devices connected directly from AWS IoT. But there is a way to detect when any device subscribes and unsubscribes from a topic using the message data from AWS Reserved Topics - specifically these topics below:

$aws/events/subscriptions/subscribed/{clientId}
$aws/events/subscriptions/unsubscribed/{clientId}

You could create an IoT rule to forward all subscribed and unsubscribed events from those reserved topics to S3, DynamoDB or RDS to be queryable. A simple Lambda function to increment on subscribes and decrement on unsubscribes within DynamoDB would work really well too. (DynamoDB Atomic Counter)

Also here's what the message body looks like - from Subscribe/Unsubscribe Events:

{
    "clientId": "186b5",
    "timestamp": 1460065214626,
    "eventType": "subscribed" | "unsubscribed",
    "sessionIdentifier": "00000000-0000-0000-0000-000000000000",
    "principalIdentifier": "000000000000/ABCDEFGHIJKLMNOPQRSTU:some-user/ABCDEFGHIJKLMNOPQRSTU:some-user"
    "topics" : \["foo/bar","device/data","dog/cat"\]
}
like image 51
John Veldboom Avatar answered Nov 03 '22 00:11

John Veldboom