Counting devices online in different groups and geofences. How?

GeorgS6 years ago

Please tell me how I can calculate at any time the number of devices in groups that are online/offline. You also need the number of devices online in a specific geofence.
Thank you in advance for your help.

Mayank6 years ago

I am not sure about if this can be done using portal GUI, but You can write a simple python script and using that You can check as per your needs.

 headers = {
                'Content-Type': 'application/json',
        }
        groupId = 2
        onlineDevices = []
        unknownDevices = []
        offlineDevicesPortal = []
        response = requests.get('http://<server_url>/api/devices', headers=headers,
                                     auth=('admin', 'admin'))
        response = response.json()
        onlineCount = 0
        offlineCount = 0
        unknownCount = 0

        for r in response:
            if r["status"] == "online" and r["groupId"] == groupId:
                onlineCount += 1
                onlineDevices.append(r["uniqueId"])
            elif r["status"] == "unknown" and r["groupId"] == groupId:
                unknownCount += 1
                unknownDevices.append(r["uniqueId"])
            elif r["status"] == "offline" and r["groupId"] == groupId:
                offlineCount +=1
                offlineDevicesPortal.append(r["uniqueId"])

        print("Total Online Devices are: {}".format(onlineCount))
        print("Total Unknown Devices are: {}".format(unknownCount))
        print("Total Offline Devices are: {}".format(offlineCount))
        print("Total Devices are: {}".format(onlineCount + unknownCount + offlineCount))
GeorgS6 years ago

Thank you!! I'll try