5 Replies Latest reply on Jan 8, 2018 9:38 AM by Digital One RSS
    Digital One Explorer

    How to enable push notifications for Alert/Exception to a mobile device ?

    Hi All,


    How to send push notification to a mobile device when their is change in an threshold limit ?

      • Re: How to enable push notifications for Alert/Exception to a mobile device ?
        Ankit Gupta Ninja

        I agree with Sushant; you just need to add an alert for that threshold limit event; then subscribe to that event and in the subscription code write the custom code to send push notification.

        • Re: How to enable push notifications for Alert/Exception to a mobile device ?
          sharmon Creator

          Here's a cool way we did this in one of our demos. Sushant and Ankit are correct on how to capture the condition - create an alert, capture the event with a subscription, and use some code to send a push your notification. I'm going to elaborate on the, "use some code to send a push alert," part.


          First, you'll need to create a developer account over at Twilio. Twilio is a service that will send voice and SMS messages for you, using simple REST calls. Then, you'll need to go to the ThingWorx Marketplace and get the Twilio extension.


          Once you've imported the Twilio extension, you'll need to create a Thing based on the Twilio ThingTemplate, and configure it with your Twilio account details. The extension comes with instructions. Here's a screen shot of my configuration:



          In our scenario, we're going to monitor a coffee roaster for a high humidity condition. Our Thing Model has coffee roasters with ChamberHumidity and ChamberHumidityThreshold properties. We want to send a voice message to the human running the roaster when ChamberHumidity is greater than ChamberHumidityThreshold. In the ThingShape that defines all my roaster properties, I subscribe to the DataChange event for the ChamberHumidity property:



          Note - I'm subscribing to the DataChange event of the ChamberHumidity property, and then letting my service check the condition, instead of subscribing to an alert on a property, subscribing to that alert, and then running custom code. As with most things, there's more than one way to do it (TMTOWTDI).


          The subscription does one thing; it runs a service called TwilioService. TwilioService checks to see if ChamberHumidity is greater than ChamberHumidityThreshold. If it is, I use my Twilio Thing's SendVoiceMessage service to send a push voice message. If it's not, I just make sure my ChamberHumidtyAlarm property is set to false:


          /* Looks to see if chamber humidity exceeds the chamber humidity threshold. If so,
          *  sends a Twilio notification to the AlarmCellPhoneNumber associated with the current
          *  Thing.
          if(me.ChamberHumidity >= me.ChamberHumidityThreshhold){
                var message = "Important Alert! Coffee Roaster at (" + me.description + ")Chamber Humidity (" + formatNumber(me.ChamberHumidity,'0.0') + ") Over Limit (" + formatNumber(me.ChamberHumidityThreshhold,'0.0') + ") : Product Is At Risk.";
                //Parameters for Twilio service  
                var params = {
               voice: 'male',
               loop: true,
               language: 'en',
               to: me.AlarmCellPhoneNumber,
               text: message
                //Send voice message via Twilio
              me.ChamberHumidityAlarm = true;
          } else {
            me.ChamberHumidityAlarm = false;        


          Because I used a ThingShape to contain all my coffee roaster properties and services, every coffee roaster Thing I create gets its own copy of all of them. This means I can send alerts for individual roasters.


          Twilio can send SMS messages for you, too.


          Once we built all the infrastructure described above, we built a mashup so we could set the properties and send push notifications in real time:



          I hope this helps.

          • Re: How to enable push notifications for Alert/Exception to a mobile device ?
            qngo Creator

            There's also the Pushover extension to push notifications to a mobile device through its client app