Use Azure IoT Tools for Visual Studio Code to send and receive messages between your device and IoT Hub
Azure IoT Tools is a useful Visual Studio Code extension that makes IoT Hub management and IoT application development easier. This article focuses on how to use Azure IoT Tools for Visual Studio Code to send and receive messages between your device and your IoT hub.
Some of the features mentioned in this article, like cloud-to-device messaging, device twins, and device management, are only available in the standard tier of IoT Hub. For more information about the basic and standard IoT Hub tiers, see How to choose the right IoT Hub tier.
What you will learn
You learn how to use Azure IoT Tools for Visual Studio Code to monitor device-to-cloud messages and to send cloud-to-device messages. Device-to-cloud messages could be sensor data that your device collects and then sends to your IoT hub. Cloud-to-device messages could be commands that your IoT hub sends to your device to blink an LED that is connected to your device.
What you will do
Use Azure IoT Tools for Visual Studio Code to monitor device-to-cloud messages.
Use Azure IoT Tools for Visual Studio Code to send cloud-to-device messages.
What you need
An active Azure subscription.
An Azure IoT hub under your subscription.
Azure IoT Tools for VS Code or copy and paste this URL into a browser window:
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.
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.
Monitor device-to-cloud messages
To monitor messages that are sent from your device to your IoT hub, follow these steps:
Right-click your device and select Start Monitoring Built-in Event Endpoint.
The monitored messages will be shown in OUTPUT > Azure IoT Hub view.
To stop monitoring, right-click the OUTPUT view and select Stop Monitoring Built-in Event Endpoint.
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.
You’ve learned how to monitor device-to-cloud messages and send cloud-to-device messages between your IoT device and Azure IoT Hub.
To continue to get started with Azure IoT Hub and to explore all extended IoT scenarios, see the following: