How To Send Device Telemetry Data From Azure IoT Hub to WEGnology
Microsoft Azure provides the raw cloud infrastructure to build cloud-native applications and also contains their IoT management service, Azure IoT Hub. Azure IoT Hub integrates with Azure Event Grid so that you can send events to WEGnology via Webhooks.
Because WEGnology is device agnostic, data can come from anywhere, including Azure, to power your IoT solution, including End-user Experiences. This tutorial will walk you through getting data from Azure IoT Hub into WEGnology.
Prerequisites
- Familiarity with Microsoft Azure and IoT Hub
- Devices registered and reporting telemetry data to Azure’s IoT Hub.
Creating a Webhook
First, let’s create a Webhook to receive messages from Azure Event Grid.
- Navigate to “Webhooks”.
Select “Add Workflow” and give your Webhook a friendly name.
Select “Wait for reply from workflow”
Select “Create Webhook”.
Upon Creating your Webhook, WEGnology will generate a URL that looks like the following:
https://triggers.app.wnology.io/webhooks/osf69cFXmBXqRBVRHms30J5CSmfUL5xpNU5rAc3G
Make note of this URL as we will be using to configure Azure Event Grid.
When selecting “Wait for reply from workflow”. This is helpful if you would like to send a response back to Azure. This provides an easy way for you to communicate back and forth with Azure IoT Hub. If not, WEGnology will always respond with {"success": true}
.
Create a Workflow
In order to effectively monitor the messages being sent from Azure through the webhook endpoint, let’s create a Workflow that is triggered when our webhook is hit.
Import the example Application Workflow.
Once done, you will have imported a workflow that looks like the following:
- Update the Webhook Trigger to select your newly created Webhook as the “Webhook Name”.
Configure Azure IoT Hub
Now, you have a workflow to accept messages from Azure. Next, we will configure the Azure Event Hub and walkthrough the workflow we imported.
- Within IoT Hub, select “Events”.
- Create a new Event Subscription.
Configure the following properties for the new Event Subscription:
- Name the Event Subscription.
- Configure
data
as the “System Topic Name”. - In the “Event Types” configuration, Select at least “Device Telemetry” and any other event you’d like to forward to WEGnology.
- Select “Web Hook” as the “Endpoint Type”
- Place the URL for the WEGnology Webhook created in the previous section as the “Endpoint”.
Note: Ensure that your Azure subscription has the EventGrid and EventHub resources registered. See the Microsoft Documentation on Registering Resource Providers for more information.
Testing
Now that you’ve configured your Webhook, and Azure IoT Hub as events are now forwarding!
Microsoft provides the following quickstart guide to simulate device data using a Node.js back end application: Quickstart: Send telemetry from a device to an IoT hub and read it with a back-end application (Node.js).
Now, let’s go through the Workflow to see how it’s functioning.
Webhook Verification
When you first create your EventGrid subscription, the first message sent to your Webhook URL by Azure is a request for validation.
In order to successfully validate the Webhook, WEGnology must reply back to Azure with the validation code contained in this initial subscription validation event.
If the Event Subscription was created properly in Azure, the very first message to WEGnology contains a payload that resembles the following:
The string found under validationCode
is what WEGnology needs to reply back to Azure with, along with a HTTP 200 OK response status code.
The reply happens in the Webhook: Reply Output Node.
In the “Reply Body” configuration, we provide a response that contains the validation code from the initial payload:
{
"validationResponse": "{{data.body.[0].data.validationCode}}"
}
After the verification is complete, any subsequent request will be validated.
Handling Event Types
When the Event Hub subscription was created in Azure, five options existed for event types: Device Created, Device Deleted, Device Connected, Device Disconnected and Device Telemetry.
In the example workflow, you can use the Switch Node to handle each event type in WEGnology.
At the payload path {{data.body.[0].eventType}}
we will find the event type for the current request.
Decoding Data From Azure IoT Hub
The device telemetry data from Azure for our simulated device is delivered to WEGnology as a Base64 encoded string, this will need to be decoded for use by our WEGnology device.
Using the Mutate Node, you can use templating to decode base64-encoded payload value:
{{{decodeBase64 data.body.[0].data.body}}}
What’s Next
Upon completion of this workflow, device data from Azure is successfully being reported to WEGnology and is available for use across the WEGnology platform - use in other workflows, or the development of data visualization through a dashboard, as seen below:
Here are further resources as you build your application:
Was this page helpful?
Still looking for help? You can also search the WEGnology Forums or submit your question there.