Use Azure IoT Tools for Visual Studio Code for Azure IoT Hub device management
In this article, you learn how to use Azure IoT Tools for Visual Studio Code with various management options on your development machine. Azure IoT Hub for VS Code is a useful Visual Studio Code extension that makes IoT Hub management and IoT application development easier. It comes with management options that you can use to perform various tasks.
Note
The features described in this article are available only in the standard tier of IoT Hub. For more information about the basic and standard/free IoT Hub tiers, see Choose the right IoT Hub tier for your solution.
Management option | Task |
---|---|
Direct methods | Make a device act such as starting or stopping sending messages or rebooting the device. |
Read device twin | Get the reported state of a device. For example, the device reports the LED is blinking now. |
Update device twin | Put a device into certain states, such as setting an LED to green or setting the telemetry send interval to 30 minutes. |
Cloud-to-device messages | Send notifications to a device. For example, "It is very likely to rain today. Don't forget to bring an umbrella." |
For more detailed explanation on the differences and guidance on using these options, see Device-to-cloud communication guidance and Cloud-to-device communication guidance.
Device twins are JSON documents that store device state information (metadata, configurations, and conditions). IoT Hub persists a device twin for each device that connects to it. For more information about device twins, see Get started with device twins.
Note
We recommend that you use the Azure Az PowerShell module to interact with Azure. See Install Azure PowerShell to get started. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Prerequisites
- An active Azure subscription.
- An Azure IoT hub under your subscription.
- Visual Studio Code
- Azure IoT Hub for VS Code or copy this URL and paste it into a browser window:
vscode:extension/vsciot-vscode.azure-iot-toolkit
.
Sign in to access your IoT hub
In Explorer view of VS Code, expand Azure IoT Hub Devices section in the bottom left corner.
Click Select IoT Hub in context menu.
A pop-up will show in the bottom right corner to let you sign in to Azure for the first time.
After you sign in, your Azure Subscription list will be shown, then select Azure Subscription and IoT Hub.
The device list will be shown in Azure IoT Hub Devices tab in a few seconds.
Note
You can also complete the set up by choosing Set IoT Hub Connection String. Enter the iothubowner policy connection string for the IoT hub that your IoT device connects to in the pop-up window.
Direct methods
Right-click your device and select Invoke Direct Method.
Enter the method name and payload in input box.
Results will be shown in OUTPUT > Azure IoT Hub view.
Read device twin
Right-click your device and select Edit Device Twin.
An azure-iot-device-twin.json file will be opened with the content of device twin.
Update device twin
Make some edits of tags or properties.desired field.
Right-click on the azure-iot-device-twin.json file.
Select Update Device Twin to update the device twin.
Send cloud-to-device messages
To send a message from your IoT hub to your device, follow these steps:
Right-click your device and select Send C2D Message to Device.
Enter the message in input box.
Results will be shown in OUTPUT > Azure IoT Hub view.
Next steps
You've learned how to use Azure IoT Hub for Visual Studio Code with various management options.
To continue to get started with Azure IoT Hub and to explore all extended IoT scenarios, see the following:
Feedback
Submit and view feedback for