4 Replies Latest reply on Mar 29, 2017 9:47 PM by zyuan RSS
    pjoly Apprentice

    Simply way to create an alert (notification) when no data received from a device ?

    Hello

     

    I would like to create an alert (email or other) when a device is not refreshed for more than N minutes ?

    I had a look in alert but it is only "equal" or "not equal" tests for properties (and when it is updated)

     

    I probably need to create a timer and a service but I guess there is something already "packaged" for that as it is an usual need ?

    (I did not find easy answers in forum and documentation)

     

    Thanks

      • Re: Simply way to create an alert (notification) when no data received from a device ?
        zyuan Apprentice

        Hello, from what I can see from your question, I assume that you are requiring a regular update to the device (a Thing entity)

         

        My question is, how is the Thing updated? Some random properties get a new value in a random time or all the properties get changed?

         

        BTW, the String property only have "equal" "not equal" in its alert type, Numeric and time properties has extra type as "above" "below" "out of range"

         

        I'm not sure if there's a build-in service for that, here is my solution:

         

        Create a service or subscription or in Expression widget, when CurrentTime - LastUpdateTime > TimeToWait, it will send out alerts and emails


        The CurrentTime value is easy to get, and here is 3 possible ways to get LastUpdateTime value:

        • Create a TimeStamp property, and each time any property is updated, reset the Time property to current time, the update can be written in other update services
        • Use the GetPropertyTime service in Generic Thing Template, and bind it to the name of the property you are concerning about (or the property that's most often be changed), and it will return a time result. This service did not work for Remote Bounded properties, but you could create a new property that get updates from them.

        • If the Thing is remote bounded, there would be a isConnected Boolean property, create a Subscription on DataChange event for it

            It returns the time when the connection is turned off.

          • Re: Simply way to create an alert (notification) when no data received from a device ?
            pjoly Apprentice

            Thanks a lot for detailed explanation.

             

            In my case all data are refreshed by 2 messages but if the connection is deffective I receive nothing associated to the thing (So I acnnot check when I receive a message).

             

            I'll create a generic service to monitor all my things  (they are on the same template) based on your guide and with a timer to awake it regularly to check the last updates.

             

            But perhaps it could be a good built-in service to monitor things to be implemented in the future

             

            regards

              • Re: Simply way to create an alert (notification) when no data received from a device ?
                pjoly Apprentice

                So I  have created a timer thing and I created a subscription to it  in the device template in which I'm testing the last update of the device

                (I'm storing this in the device thing property)

                 

                It works very fine and very easy with simple code.

                var today = new Date();
                me.DeviceUpdateStatus =  "OK";
                if ( (today -  me.DeviceLastUpdate) /1000  > 36000 )  // 10  heures
                {
                logger.error ( me.name + " pas de mise à jours depuis " +  (today -  me.DeviceLastUpdate) /1000  + "secondes")
                me.DeviceUpdateStatus = "ERROR"
                }
                else if ( (today -  me.DeviceLastUpdate) /1000  > 3600 )  // une heure
                {
                logger.warn ( me.name + " pas de mise à jours depuis " +  (today -  me.DeviceLastUpdate) /1000  + "secondes")
                me.DeviceUpdateStatus =  "WARNING";
                }
                

                 

                 

                and the mashup

                 

                 

                following the recommendation, I could optimze the performances in the future with one thing to parse all device (using etImplentingThingsWithdata) when I'll have thousand of devices to manage

                Timers and Schedulers - Best Practice

                 

                Thanks for help !