{"id":1445,"date":"2018-07-12T22:13:51","date_gmt":"2018-07-12T14:13:51","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/iotdev\/?p=1445"},"modified":"2019-02-15T10:27:10","modified_gmt":"2019-02-15T02:27:10","slug":"use-vs-code-as-iot-hub-device-simulator-say-hello-to-azure-iot-hub-in-5-minutes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/iotdev\/use-vs-code-as-iot-hub-device-simulator-say-hello-to-azure-iot-hub-in-5-minutes\/","title":{"rendered":"Use VS Code as IoT Hub Device Simulator &#8212; Say Hello to Azure IoT Hub in 5 Minutes"},"content":{"rendered":"<p>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.\u00a0 With the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-toolkit\" target=\"_blank\" rel=\"noopener\">Azure IoT Toolkit extension<\/a> for Visual Studio Code, you could easily use VS Code as a device simulator to quickly interact with Azure IoT Hub. Let&#8217;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!<\/p>\n<h2>Prerequisites<\/h2>\n<ol>\n<li>If you don\u2019t have an Azure subscription, create a\u00a0<a href=\"https:\/\/azure.microsoft.com\/free\/?WT.mc_id=A261C142F\" rel=\"nofollow\">free account<\/a>\u00a0before you begin.<\/li>\n<li>Install the Visual Studio Code extension\u00a0<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-toolkit\" rel=\"nofollow\">Azure IoT Toolkit<\/a>.<\/li>\n<\/ol>\n<h2>Create an IoT hub<\/h2>\n<p>The first step is to\u00a0create an IoT hub\u00a0in your subscription from VS Code.<\/p>\n<ol>\n<li>Click\u00a0<strong>&#8230; &gt; Create IoT Hub<\/strong>\u00a0at\u00a0<strong>AZURE IOT HUB DEVICES<\/strong>\u00a0tab, or type\u00a0<strong>Azure IoT Hub: Create IoT Hub<\/strong>\u00a0in\u00a0Command Palette. (If you want to use an existing IoT Hub, Click\u00a0<strong>&#8230; &gt; Select IoT Hub<\/strong>\u00a0at\u00a0<strong>AZURE IOT HUB DEVICES<\/strong>\u00a0tab)<\/li>\n<li>Choose your subscription, resource group, and the closest deploy location to you.<\/li>\n<li>For\u00a0Pricing and scale tier, select the\u00a0<strong>F1 &#8211; Free<\/strong>\u00a0tier if it&#8217;s still available on your subscription.<\/li>\n<li>Enter the name of your IoT Hub.<\/li>\n<li>Wait a few minutes until the IoT Hub is created. you can see that your devices status become\u00a0<strong>No device in &#8230;<\/strong>.<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2018\/07\/createhub.gif\" alt=\"create hub\" \/><\/p>\n<h2><a id=\"user-content-register-a-device\" class=\"anchor\" href=\"https:\/\/github.com\/Microsoft\/vscode-azure-iot-toolkit\/wiki\/Quickstart-Node.js#register-a-device\"><\/a>Register a device<\/h2>\n<p>A device must\u00a0be registered\u00a0with your IoT hub before it can connect.<\/p>\n<ol>\n<li>Click\u00a0<strong>&#8230; &gt; Create Device<\/strong>\u00a0at\u00a0<strong>AZURE IOT HUB DEVICES<\/strong>\u00a0tab, or type\u00a0<strong>Azure IoT Hub: Create Device<\/strong>\u00a0in\u00a0Command Palette.<\/li>\n<li>Enter device ID and press\u00a0<strong>Enter<\/strong>.<\/li>\n<li>Wait a few seconds until the new device is created.<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2018\/07\/createdevice.gif\" alt=\"create device\" \/><\/p>\n<h2>Say Hello to IoT Hub (Send D2C message)<\/h2>\n<p>Right-click your device and select\u00a0<strong>Send D2C message to IoT Hub<\/strong>, then enter the message, results will be shown in\u00a0<strong>OUTPUT &gt; Azure IoT Toolkit<\/strong>\u00a0view. Your &#8216;Hello World&#8217; is sent to Azure IoT Hub!<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2018\/07\/sendd2c.gif\" alt=\"send d2c\" \/><\/p>\n<h2>Monitor IoT Hub D2C message in VS Code<\/h2>\n<p>While you could send message to your IoT Hub, it is also possible to\u00a0monitor those message\u00a0in VS Code.<\/p>\n<ol>\n<li>Right-click your device and select\u00a0<strong>Start Monitoring D2C Message<\/strong>.<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2018\/07\/startmonitor.png\" alt=\"start monitor\" \/><\/p>\n<ol start=\"2\">\n<li>The monitored messages will be shown in\u00a0<strong>OUTPUT &gt; Azure IoT Toolkit<\/strong>\u00a0view.<\/li>\n<li>To stop monitoring, right-click the\u00a0<strong>OUTPUT<\/strong>\u00a0view and select\u00a0<strong>Stop Monitoring D2C Message<\/strong>.<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/iotdev\/wp-content\/uploads\/sites\/24\/2018\/07\/stopmonitor.png\" alt=\"stop monitor\" \/><\/p>\n<p>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 <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-toolkit\" target=\"_blank\" rel=\"noopener\">Azure IoT Toolkit extension<\/a> to do lots of things when you develop with Azure IoT Hub! Checkout with our <a href=\"https:\/\/github.com\/Microsoft\/vscode-azure-iot-toolkit\/wiki\">Wiki Page<\/a> to see the full features and tutorials. Azure IoT Toolkit makes your Azure IoT development easier.<\/p>\n<p>Useful Resources:<\/p>\n<ul>\n<li><a href=\"https:\/\/channel9.msdn.com\/Shows\/Internet-of-Things-Show\/Azure-IoT-Toolkit-extension-for-Visual-Studio-Code\" target=\"_blank\" rel=\"noopener\">Channel 9 video: Walkthrough of Azure IoT Toolkit extension<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-hub\/iot-hub-vscode-iot-toolkit-cloud-device-messaging\" rel=\"nofollow\">Use Azure IoT Toolkit to send and receive messages between your device and IoT Hub<\/a><\/li>\n<li><a href=\"https:\/\/blogs.msdn.microsoft.com\/iotdev\/2017\/09\/01\/handy-tool-when-you-develop-with-azure-iot\/\" target=\"_blank\" rel=\"noopener\">Handy Tool When You Develop With Azure IoT<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Microsoft\/vscode-azure-iot-toolkit\/wiki\/Quickstart-Node.js\">Create and control an IoT device connected to an IoT hub (Node.js)<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Microsoft\/vscode-azure-iot-toolkit\/wiki\/Quickstart-.NET\">Create and control an IoT device connected to an IoT hub (.NET)<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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.\u00a0 With the Azure IoT Toolkit extension for Visual Studio Code, you could easily use VS Code as a device simulator to quickly interact [&hellip;]<\/p>\n","protected":false},"author":672,"featured_media":1855,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,12,17,33,35],"class_list":["post-1445","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-iot-dev","tag-azure-iot-hub","tag-device-simulation","tag-iot","tag-visual-studio-code","tag-vs-code"],"acf":[],"blog_post_summary":"<p>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.\u00a0 With the Azure IoT Toolkit extension for Visual Studio Code, you could easily use VS Code as a device simulator to quickly interact [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts\/1445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/users\/672"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/comments?post=1445"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/posts\/1445\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/media\/1855"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/media?parent=1445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/categories?post=1445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/iotdev\/wp-json\/wp\/v2\/tags?post=1445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}