Filtering telemetry from devices with multiple users in Azure IoT Central - azure-iot-central

Suppose that I have a device with multiple users. User 1 will start a session with the device, send some telemetry data over a period of time and eventually end their session. Next, User 2 will start a session and also send some telemetry data from the same device. In IoT Central, I am interested in generating telemetry analytics grouped by user, not by device. Is it possible to send a user ID string once at the start of every session to indicate to azure that the following telemetry data is for that user? What is the best way to implement this?

Are you concerned with data isolation from user to use? If so, the best way to accomplish this is to delete and re-create a device instance (i.e. reprovision) the device when it gets moved from user to user; however this won't allow you to track device telemetry trends over time for the same device (i.e. battery life).
If you're not concerned with data isolation, you can send a device property that's unique per user and then be able to slice and dice the data by the device property. This won't be supported within the built-in analytics tool in IoT Central though. You can export the data using continuous data export and do the analysis offline (i.e. in PowerBI).

Related

Run scheduler on Azure based on user specific scheduled time

We have an API to fetch the latest transaction data of the user based on the scheduled Next_Refresh_Time. Each user has different scheduled refresh time. Since we have thousands of users we have to run the scheduler to fetch the data. Please suggest me the best way to do it.
Each user has different scheduled refresh time. Since we have thousands of users we have to run the scheduler to fetch the data.
You could add a queue message and specify initialVisibilityDelay with Next_Refresh_Time value when a user login, and then you could create and run a Queue-trigger WebJob to process queue message and featch the latest data (and if current user is still online, add the message (specify same content and initialVisibilityDelay as original message) to queue).
Besides, if you’d like to real-time push the latest data to specific connected user, SignalR would help you implement real-time functionality and SignalR can be used in a variety of client platforms. You could save connection id of a login user in queue message, and then you can call hub method in WebJob function to push data to a connected user based on connection id.
The following thread and article would be helpful to know how to establish connection and call hub method.
SignalR - Broadcasting over a Hub in another Project from outside of
a
Hub
Hubs API for
SignalR

How are users tracked for location based push notifications?

I want to enable push notifications for a UWP mobile app connected to Azure app service with Azure SQL database. The notifications will alert only the users that are located within x kilometres from a certain geo coordinate.
However I'm not clear about how to track the users, My questions are as follows,
In my database should I store every user that uses the app and update their location periodically? I'm guessing I would need to do this in order to calculate which ones are in range and send notification to only those. However this leads me to my next question,
If I was going to store a record for each user in my database, what identifier is used for them? How are users identified on each device? Do they need to log in with an authorization provider like Facebook, Twitter, etc. in order for my app to record a unique identifier? Or is there a different mechanism to create or get a unique identifier?
#DaveSmits is on the right direction. You could register a GeofenceBackgroundtask to report user's location to your azure service. Besides current location, you also need to report current device channel Uri to your zaure device.
I believe you're familiar with WNS. If not, please check that document, it will explain what the channel Uri for you.
Then in your azure service, you need to save the location and channel Uri in some database tables. You would need to caculate the distance from a certain geo coordinate. If it meets the requirement, you can get all qualified channel Uris.(e.g. select channelUri from yourtable where location='xxxxx')
After you get all channel Uris, you could use it to send notifications to the specific users. About how to send notification, please check the WNS document.
I've answered a similar question on MSDN, it also needs to send notifications to the specific users.
there is nothing to track the location of the user in the push notifications. There are two things you can do:
solution 1:
- use a geofence that triggers a background task. If entering a geofence register for push notifications. If leaving the geofence unsubscribe again in your backend.
solution 2:
- Only send raw notifications and use a background task to handle them. In the background task evaulate the current location and if in the right location trigger the notification from code.

SignalR Communicating Between Hubs

How would I communicate between two separate hubs?
So Hub1 is my ChatHub for Support Agents and Hub2 is my Hub for customers.
Support agents have logins, customers have a form they fill out which creates a user and so on. But how can I pass the user created from Hub2 to Hub1 for all the users who have a Hub1(Support Agents) or is there some better way to do this?
Would I need to handle it all in Hub1 with some logic for differentiating between customers and agents?
May not be possible since the Hubs aren't static they are created per user right?
The problem with doing it all in one Hub is after the form is filled out it sends them to another page so they get a new connectionId and they have no Context.User.Identity.Name so there is no way to grab them again since I don't know their information from the new page.
You can use GlobalHost.ConnectionManager for communicating between Hubs:
var ctx = GlobalHost.ConnectionManager.GetHubContext<HubName>();
ctx.Clients.All.methodName(parameter);

