Part 2: Creating an alert using Service Bus and Logic Apps


IoT Hub offers device-to-cloud message routing to specific services endpoints, based on rules created using message properties values as filters without requiring any additional code. If a single message matches the condition of multiple rules, it will be delivered to each endpoint associated with the routes. However, there’s a protection against duplicated messages – if multiple routes points to the same endpoint, the message will be delivered just once.

See previous: Part 1: Connecting your device to IoT Hub and viewing real-time data

Understanding the routes and endpoints

IoT Hub has two default built-in endpoints (Events and Cloud to device feedback). Others services are available via custom endpoints: Azure Storage containers (blobs only), Event Hubs, Service Bus Queues and Service Bus Topics.


Important: When you use custom endpoints, only messages that doesn’t matches any rule will be delivered to the default built-in Events endpoint, unless you create a specific route to address the messages to it. This is important to be done, as some sample projects used in this experiment relies on messages delivered to the Events endpoint.

In the screen below I’ve created 2 routes:

  • devkit-route-events: delivery ALL messages to the Events endpoint;
  • devkit-route-sbqueue: delivery messages that contains the property “temperatureAlert = true” to a custom Service Bus Queue endpoint create previously;


In this case, a message that contains the property “temperatureAlert = true” will be delivered to both endpoints because it matches both rules.

Setting up IoT Hub, Service Bus and Logic Apps

Follow the steps on “IoT remote monitoring and notifications with Azure Logic Apps connecting your IoT hub and mailbox” to have the Service Bus and Logic Apps setup to send an email when the temperature alert threshold is reached.

The temperature threshold value is set on “config.h” file located in your GettingStarted project on Visual Studio Code. When the temperature reaches the value set on TEMPERATURE_ALERT (or higher), the device attaches the property “temperatureAlert” with the value “true” to the message sent to IoT Hub.


When a message is received by IoT Hub and routed to the Service Bus Queue, it triggers the Logic Apps and from there you can add any action or condition to deal with the data received. In this sample we are sending an email alert as shown in the designer below.


See next: Part 3: Using Machine Learning to calculate chance of precipitation and saving the output

One thought on “Part 2: Creating an alert using Service Bus and Logic Apps

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s