Leveraging Azure Mobile Services and Twilio for NightScout real time push notification and SMS messages


 

In this blog post I am going through steps to configure and enable real time push notification for NightScout Windows Phone 10 app and also sending SMS messages to other subscribers on other smartphone platforms like iOS.

First, I created an Azure Mobile Services project in Visual Studio 2015 preview and added required packages including MongoDB (v2.0.50727) and Twilio (v4.0.30319) using Nuget.

Second, I added a custom Mobile Services ScheduledJob class called “NightScoutJob” and added the required references as following:

clip_image002

Next, Under ExecuteAsync method, by leveraging MongoDB’s MongoClient we now have direct access to MongoDB’s database/collection and using Linq queries we can get the last reading from Dexcom. With a simple check if glucose reading is below or above a limit (Configurable using App Settings) the custom job sends a notification push and a SMS message to verified numbers.

Snippet for Push Notification:

clip_image004

As a prerequisite I also configured Push setting for the Notification Hub on Azure portal and modified the code for the Windows Phone app to subscribe to this channel using Windows.Networking.PushNotifications class library, more info here.

clip_image006

Snippet for SMS messages using Twilio:

clip_image008

Note:
Twilio SID, Token and phone number was provided by Twilio after creating a trial account, also note that you need to verify recipient numbers to be able to send SMS messages via service, more info here.

clip_image010

After adding the App Settings and Connection strings to my custom mobile service I published the code via Visual Studio, added a custom job through Azure Portal and set it to run every five minutes:

clip_image012

As a result now I am able to receive notifications through Azure notification hub or an SMS message via Twilio when glucose numbers are low or high and be able to avoid Hyperglycemia and Hypoglycemia with the power of Azure and the cloud.

Update:

Recently I also got a chance to try the Band SDK and although background task is still not supported (Coming for Beta) now by using Mobile Services Push Notification Channel Message Received event handlers I should be able to send notification to Microsoft Band as well. More to come …

louderthanwords

Comments (2)

  1. Indul Hassan says:

    Great ways to explain. Thanks

  2. Indul Hassan says:

    Well are we really suppose to mention all of the using methods.

    Is there any global method available for some while using using statement.

Skip to main content