HOW TO: Query the Connection History of a Connected device from Digi Device Cloud

Introduction:

One very useful aspect of Device Management on the Digi Device Cloud is the ability to view the Connection History of a device.  This of course refers to the connection history of that device as viewed from Device Cloud, and is a record of a device's connections and disconnections with the server, for whatever reason.

Device Cloud Connection History (from the device UI):


 

Getting the Connection History from the Data Streams API:

As seen above, the Connection History of a device is something which Device Cloud keeps track of.  A screen like the one above may be useful when wanting to know the current state of a device or what's been going on with it, but short of taking a screenshot or copying/pasting that information into a text file, the information isn't very portable.  The good news is, the Connection History is something which is also tracked as a Data Stream, and each of the Connect/Disconnect events is a separate Data Point within that Stream.

To query the Data Stream Connection History if the same device, we must query for the Data Points which make up that Stream as follows:

/ws/DataPoint/{deviceId}/management/connections/

Example Request:  /ws/DataPoint/00000000-00000000-00409DFF-FF5DF1CB/management/connections/

Response (for a single Data Point of the Stream):

<?xml version="1.0" encoding="ISO-8859-1"?>
<result>
   <resultSize>206</resultSize>
   <requestedSize>1000</requestedSize>
   <pageCursor>27f2d9aa-beab-11e5-92dc-fa163ea15feb</pageCursor>
   <requestedStartTime>-1</requestedStartTime>
   <requestedEndTime>-1</requestedEndTime>
   <DataPoint>
      <id>f5e6756c-75c8-11e5-8dc1-fa163ee3abab</id>
      <cstId>70</cstId>
      <streamId>00000000-00000000-00409DFF-FF5DF1CB/management/connections</streamId>
      <timestamp>1445194168409</timestamp>
      <timestampISO>2015-10-18T18:49:28.409Z</timestampISO>
      <serverTimestamp>1445194168412</serverTimestamp>
      <serverTimestampISO>2015-10-18T18:49:28.412Z</serverTimestampISO>
      <data>{"connectTime":"2015-10-18T03:14:07.442Z","disconnectTime":"2015-10-18T18:49:28.409Z","type":"Wi-Fi","remoteIp":"213.35.189.122","localIp":"192.168.82.204","bytesSent":70412,"bytesReceived":69588,"session":"6b861b2f-bd52-4455-b9fc-dc92693460db"}</data>
      <description/>
      <quality>0</quality>
   </DataPoint>...
</result>

As can be seen in the <resultSize> field, there were 206 Data Points in the response to the query, so I've only listed one Data Point as an example of the type of data retrieved from the Connection History Data Stream.
 

Further Reading:

Device Cloud Programming Guide

Last updated: Mar 22, 2019

Recently Viewed

No recently viewed articles

Did you find this article helpful?