Deploy Azure IoT Edge on a simulated device in Linux - preview

Azure IoT Edge enables you to perform analytics and data processing on your devices, instead of having to push all the data to the cloud. The IoT Edge tutorials demonstrate how to deploy different types of modules, built from Azure services or custom code, but first you need a device to test.

In this tutorial you learn how to:

  1. Create an IoT Hub
  2. Register an IoT Edge device
  3. Start the IoT Edge runtime
  4. Deploy a module

Tutorial architecture

The simulated device that you create in this tutorial is a monitor that generates temperature, humidity, and pressure data. The other Azure IoT Edge tutorials build upon the work you do here by deploying modules that analyze the data for business insights.

Prerequisites

This tutorial assumes that you're using a computer or virtual machine running Linux to simulate an Internet of Things device. The following services are required to successfully deploy an IoT Edge device:

  • Install Docker for Linux and make sure it's running.
  • Most Linux distributions, including Ubuntu, already have Python 2.7 installed. Use the following command to make sure that pip is installed: sudo apt-get install python-pip.

Create an IoT hub

Start the tutorial by creating your IoT Hub. Create IoT Hub

  1. Sign in to the Azure portal.
  2. Select New > Internet of Things > IoT Hub.

    Azure portal Jumpbar

  3. In the IoT hub pane, enter the following information for your IoT hub:

    • Name: Create a name for your IoT hub. If the name you enter is valid, a green check mark appears.

    Important

    The IoT hub will be publicly discoverable as a DNS endpoint, so make sure to avoid any sensitive information while naming it.

    • Pricing and scale tier: For this tutorial, select the F1 - Free tier. For more information, see the Pricing and scale tier.

    • Resource group: Create a resource group to host the IoT hub or use an existing one. For more information, see Use resource groups to manage your Azure resources

    • Location: Select the closest location to you.

    • Pin to dashboard: Check this option for easy access to your IoT hub from the dashboard.

      IoT hub window

  4. Click Create. Your IoT hub might take a few minutes to create. You can monitor the progress in the Notifications pane.

Register an IoT Edge device

Register an IoT Edge device with your newly created IoT Hub. Register a 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.

Install and start the IoT Edge runtime

Install and start the Azure IoT Edge runtime on your device. Register a device

The IoT Edge runtime is deployed on all IoT Edge devices. It comprises two modules. The IoT Edge agent facilitates deployment and monitoring of modules on the IoT Edge device. The IoT Edge hub manages communications between modules on the IoT Edge device, and between the device and IoT Hub. When you configure the runtime on your new device, only the IoT Edge agent will start at first. The IoT Edge hub comes later when you deploy a module.

On the machine where you'll run the IoT Edge device, download the IoT Edge control script:

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

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

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

Start the runtime:

sudo iotedgectl start

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

sudo docker ps

See edgeAgent in Docker

Deploy a module

Manage your Azure IoT Edge device from the cloud to deploy a module which will send telemetry data to IoT Hub. Register a device

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 tutorial, 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:

sudo docker ps

View three modules on your device

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

sudo 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.

Next steps

In this tutorial, you created a new IoT Edge device and used the Azure IoT Edge cloud interface to deploy code onto the device. Now, you have a simulated device generating raw data about its environment.

This tutorial is the prerequisite for all of the other IoT Edge tutorials. You can continue on to any of the other tutorials to learn how Azure IoT Edge can help you turn this data into business insights at the edge.