Skip to content

Latest commit

 

History

History
79 lines (46 loc) · 4.65 KB

Lab-3.md

File metadata and controls

79 lines (46 loc) · 4.65 KB

Lab-3: Connect to Azure IoT Hub

Goals

  • Hands-on with Azure IoT Hub configuration
  • Understand how will IoT Hub DPS provision Azure Sphere device
  • Understand Azure IoT Hub Device to Cloud message and Device Twin
  • Get familiar with the basics of Azure IoT C device SDK API

Steps

  1. Follow Setup IoT Hub page to setup cloud resources, the key steps are:

    • Create Azure IoT Hub and DPS and link them
    • Upload tenant CA certificate to DPS and finish Proof of Procession
    • Add a enrollment group in DPS to provision Azure Sphere devices

Azure IoT Hub DPS service do not allow to use free subscription, You should use a pay-as-you-go subscription for this lab.

  1. After connect hardware to your PC, enable device debug and disable OTA in Azure Sphere utility by:

    azsphere device enable-development

  2. Make sure WiFi credential is configured and Azure Sphere is connected to the WiFi Access Point. If Lab-2 is skipped, please follow Step 1) and 2) in Ove-The-Air upgrade to configure the WiFi ssid and password.

  3. Open the AzureIoT project in .\azure-sphere-samples\Samples\AzureIoT folder. If you're using AVNET_MT3620_SK board, ensure that the hardware definition file is updated. Please refer to Step 4 in Lab-1 to get the hardware definition file updated.

  4. Before building the project, there are three key information that need to be provided to the applicaton via the app_manifest.json file.

    1. The Tenant ID for your Azure Sphere device
    2. The Scope ID for your device provisioning service (DPS) instance
    3. The Azure IoT Hub URL for your IoT hub

    This link provides your information about how to get these information

    IMPORTANT! DON'T delete the exisiting DPS global endpoint: global.azure-devices-provisioning.net in AllowedConnections

  5. Select GDB Debugger (HLCore) as debug target and press F5 to start build and load target application onto device for debugging.

  6. From the local device output log window, it shows that the device is currently sending simulated telemetry data to the IoT Hub upon successful connection.

    Azure IoT Hub is the core PaaS that enable reliable and secure bidirectional communications between millions of IoT devices and a cloud solution. It exposes service API for user to integrate your own business backend for data analystic, storage and show. In this Lab, we will use a tool called Device Explorer Tool to simulate an user application to sink data and control IoT device.

  7. Download and install Azure IoT Explorer.msi, the latest cross-platform management tool for Azure IoT platform

  8. Navigate to your IoT Hub portal and find the iothubowner policy's connection string under shared access policies setting, click the icon to copy.

  9. Open Azure IoT Explorer and paste connection string to the dialog, click update to get access to IoT Hub.

  1. Select the connected device and go to Telemetry tab, click Start to read telemetry from the build-in endpoint of IoT Hub

  1. In sample code, the LED5 is controlled by Device Twin mechanism. Go to Device Twin tab you will see the whole twin document on the cloud. In Device Twin window, add a property "StatusLED":{"value":true} under the "desired" property and remove all other key-value. Then click Save button to update the Device Twin. Your device will be notified for this property change and light LED5 on board accordingly.

  2. User can click Refresh button to get the updated twin document. In "reported" seciton you will observe the status reported by device.

Read more