Get In Touch
401, Parijaat, Baner Pune 411021
[email protected]
Business Inquiries
[email protected]
Ph: +91 9595 280 870
Back

Bi-Directional Communication Between IoT Devices and Azure Services

How Azure services can help us enable bi-directional communication between IOT devices and cloud.

The importance of IOT devices in today’s world is profound, as they are improving daily life, driving technological advancements and revolutionizing industries. Some of the applications of IOT devices in today’s world are smart homes (smart lighting, home security), smart cities (smart streetlight, public utilities, solar), transportation and logistics (vehicle tracking, shipment tracking) and many more, with profound use of IOT devices in today’s world it becomes difficult to monitor and extract data gathered by these IOT devices when deployed in multiple places.

Below we will discuss how different azure services can help us monitor and use the data gathered by these IOT devices.

IoT Hub: Central messaging hub

IoT Hub is a managed cloud service by Microsoft Azure that acts as a central message hub for secure and reliable communication between IoT devices and the cloud.

Azure IoT Hub offers a wide range of capabilities –

 

Device registration

  • Create, manage and authenticate IoT devices with unique identities.
  • Ensures secure communication between cloud and devices using symmetric keys, SAS tokens.

Device management

  • Monitor device status and its connectivity.
  • Configure and synchronize device settings using device twins.

Bi-directional communication

  • Device to cloud communication – Send telemetry data, logs or alerts from device to cloud.
  • Cloud to device communication – Send commands, updates, notifications from cloud to device.

Device messaging

  • Collect real time data from IoT devices for analysis and visualization.
  • Route device messages to multiple endpoints like Azure event hubs, Azure functions, Azure event grids, Blob Storage etc.

Integration with multiple azure services

  • Perform real-time analytics on IoT data using Azure stream analytics.
  • Trigger server less workflows based on IoT messages using Azure Functions.
  • Store raw IoT data for archival using Azure blob storage.
  • Set up alerts for anomalies, device failures, or threshold breaches using Azure Monitor or Logic Apps.

Supported communication protocols

  • MQTT (Message Queuing Telemetry Transport)
  • HTTP
  • AMQP (Advanced Message Queuing Protocol

How to use telemetry data received from IoT devices for analysis and visualization?

Azure offers two ways to gather and collect telemetry data from IoT devices

Message Routing

Message routing allows telemetry data (device-to-cloud) messages and device lifecycle events (connectivity) to various endpoints without any boilerplate code to manually manage data flow. This feature ensures efficient data flow to other Azure services as endpoints.

Key Concepts:

  1. Source – Represents where the data comes from, example – device telemetry data, device lifecycle events. In our case all the messages from devices are sent to IoT Hub.
  1. Routing Queries – IoT Hub allows us to add SQL filters to filter the messages received from IoT devices. Example – a IoT device sensing temperature, on reaching a specific threshold the message will be routed to the endpoint, temperature > 30 routes only high temperature telemetry to the specific endpoint and discards the rest.
  1. Endpoints – The destination where the messages are routed. Major endpoints include Azure Blob Storage, Azure Event Hubs, Azure Service Bus, Azure Cosmos Db etc. IoT Hub ensures messages from devices arrive in ordered fashion and no message is lost in transit.
Example scenario of using message routing
  1. High priority alerts – Send messages to Azure Event Hubs or Azure Service Bus when a specific condition is met example – temperature > 30. IoT Hub offers SQL filter to achieve without processing all the messages manually.
  1. Archiving data – Store all the messages received from devices using Azure Blob Storage or Azure Cosmos Db.
  1. Lifecycle event monitoring – When monitoring deviceLifecycleEvents. On receiving Disconnected as device state we can use Azure Functions to alert a system.

Benefits of using message routing

  1. No code maintenance – Routing logic is defined in IoT Hub, we do not have to define any logic in our backend code or device code.
  1. Scalability –  IoT Hub can manage data flow for millions of devices easily.
  1. Filtering data – It is easy to filter data using SQL queries when certain threshold is met. This does not require to write any backend code or device code.
  1. Ordered Sequence – IoT Hub ensures the messages reaching endpoints are always received in ordered fashion.

Event Routing – Azure Event Grid

Azure Event Grid is an event routing service that uses an event driven architecture to route events generated from event sources to event handlers seamlessly.

Key Concepts:
  1. Event Source – Sources are systems or services that generate an event, In our case IoT Hub as a service acts as an event source.
  1. Event Handlers – Handlers are services that handle an event, Example services can be – Azure Event Hubs, Web Hooks, Azure Functions, Logic Apps.
  1. Event Routing – Events are routed from source to handlers based on event subscription. Each subscription can have filters to only provide necessary events.
How Event Grid works:
  1. An event source generates an event such as a blob storage generating an event on file creation, similarly in our case receiving telemetry messages on IoT Hub is an event.
  1. Event Grid will process the event and matches it with subscription based on filters.
  1. Event Grid sends the events to the specific handler for further processing.

Differences between message routing and event routing.

Aspect Message Routing Event Routing
Order of telemetry messages received from IoT Devices. Order is maintained Order is not maintained, Messaging can become out of order after a delay.
Trigger Triggered by messages sent to IoT Hub from IoT Devices. Triggered by events generated by an event source (IoT Hub).
No. Of routes In a single IoT Hub instance a maximum of 100 messaging routes are allowed. In a single IoT Hub instance a maximum of 500 event subscribers can be allowed.
Allowed destination Azure Event Hub, Azure Blob Storage, Azure Cosmos Db, Azure Service Bus, Azure functions. All the services mentioned in message routing + many more subscriber services offered by Azure.

Azure IoT Hub, Azure Event Hub and Azure Event Grid are some of the services offered by Azure to enable bidirectional communication between cloud and IoT devices.

Using such managed services, it makes it easy to monitor and capture telemetry data from IoT devices.

When choosing message routing or event routing, If order of messages is important choose message routing else event routing.

If you found this blog insightful, explore more topics on industrial automation and IoT on our website. For further discussions or inquiries, feel free to contact the author at [email protected]. We’d love to hear your thoughts!

Kshitij Gajbhiye
Kshitij Gajbhiye

Leave a Reply

Your email address will not be published. Required fields are marked *