0 Replies Latest reply on May 23, 2017 9:13 AM by khayes RSS
    khayes Apprentice

    Logging isConnected


    hoping someone can help me overcome an issue I have. Bear with me, it's a little long winded & complicated. The remote device I am working with has a STRING property called SystemState.  The property is remotely bound to a thing property of the same name, on the server. There are a number of states (idle/Running/Fault etc) which the device can have. These all record fine, and are logged in a value stream. My problem arises because when trying to display the device states in a grid with their time stamp, I also want to show when the device was switched off (this can happen numerous times in the day). Effectively I wish to add a new state ('Offline') which the device has no knowledge of.


    The way I have tried to do this is by subscribing to the data change event for the isConnected property, which I can see is being triggered. It is here where my problems begin.

    At first I tried to set the set the SystemState property to 'Offline' directly from within the subscription. I am unable to do this because (I think) the property is remotely bound to the edge.

    Next I created a new local BOOLEAN property called 'isOffline' and set this accordingly within the isConnected subscription. This new property is also logged to the value stream. Next I wrote a service for my mashup which uses the QueryNamedPropertyHistory() service. It takes a start and end date and uses 'SystemState' & 'isOffline' as the named properties. Unfortunately the returned info table is not what I was expecting. Because the start time can (and usually is) be between logged entries I try to get the entry prior to the start time so I can tell what the state was as we enter the start time. To do this I use the code below

    var prevParams = {

           maxItems: 1 /* NUMBER */, 

           oldestFirst: true , /* BOOLEAN */

           endDate: StartTime /* DATETIME */, 

           propertyNames: paramTable  /* INFOTABLE  contains 'SystemState' & 'isOffline'*/


    var previous = me.QueryNamedPropertyHistory(prevParams);

    I was expecting to get a single row in my results infotable, but what I actually get is 2 rows


    I can't prove it, but apart from the fact that there are 2 rows, I'm pretty sure that there should have been more entries between the 2 time stamps above. As an aside I also have another property which I set in the isConnected subscription called 'lastSeenAlive' which is a DATETIME property and only records the time now when the isConnected new value is false. This bit of code does get called, however if I inspect this property in the composer for a remote device I know has been switched off for days I will see that it is set to a time within the last few hours, as if something else has set it.


    So, apologies for the long question, but I guess my question is... am I doing something wrong... or... is there a better way to do this. Ideally I would just be able to set 'SystemState' to "Offline" in the subscription.

    Thanks in advance