azure notification hubs - app uninstall

I would like to use Azure Notification Hubs to send push notifications to users of my app running across iOS, Android and Windows Phone.
I have managed to get the basics working but I don't know how to manage the App uninstall story.
On starting, the mobile app will call my Identity Svc to get an Auth Token.
It then calls its Platform Notification service (eg Google Cloud Messaging, APNS) to get a PNS Token.
After persisting the token to local storage it will call a back-end Contact Svc to register the customer's device. This service will create a subscription to the Azure Notification hub for the device.
This is illustrated in the following diagram:
Later on a back-end publishing service will call the Contact Service requesting a push notification for a particular user id. The contact service will lookup the Id allocated to a tag on the notification hub and send a push request.
What options are available to determine when a customer uninstalls the app? Is it just a matter of trapping errors when calling "Send" on the notification hub? I guess this could work if only sending to a single user but my intention is that certain message types are to be published to multiple subscribers. On the initial registration of a device a subscription will be created for a tag of the user id but also for a more general tag such as "New Promotion". The publishing service would later want to issue a "New Promotion" notification to all devices.
Why do you need to know app uninstalls?
Notification Hubs automatically expire registrations for devices that get uninstalled.
Also, I would avoid persisting the PNSHandles in your service at all.
The current guidelines for using hubs are the following:
store the registrationIds of the registrations associated with the device in local storage. This enables you to update tags and channel information with a single update call.
Because mobile connections are not always reliable, it is best to avoid creating a new registration without being able to store the registrationId in local storage. This can result in the device registering multiple times, causing duplicate notifications. You can achieve this by using the Create Registration ID and Create or Update Registration REST APIs.
The first API returns a registrationId without actually creating a registration. When the ID has been securely stored on the device storage, the device can call the Create or Update Registration API.
So I would have your ContactSvc expose two functionalities:
a) create registration id (just call hub to get it)
b) create or update registration given (registrationId, pnsHandle, tags?)
Then your device keeps the regId in its storage, ad after getting the handle from PNS, if as regId is not there creates a new one with endpoint a), then updates the registration with pnsHandle and tags.
Note that in this way your service does not need to persist handles or UUIDs, and does not need to worry about app uninstalls.
If you are keeping track of users, one approach is to periodically (once a month?) check in your hub if its registrations are still there...
You can reach me at #eliodamaggio if this is not clear.

Does Azure Push Notification support a user Id or alias?

I am evaluating which Push Notification service to use out of Azure Mobile Services, Parse and Urban Airship.
One of the criteria is whether the service provides a way for the app to register a bespoke user Id or alias that can then easily be used when calling the service to send a push notification to an individual. This removes the need for our backend service to have a lookup table giving us the service registration ID for a given user.
Urban Airship has the alias feature: http://docs.urbanairship.com/connect/connect_audience.html#aliases
Parse has a sophisticated Installation object which behaves like a dictionary so that additional values can be added to it (like UserId). When the Parse service is called to send a Push Notification a query can be used to specify the user that will receive the message:
https://www.parse.com/docs/push_guide#sending-queries/REST
Is there an equivalent feature in Azure Mobile Services?
With Mobile Services, you would need to keep track of a user to token / channel URI / registration ID association in a table which is more work than you NEED to do. However, another feature of Windows Azure is Notification Hubs which does what you want (and much more). With Notification Hubs, from the client you say "I want to register for Notification Hubs, here are some tags you can use to push me information". Those tags can be anything you want including a User ID. Later on you can tell your Notification Hub to push to anyone registered with a certain tag. That would allow you to then push notifications out to any devices a specific user has registered.
The flow would look something like this:
Register with Push Provider (APNS, GCM, MPNS, WNS)
Send token to Notification Hubs along with tags (such as the User's ID)
Trigger a push to a specific Tag (i.e. User ID)
Notification Hubs will handle delivering a push to all devices with a Tag (again, their user ID)
Notification Hubs has client SDKs for WinPhone, WinStore, iOS, and Android so it's very easy to use from the client side. As far as triggering pushes goes, Notification Hubs exposes a REST API you can communicate with, there is a .NET SDK, a Node SDK, as well as an unofficial Java SDK. You can even use the Node SDK from Mobile Services which makes it super easy to combine authentication (i.e. getting User IDs) with data storage and push notifications. It also has lots of other features like templated push notifications so instead of specifying a different payload depending on what the device OS you're pushing to is, you can have the client application indicate how it should receive a certain type of push.

Resources