Use VS Code as IoT Hub Device Simulator — Say Hello to Azure IoT Hub in 5 Minutes


When doing development for Azure IoT solutions, developers may want to test and debug his cloud solution with a real device. However, not every developer has a real device in his hand.  With the Azure IoT Toolkit extension for Visual Studio Code, you could easily use VS Code as a device simulator to quickly interact with Azure IoT Hub. Let's see how easy it is to send a D2C (device-to-cloud) in VS Code! Say Hello to IoT Hub in VS Code in 5 minutes!

Prerequisites

  1. If you don’t have an Azure subscription, create a free account before you begin.
  2. Install the Visual Studio Code extension Azure IoT Toolkit.

Create an IoT hub

The first step is to create an IoT hub in your subscription from VS Code.

  1. Click ... > Create IoT Hub at AZURE IOT HUB DEVICES tab, or type Azure IoT Hub: Create IoT Hub in Command Palette. (If you want to use an existing IoT Hub, Click ... > Select IoT Hub at AZURE IOT HUB DEVICES tab)
  2. Choose your subscription, resource group, and the closest deploy location to you.
  3. For Pricing and scale tier, select the F1 - Free tier if it's still available on your subscription.
  4. Enter the name of your IoT Hub.
  5. Wait a few minutes until the IoT Hub is created. you can see that your devices status become No device in ....

create hub

Register a device

A device must be registered with your IoT hub before it can connect.

  1. Click ... > Create Device at AZURE IOT HUB DEVICES tab, or type Azure IoT Hub: Create Device in Command Palette.
  2. Enter device ID and press Enter.
  3. Wait a few seconds until the new device is created.

create device

Say Hello to IoT Hub (Send D2C message)

Right-click your device and select Send D2C message to IoT Hub, then enter the message, results will be shown in OUTPUT > Azure IoT Toolkit view. Your 'Hello World' is sent to Azure IoT Hub!

send d2c

Monitor IoT Hub D2C message in VS Code

While you could send message to your IoT Hub, it is also possible to monitor those message in VS Code.

  1. Right-click your device and select Start Monitoring D2C Message.

start monitor

  1. The monitored messages will be shown in OUTPUT > Azure IoT Toolkit view.
  2. To stop monitoring, right-click the OUTPUT view and select Stop Monitoring D2C Message.

stop monitor

Is that cool? You could send and receive messages for Azure IoT Hub very easily in VS Code. Is that all? Not yet! Actually, you could use Azure IoT Toolkit extension to do lots of things when you develop with Azure IoT Hub! Checkout with our Wiki Page to see the full features and tutorials. Azure IoT Toolkit makes your Azure IoT development easier.

Useful Resources:

Comments (0)

Skip to main content