Tushar
Tushar

Reputation: 167

IOT hub to Email Notification

I am developing a Azure IOTHUB use case.

I want to make a system that that sends an email notification on certain weight to the device owner.

What is the right approach to achieve that.

I have seen Logic apps is an option but how to implement it with multiple user account and devices.

Upvotes: 0

Views: 1618

Answers (3)

Daniel Krzyczkowski
Daniel Krzyczkowski

Reputation: 3157

I would like to present one another approach which I think is correct too (I tested this flow):

enter image description here

  1. Data is sent to the Azure IoT Hub from device
  2. Azure Stream Analytics filters this data basing on weight and deviceID
  3. Once data is analyzed there is a call to the Azure Function which triggers Azure Logic App with data collected from the Stream Analytics
  4. Azure Logic App receives data (HTTP trigger) from Azure Function App
  5. Then Logic App uses "Get row" action step to get user data from SQL Database
  6. Last step is up to you - you can use either "SendGrid - send e-mail" action or integrate Logic App with Outlook or even Office365, Gmail and other services.

Here are the links to the documentation:

Connect to SQL Server or Azure SQL Database from Azure Logic Apps

Send emails and manage mailing lists in SendGrid by using Azure Logic Apps

Upvotes: 0

Roman Kiss
Roman Kiss

Reputation: 8235

Basically, there are two solutions for your scenario, when each device has own criteria on the weight:

  1. The device twin desired property contains a weight value used for publishing a non-telemetry alert message by a real device to the Azure IoT Hub. This alert message can be routed in the Azure IoT Hub Routes to the custom endpoint the same way like is described in Jim's answer (ServiceBus->AzureFuction->SendGrid)

  2. The second solution is more complex, generic, very flexible and it doesn't require any special coding on the device side or device twin. It's based on the standard telemetry stream pipeline with Azure Stream Analytics (ASA) job for analyzing events and generating a notification message for output to the Azure Function with SendGrid. The ASA job used a reference data (user data, weight, etc.) from the blob file generated and refreshed by SQL Database. The following screen snippet shows this solution: enter image description here

Upvotes: 1

Jim O'Neil
Jim O'Neil

Reputation: 23764

I would use IoT Hub routing to push the messages that meet the weight criteria to a service bus queue. From there you can use an Azure Function with a Service Bus Trigger. I assume the user account information (e-mail address?) is available via a query in the SQL table. Azure Functions have a SendGrid binding that you'd then use to send out the e-mail.

Note that routing IoT Hub directly to a function is on the backlog.

Upvotes: 1

Related Questions