Getting started with Azure IoT Hub

Azure IoT Hub provides a cloud-hosted back-end that allows you to connect virtually any device. Azure IoT hub lets you configure per-device authentication, built-in device management, and scaled provisioning.

In this blog post we are going to configure and connect an Azure IoT device simulator to Azure IoT hub.

Prerequisites

Create your Azure IoT Hub using the Azure Portal

If you prefer to use the Azure CLI, click here.

  1. Login into the Azure Portal.
  2. Search for and select IoT Hub.
    Search and select IoT Hub
  3. Click the + Create button.
    Create IoT Hub
  4. Fill out the following fields on the Basics tab:
    Project Details:
    – Select a subscription.
    – Create a new, or use an existing resource group.
    Instance Details
    – Enter the IoT Hub Name.
    – Select a region.

    Basics Tab
  5. Select the Management tab.
    Scale tier and units
    – Select F1: Free Tier from the Pricing and scale tier dropdown.
    – Click the Review + create button.
    Management Tab
  6. Click the Create button.
    Click Create Button
  7. Click the Go to resource button.

Create your Azure IoT Hub Using Azure CLI

  1. Open Azure Cloud Shell and select Bash from the dropdown.
  2. Your IoT needs to be contained in a resource group. You can either use an existing resource group or create a new one with the following command to create your resource group in East US:
    az group create --name {your resource group name} --location eastus
  3. Run the following command to create your IoT Hub in the F1 pricing tier:
    az iot hub create --name {your iot hub name} \
    --resource-group {your resource group name} --sku F1

Create your IoT Hub Message Routing

  1. Click on your IoT Hub Resource.
    Click on IoT Hub Resource
  2. Click Message Routing in the IoT Hub resource listview located under Hub Settings.
    Click Message Routing
  3. Click + Add
    Click Add
  4. Enter a name for your Message Route.
    – Click + Add Endpoint and select Storage.
    Add Endpoint

  5. Enter a name for your storage endpoint.
    – Click the Pick a container button.
    Pick a container
  6. Click + Storage Account.
    Add storage account
  7. Enter your storage account name.
    – Click OK.
    Create storage accoun
  8. Click the storage account you created in the last step.
    Click your storage account
  9. Click + Container to create a new container.
    Click Container
  10. Enter a name for Container and click Create.
    Create Container
  11. Select the container you created in the previous step and click the Select button.
    Select Container
  12. Click the Create button.
    Create Storage Endpoint
  13. Click Save
    Save a route

Create your IoT Device

  1. Click Devices in the IoT Hub resource listview located under Device Management.
    Select Devices
  2. Click Add Device.
    Click add device
  3. Enter a Device ID and click the Save button.
    Create Device
  4. Click the device created in the previous step.
    Select Device
  5. Copy the Primary Connection String.
    Copy primary connection string
  6. Click the following link to launch the Raspberry Pi Simulator.
  7. In the code pane, find the following line:
    const connectionString = '[Your IoT hub device connection string]';
    RP Simulator
  8. Paste the Primary Connection String you copied in step 5 in the '[Your IoT hub device connection string]' placeholder ensuring it is wrapped in single quotes.
  9. Click Run.
    Click Run
  10. The device will begin sending telemetry to Azure IoT Hub.
    Telemetry
  11. Navigate back to your IoT Hub in the Azure Portal.
  12. The metrics on the Overview blade should reflect the number of messages you sent from the Raspberry Pi simulator.
    Metrics

Summary

In this blog post we created an Azure IoT Hub, connected it to the Raspberry PI simulator and sent messages from the Raspberry Pi back to your Azure IoT hub.

Thank you for reading!


Posted

in

by

Tags:

%d bloggers like this: