In today’s world, IT and electronics are transforming the way we live our lives. By profession, I’m a programmer, but first and foremost, I’m a new dad—and like all new dads, I want to give my daughter what she needs. I want to know when she needs me, especially at night, if she wakes up or she’s crying. That naturally led me to think about creating an electronic tool that could help me fulfill my new responsibilities.
I had an idea that involved exploring the possibilities of Azure Notification Hubs. This is a feature of Azure that’s used for sending and receiving notifications. My idea was to replace a baby monitor (or “baby phone”) with a mechanism that would send notifications whenever it detected a sound, then send another notification to the receiver via a compatible electronic device (e.g., a Windows phone). The recipient would get a message like “wake up, daddy,” encouraging him to get up and see what his child needs.
The first stage is to send notifications to Azure Notification Hubs from a console application or mobile application (the message sender). The second stage is to send a second notification from Azure Notification Hubs to the Windows phone (the message receiver).
In this post, I will show you how I was able to send notifications to Azure Notification Hubs.
The image below explains how notifications are sent via various IT components.
To use Azure Notification Hubs, you will need to:
- have a Microsoft Account, so that you can register the app in the Windows Store
- be able to access the Azure portal https://portal.azure.com
- have Visual Studio 2015 or later
- have Windows 10
- install “https://go.microsoft.com/fwlink/p/?LinkID=534189” Windows 10 developer tools from VS 2015
Stage 1: CREATING A NOTIFICATION HUB IN THE AZURE PORTAL
- Connect to https://portal.azure.com
- Create a Notification Hub by clicking on New, then clicking on Notification Hub
- Fill out the details in the fields that appear on the screen, then click the Create button
- Once the notification has been created, you should find the new addition in your account’s dashboard. Here’s an image showing the result in the present case, for a notification called APNotificationHub1.
- Click on “APNotificationHub1” and you will see the following appear on your screen:
- Click on Quick Start and select “Send pushes in Windows 8 applications”
- You will be directed to a website that explains step by step how to start Notifications for Windows applications—see “(Optional) Send notifications from a console app.”
- Here is the link: https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs- windows-store-dotnet-get-started-wns-push-notification. Follow the steps outlined in the link and you will be able to send notifications from a console application.
Stage 2: CREATING THE CONSOLE APPLICATION
- Follow the steps found in the link included in step 7 above.
- Once you have created the console application, you should add the “connection string” information and Azure Notification Hubs name in the application. See the SendNotificationAsync() method for more information. See the images below and consult the link if needed.
- Launch the application by pressing F5 to send a notification. The result is shown in the second image. See the message to the right of the second PhoneApp16 image and the “Hello from a.NET App” message.
PhoneApp16 is the application registered in Windows Dev Center (see the first image below) to associate the console application with the help of Visual Studio. See “Register your app for the Windows Store” in the following link for more details: https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-windows-store-dotnet-get-started-wns-push-notification.
- You should finally see the notification appear in the Azure portal in Metric (incoming messages)—see the image.
I have now successfully completed the first part of my project, which was to duplicate the function of a baby monitor by sending notifications from a console application to Azure Notification Hubs—the Azure component used for sending and receiving notifications.
From a technological standpoint, I found it rewarding to explore the use of Azure Notification Hubs in this way, since implementing the first part of my project allowed me to understand how this feature works.
In closing, I would say that Azure Notification Hubs has multiple benefits. For example, it’s easy to send notifications from any back-end to any mobile platform. It also offers the possibility of telemetry monitoring and sending scheduled notifications, which is very attractive.
The second part of my project—sending notifications (from Azure Notification Hubs) to a Windows phone receiver—will be covered in a future post.
In the meantime, I hope you enjoy discovering the many advantages of Azure Notification Hubs as much as I have.