cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

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

done11
1-Visitor

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 ?

5 REPLIES 5
supandey
19-Tanzanite
(To:done11)

Hi, have you considered creating Thing Subscriptions on an Thing Events?

ankigupta
12-Amethyst
(To:done11)

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.

sharmon
13-Aquamarine
(To:done11)

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:

Twilio-Config.png

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:

ChamberHumiditySub.png

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){

    if(!me.ChamberHumidityAlarm){

      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

      Things["TPG.CoffeeRoasterTwilioThing"].SendVoiceMessage(params);

    }

    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:

Twilio-Thing.png

I hope this helps.

supandey
19-Tanzanite
(To:sharmon)

Stephen, that's neat! Could be a good idea for a blog

qngo
12-Amethyst
(To:done11)

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

https://marketplace.thingworx.com/Items/Pushover%20Notification%20Platform%20Extension

Announcements


Top Tags