Quickstart: Deploy your first IoT Edge module from the Azure portal to a Windows device - preview

In this quickstart, use the Azure IoT Edge cloud interface to deploy prebuilt code remotely to an IoT Edge device. To accomplish this task, first use your Windows device to simulate an IoT Edge device, then you can deploy a module to it.

If you don't have an active Azure subscription, create a free account before you begin.

Prerequisites

This tutorial assumes that you're using a computer or virtual machine running Windows to simulate an Internet of Things device. If you're running Windows in a virtual machine, enable nested virtualization and allocate at least 2GB memory.

  1. Make sure you're using a supported Windows version:
    • Windows 10
    • Windows Server
  2. Install Docker for Windows and make sure it's running.
  3. Install Python 2.7 on Windows and make sure you can use the pip command.
  4. Run the following command to download the IoT Edge control script.

    pip install -U azure-iot-edge-runtime-ctl
    

Note

Azure IoT Edge can run either Windows containers or Linux containers. To use Windows containers, you have to run:

  • Windows 10 Fall Creators Update, or
  • Windows Server 1709 (Build 16299), or
  • Windows IoT Core (Build 16299) on a x64-based device

For Windows IoT Core, follow the instructions in Install the IoT Edge runtime on Windows IoT Core. Otherwise, simply configure Docker to use Windows containers, and optionally validate your prerequisites with the following powershell command:

Invoke-Expression (Invoke-WebRequest -useb https://aka.ms/iotedgewin)

Create an IoT hub with Azure CLI

Create an IoT hub in your Azure subscription. The free level of IoT Hub works for this quickstart. If you've used IoT Hub in the past and already have a free hub created, you can skip this section and go on to Register an IoT Edge device. Each subscription can only have one free IoT hub.

  1. Sign in to the Azure portal.
  2. Select the Cloud Shell button.

    Cloud Shell button

  3. Create a resource group. The following code creates a resource group called IoTEdge in the West US region:

    az group create --name IoTEdge --location westus
    
  4. Create an IoT hub in your new resource group. The following code creates a free F1 hub called MyIotHub in the resource group IoTEdge:

    az iot hub create --resource-group IoTEdge --name MyIotHub --sku F1 
    

Register an IoT Edge device

Create a device identity for your simulated device so that it can communicate with your IoT hub. Since IoT Edge devices behave and can be managed differently than typical IoT devices, you declare this to be an IoT Edge device from the beginning.

  1. In the Azure portal, navigate to your IoT hub.
  2. Select IoT Edge (preview) then select Add IoT Edge Device.

    Add IoT Edge Device

  3. Give your simulated device a unique device ID.

  4. Select Save to add your device.
  5. Select your new device from the list of devices.
  6. Copy the value for Connection string—primary key and save it. You'll use this value to configure the IoT Edge runtime in the next section.

Configure the IoT Edge runtime

The IoT Edge runtime is deployed on all IoT Edge devices. It comprises two modules. First, the IoT Edge agent facilitates deployment and monitoring of modules on the IoT Edge device. Second, the IoT Edge hub manages communications between modules on the IoT Edge device, and between the device and IoT Hub.

Configure the runtime with your IoT Edge device connection string from the previous section.

iotedgectl setup --connection-string "{device connection string}" --auto-cert-gen-force-no-passwords

Start the runtime.

iotedgectl start

Check Docker to see that the IoT Edge agent is running as a module.

docker ps

See edgeAgent in Docker

Deploy a module

One of the key capabilities of Azure IoT Edge is being able to deploy modules to your IoT Edge devices from the cloud. An IoT Edge module is an executable package implemented as a container. In this section, you deploy a module that generates telemetry for your simulated device.

  1. In the Azure portal, navigate to your IoT hub.
  2. Go to IoT Edge (preview) and select your IoT Edge device.
  3. Select Set Modules.
  4. Select Add IoT Edge Module.
  5. In the Name field, enter tempSensor.
  6. In the Image URI field, enter microsoft/azureiotedge-simulated-temperature-sensor:1.0-preview.
  7. Leave the other settings unchanged, and select Save.

    Save IoT Edge module after entering name and image URI

  8. Back in the Add modules step, select Next.

  9. In the Specify routes step, select Next.
  10. In the Review template step, select Submit.
  11. Return to the device details page and select Refresh. You should see the new tempSensor module running along the IoT Edge runtime.

    View tempSensor in list of deployed modules

View generated data

In this quickstart, you created a new IoT Edge device and installed the IoT Edge runtime on it. Then, you used the Azure portal to push an IoT Edge module to run on the device without having to make changes to the device itself. In this case, the module that you pushed creates environmental data that you can use for the tutorials.

Open the command prompt on the computer running your simulated device again. Confirm that the module deployed from the cloud is running on your IoT Edge device.

docker ps

View three modules on your device

View the messages being sent from the tempSensor module to the cloud.

docker logs -f tempSensor

View the data from your module

You can also view the telemetry the device is sending by using the IoT Hub explorer tool.

Clean up resources

When you no longer need the IoT Hub you created, you can use the az iot hub delete command to remove the resource and any devices associated with it:

az iot hub delete --name {your iot hub name} --resource-group {your resource group name}

Next steps

You learned how to deploy an IoT Edge module to an IoT Edge device. Now try deploying different types of Azure services as modules, so that you can analyze data at the edge.