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:
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:
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.
Snippet for SMS messages using Twilio:
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.
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:
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.
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 …