{"id":15876,"date":"2017-12-12T09:00:54","date_gmt":"2017-12-12T17:00:54","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudio\/?p=15876"},"modified":"2019-10-24T17:36:27","modified_gmt":"2019-10-25T00:36:27","slug":"easily-create-iot-edge-custom-modules-with-visual-studio-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/easily-create-iot-edge-custom-modules-with-visual-studio-code\/","title":{"rendered":"Easily Create IoT Edge custom modules with Visual Studio Code"},"content":{"rendered":"<p>At the recent Connect(); 2017 in November, we announced public preview of <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/iot-edge\/\">Azure IoT Edge<\/a>. Now you can bring the intelligence of the Cloud right to the IoT Edge as well as easily create and manage business logic for your devices. The new <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-edge\">Azure IoT Edge extension<\/a> for Visual Studio Code along with the updated <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-toolkit\">Azure IoT Toolkit extension<\/a> will make your IoT Edge developments a real pleasure, providing a set of functionalities including:<\/p>\n<ul>\n<li>Creating new IoT Edge projects<\/li>\n<li>Building and publishing IoT Edge modules<\/li>\n<li>Debugging IoT Edge modules locally<\/li>\n<li>Managing IoT Edge devices in IoT Hub<\/li>\n<li>Deploying IoT solutions to IoT Edge devices<\/li>\n<li>Stopping and restarting IoT Edge<\/li>\n<\/ul>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-edge\"><img decoding=\"async\" class=\"\" style=\"margin: 0px\" title=\"Azure IoT Edge Extension\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/clip_image0027.jpg\" alt=\"Azure IoT Edge Extension\" width=\"482\" height=\"174\" border=\"0\" \/><\/a><\/p>\n<h2>Get Started with IoT Edge in Visual Studio Code<\/h2>\n<p>First things first, let\u2019s start by answering the obvious question &#8211; What is IoT Edge? What can it do and how does it work? Azure IoT Edge moves cloud analytics and custom business logic to devices so that your organization can focus on business insights instead of data management. Enable your solution to truly scale by configuring your IoT software, deploying it to devices via standard containers, and monitoring it all from the cloud. Here is the <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-edge\/how-iot-edge-works\">Azure IoT Edge introduction page<\/a> where you can find more in details.<\/p>\n<h3>Create a simulated Edge Device<\/h3>\n<p>Azure IoT Edge enables you to perform analytics and data processing on your devices, instead of having to push all the data to the cloud. To achieve this, you need a device having <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-edge\/iot-edge-runtime\">IoT Edge runtime<\/a> installed to start with. Here are the tutorials about deploying Azure IoT Edge on a simulated device from end to end for both <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-edge\/tutorial-simulate-device-windows\">Windows<\/a> and <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-edge\/tutorial-simulate-device-linux\">Linux<\/a> operating environments.<\/p>\n<h3>Develop and deploy a C# IoT Edge module<\/h3>\n<p>Once you have the IoT Edge runtime deployed on your device (or simulator), you can then start working on <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-edge\/iot-edge-modules\">modules<\/a>. At the time we are writing this post, only C# is available for developing modules, but soon you will be able to develop them using C, Java, Node or Python as well. We have published a page talking about <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-edge\/tutorial-csharp-module\">develop and deploy a C# IoT Edge module to your simulated device using Visual Studio Code<\/a>, check it out first, then we&#8217;ll show you how to debug it in VS Code with the IoT Edge extension.<\/p>\n<h3>Debug your IoT Edge C# module<\/h3>\n<ol>\n<li>To start debugging, you will need to use the dockerfile.debug to rebuild your docker image and deploy your Edge solution again. This is to add debugging support and rebuild the Docker image through dockerfile.debug configurations.In Visual Studio Code explorer, select <b>Dockerfile.debug<\/b> and right-click to select <b>Build IoT Edge module Docker image<\/b>. Then containerize and publish your module image as usual. It&#8217;s recommended you use a local registry to host your images for debugging purposes if you are working on a Linux container.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/dockImageDebug.png\"><img decoding=\"async\" class=\"\" style=\"margin: 0px\" title=\"Select Docker file debug\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/dockImageDebug.png\" alt=\"Select Docker file debug\" width=\"650\" height=\"451\" border=\"0\" \/><\/a><\/li>\n<\/ol>\n<ol start=\"2\">\n<li>You can reuse the deployment.json file (click <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/iot-edge\/module-deployment-monitoring\">here <\/a>to know more about IoT Edge deployment) if you already have the desired modules and routes configured for your IoT Edge device. In command Palette (Ctrl+Shift+P), type and select Edge: Restart Edge to get your module started in debug version.<\/li>\n<li>Now you can setup the debug configuration. Visual Studio Code provides a configuration file launch.json that allows you to configure your own debugging environment (click <a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/debugging\">here <\/a>to read more). In this scenario, configure your launch.json file as follows:\n<ul>\n<li>If you don&#8217;t have a launch.json file yet, navigate to the VS Code debug window, press <b>F5<\/b> and select <b>IoT Edge (.Net Core)<\/b>. The launch.json file will be generated for you.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/1-add-config-new-launch-json.gif\"><img decoding=\"async\" class=\"\" style=\"margin: 0px\" title=\"Add new launch json file\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/1-add-config-new-launch-json.gif\" alt=\"Add new launch json file\" width=\"650\" height=\"444\" \/><\/a><\/li>\n<li>If the launch.json file already exists, open it in VS Code, click <b>Add Configuration&#8230;<\/b>, and select <b>Edge: Debug IoT Edge Module (.NET Core)<\/b>.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/1-add-config-existing-launch-json.gif\"><img decoding=\"async\" class=\"\" style=\"margin: 0px\" title=\"Add configuration to existing json file\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/1-add-config-existing-launch-json.gif\" alt=\"Add configuration to existing json file\" width=\"650\" height=\"455\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>In launch.json, navigate to the Debug IoT Edge Module (.NET Core) section and specify the &lt;container_name&gt;.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/2-update-container-name.gif\"><img decoding=\"async\" class=\"\" style=\"margin: 0px\" title=\"Update configuration name\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/2-update-container-name.gif\" alt=\"Update configuration name\" width=\"650\" height=\"455\" \/><\/a><\/li>\n<li>Navigate to Program.cs. Add breakpoints and press <b>F5<\/b> again. Then select the dotnet process to attach to.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/3-start-debugging.gif\"><img decoding=\"async\" class=\"\" title=\"Start debugging\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/3-start-debugging.gif\" alt=\"Start debugging\" width=\"650\" height=\"455\" \/><\/a><\/li>\n<li>In the Debug window, you can see the variables in the left panel.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-edge\">Azure IoT Edge extension<\/a> also supports developing, debugging and deploying Azure Function for IoT Edge. For more information, please visit <a href=\"https:\/\/aka.ms\/DevelopeAzureFunctionOnEdge\">here<\/a>.<\/p>\n<p><b>Try it out<\/b><\/p>\n<p>Now that you have learnt the basics about debugging an IoT Edge module with Visual Studio Code, go download <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=vsciot-vscode.azure-iot-edge\">the Edge extension<\/a> and create your first Module, then join <a href=\"https:\/\/gitter.im\/Microsoft\/vscode-azure-iot-edge\">Gitter <\/a>to let us know what you think or if you need help.<\/p>\n<table border=\"0\" width=\"600\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"150\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/Xinyi-Zhang.jpg\" width=\"180\" height=\"410\" \/><\/td>\n<td valign=\"top\" width=\"450\"><strong>Xinyi Zhang<\/strong>, Senior Engineering Manager, IoT Tools and Services<\/p>\n<p>Xinyi is a engineering manager working on IoT tools and services, focusing on providing great dev experience on IoT related tools.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>At the recent Connect(); 2017 in November, we announced public preview of Azure IoT Edge. Now you can bring the intelligence of the Cloud right to the IoT Edge as well as easily create and manage business logic for your devices. The new Azure IoT Edge extension for Visual Studio Code along with the updated [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":255385,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1085,4980,155],"tags":[237,242,1383,9,382,376,185,172,156,280],"class_list":["post-15876","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud","category-java","category-visual-studio","tag-net","tag-azure","tag-c","tag-debug","tag-iot","tag-java","tag-node-js","tag-python","tag-visual-studio-2017","tag-visual-studio-code"],"acf":[],"blog_post_summary":"<p>At the recent Connect(); 2017 in November, we announced public preview of Azure IoT Edge. Now you can bring the intelligence of the Cloud right to the IoT Edge as well as easily create and manage business logic for your devices. The new Azure IoT Edge extension for Visual Studio Code along with the updated [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/15876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=15876"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/15876\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/255385"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=15876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=15876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=15876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}