Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Azure icon
Labs

Using IoT Hub Direct Methods to Change Device Properties

The primary purpose for an Azure IoT hub is to be somewhere the devices, or "things," can send telemetry. But did you know it can talk *back* to the things as well? Standard Tiers of Azure IoT Hub allow for cloud-to-device communication. One of the options by which we can communicate from our back-end applications to our devices is by using direct methods. Direct methods are used for communications that require immediate confirmation of the result. Direct methods are often used for interactive control of devices. In this hands-on lab, we will create a device in a pre-provisioned Azure IoT hub and then use a Node.js application to simulate the physical device. As our "device" sends telemetry information back to the IoT hub, we will use another Node.js application to send a direct method to the device, forcing it to change the interval in which it provides telemetry.

Azure icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Jul 02, 2025
Duration
1h 15m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Register the Device with an Azure IoT Hub
    1. Access Azure Cloud Shell using the credentials provided in the lab.

    2. Choose the Bash environment.

    3. Select Show advanced settings.

    4. Use the existing storage account that resides in the resource group location and the existing cloudshell file share name.

    5. Install the Azure IoT extension for CLI:

      az extension add --name azure-iot
      
    6. Register the device (XXXXX is the five-character suffix for the lab resources):

      az iot hub device-identity create --device-id IoTDevice1 --hub-name iothub-XXXXX
      
    7. Obtain the connection string for the device application (XXXXX is the five-character suffix for the lab resources):

      az iot hub device-identity connection-string show --hub-name iothub-XXXXX --device-id IoTDevice1 --output table
      
    8. Copy the connection string to your clipboard and paste it into a text document.

    9. Obtain the connection string for the back-end application (XXXXX is the five-character suffix for the lab resources):

      az iot hub connection-string show -n iothub-XXXX --policy-name service --output table
      
    10. Copy the connection string to your clipboard and paste it into a text document.

  2. Challenge

    Configure and Launch the Simulated Device
    1. Download the sample Node.js IoT project from Github by typing the following:

      wget https://github.com/Azure-Samples/azure-iot-samples-node/archive/master.zip
      
    2. Unzip the project into your home directory:

      unzip master.zip
      
    3. Change to the directory for the simulated device Node.js application:

      cd azure-iot-samples-node-master/iot-hub/Quickstarts/simulated-device-2
      
    4. Edit the SimulatedDevice.js file, replacing the value of the connectionString variable with the device connection string you made a note of earlier. Save the file.

    5. Install the required libraries and run the simulated device application:

      npm install
      
      node SimulatedDevice.js
      
    6. Verify the "device" is sending telemetry data as shown in the following screenshot:

      Device Telemetry

  3. Challenge

    Configure and Launch the Back-End Application
    1. Change to the directory for the back-end Node.js application:

      cd azure-iot-samples-node-master/iot-hub/Quickstarts/back-end-application
      
      1. Edit the BackEndApplication.js file, replacing the value of the connectionString variable with the service connection string you made a note of earlier, and replacing the value of the deviceId variable to IoTDevice1. Save the file.
    2. Install the required libraries and run the back-end application:

      npm install
      
      node BackEndApplication.js
      
    3. Verify the back-end application has changed the telemetry interval for the device to 10 seconds:

      App Telemetry Interval

      Back-end Application Response

      Device Telemetry Interval

      Device Response

About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight