A hands on workshop for an agrotech hackathon π½
In the previous step, you wrote the code to capture telemetry from the Raspberry Pi. In this step, you will export IoT telemetry to Azure Event Hubs.
Azure Event Hubs allow you to take streaming data and connect it to other services, such as storing the data or using Azure Stream Analytics to analyze the data in real time. Azure IoT Central can be configured to stream data to an Azure Event Hubs instance.
To export data you will need an Azure account. If you donβt have one, head to the Azure Account instructions to create an account.
There are two ways to create an Azure Event Hubs instance - from the Azure Portal or the Azure CLI.
The instance consists of a namespace, containing an event hub.
Open the Azure Portal
Log in with your Microsoft account if required
From the left-hand menu select + Create a resource
Search for Event Hubs
and select Event Hubs
Select Create
Fill in the details for the Event Hubs
Give the Event Hubs a name. This needs to be globally unique, so include things such as the data or your name, for example agrohackjim2020
. To make it easier, name it the same as your Azure IoT Central app.
Leave the Pricing Tier as Standard
Select your Azure subscription
For the Resource group, select Create new and name it AgroHack
, then select OK
Resource groups are logical groupings of Azure services, allowing you to manage all the services for a particular application or project together. At the end of this workshop this Resource Group will be deleted, deleting all the services created.
Select a Location closest to you
Leave the rest of the options as the defaults
Select Review + create
Select Create
Once the deployment has completed, select the Go to resource button.
From the Event Hub Namespace in the Azure Portal, select + Event Hub
Name the Event Hub Telemetry
Leave the rest of the options as the defaults
Select Create
To install the Azure CLI, head to the installation guide and follow the instructions for your OS.
From your terminal, log in to the Azure CLI using the following command
az login
A web browser window will be launched to allow you to log in to your Azure subscription
If you have multiple Azure subscriptions, you will need to select the one you want to use
List all the subscriptions using the following command
az account list --output table
Find the subscription id of the subscription you want to use and copy it
Set the active subscription using the following command
az account set --subscription <subscription id>
For the <subscription id>
, use the id you copied in the previous step
Run the following command to get a list of Azure locations
az account list-locations --output table
Note the name of the location closest to you
Create a new Resource Group with the following command
az group create --name AgroHack --location <location>
For the <location>
, use the name of the location closest to you.
This will create a Resource Group called AgroHack
in the location you specify.
Resource groups are logical groupings of Azure services, allowing you to manage all the services for a particular application or project together. At the end of this workshop this Resource Group will be deleted, deleting all the services created.
Create the event hubs namespace using the following command
az eventhubs namespace create
--location <location>
--name <account_name>
--resource-group AgroHack
For the <location>
, use the name of the location closest to you, the same location that you used for the resource group.
For the <account_name>
, pick a name that is globally unique, so include things such as the date or your name, for example agrohackjim2020
. To make it easier, name it the same as your Azure IoT Central app.
The --resource-group AgroHack
setting adds this event hubs namespace to the new Resource Group you created in the previous step.
Create the event hub inside the namespace using the following command
az eventhubs eventhub create
--name telemetry
--resource-group AgroHack
--namespace-name <namespace_name>
The --name telemetry
names the event hub as telemetry
.
The --resource-group AgroHack
setting adds this event hubs namespace to the new Resource Group you created in the previous step.
For the <namespace_name>
, use the name you used when creating the namespace.
Azure IoT Central can export data to a number of different services, either to route the data to multiple other services, or to store data. For example, it can send IoT messages to Azure Event Hubs, and other services can listen on these events and respond - maybe by running code to process each message.
Open the app in Azure IoT Central
Select Data export from the left-hand menu
Select the New button, then select the Azure Event Hubs option
Give the export a name, such as Export telemetry
Select the Azure Event Hubs Namespace you just created, along with the Event Hub
In the Data to export section, leave Telemetry turned on, and turn off Devices and Device templates
Select Save
The new data export job will appear in the list, showing a status. Wait until the status shows Running, this will only take about 30 seconds or so.
The easiest way to see messages flowing to the Event Hub is via the Azure Portal.
Open the Azure Portal
Log in with your Microsoft account if required
If you are not on the blade for the event hub you created, search for it by typing the name of the namespace into the search box at the top of the portal, and selecting the Event Hubs Namespace under the Resources section
In the Overview tab you should see message throughput on the graph
In this step you exported IoT telemetry to Azure Event Hubs. In the next step, you will create a storage account to store telemetry data.