简体   繁体   中英

How can I Implement the logic for to send the values of event hub (filtered values by stream analytics job) to IoT Hub using UWP App?

I am currently working on Internet Of Things, in my current project I was implemented the logic for to send temperature values to IoT Hub (using Raspberry PI2 and BMP280 sensor), in the azure part I created stream analytics job for receiving the messages from IoT Hub and filters those values based on my query like if temperature value exceeds 30 deg and post those filtered values to event hub is one of the output of the stream analytics job.

Query I wrote in stream analytics job.

SELECT
  System.timestamp AS Time,
  DeviceId,
  RoomTemp,
  RoomPressure,
  RoomAlt
INTO
  eventhub
FROM
  bmpsensordata
WHERE RoomTemp>35

I was already created one event hub in azure, and monitor those filtered values by stream analytics job, in dashboard of event hub what I was created earlier.

But I want to send the values (filtered values by stream analytics job) of event hub to IoT Hub from that I will receive the values in the form of alert message/ notification using UWP App(C# language).

Please tell me how I can do it above scenario.

Regards,

Pradeep

I think that your solution could look like in the diagram I prepared:

在此处输入图片说明

Once data is retrieved from the IoT Hub and analyzed by Stream Analytics it can call Azure Function which triggers Azure Notification Hub to send push notification to your UWP application. Please use my tutorial to see how to use Stream Analytics together with Azure function and at the end how to send SMS alerts - in your case you should replace the code with the one for Notification Hub:

https://github.com/Daniel-Krzyczkowski/Daniel-Krzyczkowski.github.io/blob/master/cloudyofthings/article1/index.md

Here is the documentation how to use Notification Hub SDK and how to integrate it with UWP applications:

https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-aspnet-backend-windows-dotnet-wns-notification

I think you will need another Stream Analytics job with Event Hub as input, and IoT Hub as output. Then you can receive the cloud-to-device messages from IoT Hub in your UWP application as described in this article .

You can have multiple output from a single Stream Analytics job. Refer to https://blogs.msdn.microsoft.com/streamanalytics/2015/09/16/query-pattern-of-the-week-send-data-to-multiple-outputs/ for more information on this.

Stream Analytics does not have a direct output to IoT hub though. You'd need to put the info in to an EventHub and have a worker role process this and send the info from there in to IoT hub

Per my experience, I think you can try to integrate Notification Hub with IoTHub , Stream Analytics , Event Hub to implement your needs. Please see the details below.

  1. Create a Stream Analytics Job with IoTHub as input and Event Hub as output for filtering sensor data.
  2. Create a Notification Hub for pushing data to UWP app.
  3. Create an server service or a scheduler job for receiving and sending the data from the Event Hub to the Notification Hub, such as continuous WebJob.

As references, there are some documents which show you how to do it.

  1. Get started with Azure Stream Analytics to process data from IoT devices , https://azure.microsoft.com/en-us/documentation/articles/stream-analytics-get-started-with-azure-stream-analytics-to-process-data-from-iot-devices/
  2. Getting started with Notification Hubs for Windows Store Apps, https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-windows-store-dotnet-get-started/
  3. Event Hubs programming guide, https://azure.microsoft.com/en-us/documentation/articles/event-hubs-programming-guide/
  4. Notification Hub Server SDK reference for .NET, https://msdn.microsoft.com/library/mt414893.aspx
  5. Create a .NET WebJob in Azure App Service (run continuously), https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-webjobs-sdk-get-started/

Hope it helps.

Any concern, please feel free to let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM