Count the number of active device sessions, unique serial numbers

Our application needs to keep track of the currently active sessions from devices, and the number
of unique serial numbers reported by the devices. The number will be in the hundreds to start with,
thousands and more is our normal case.
This is useful for fault detection (what percentage of the total number of devices is down) and/or
intrusion detection (illegal serial numbers, duplicate serial numbers, etc).
If we combine this with timestamps then we can count the active devices during the last period
of interest (minute, hour, day, week, etc).
How do we get the number of currently active MQTT sessions from the platform?
For keeping track of serial numbers, the “data table” https://docs.losant.com/data-tables/overview/
seems to be relevant. Can this be made into an associative array where the serial number is the key?
Any references to documentation / tutorial would be very helpful. There does not seem to be a search
facility on your documentation that I could find.

Hi @Gambit_Support,

I would recommend a creating a workflow beginning with a Timer Node for your period of interest (minute, hour, day). Then you could use a Device: Get Node to query your devices by tag (or the Losant API Node if tags are unavailable), and the connection information will be available for each device:
10%20AM

This way you would be able to count the number of connected devices with the connected boolean, as well as see the last connected time.

For your serial numbers, we recommend using the Data Table for non-state data, and reporting device data as state. Could you explain your use case on the serial numbers a bit further? I want to ensure I recommend the correct solutions to fit your goal.

Thanks! :smile:
Julia