-
Notifications
You must be signed in to change notification settings - Fork 3
IOT Team Set up your dev environment for IoT Edge and run a sample module
## Prerequisites:
Install Docker on your PC. You will need Windows Pro or Windows Education in order to do this. If you just have Windows 10 Home you will have to expect future errors.
Install Visual Studio Code on your PC: https://code.visualstudio.com/
## Begin with Visual Studio Code:
-
Once the installation of VS Code is finished, select View > Extensions.
-
Search for Azure IoT Tools, which is actually a collection of extensions that help you interact with IoT Hub and IoT devices, as well as developing IoT Edge modules.
-
Select Install. Each included extension installs individually.
-
When the extensions are done installing, open the command palette by selecting View > Command Palette.
-
In the command palette, search for and select Azure: Sign in. Follow the prompts to sign in to your Azure account.
-
In the command palette again, search for and select Azure IoT Hub: Select IoT Hub. Our Azure subscription is: TODDYSM DIRECTORY (LIVE). It will prompt you to select the Hub, ours is: IoT Hub
-
Open the explorer section of Visual Studio Code by selecting the top option in your left hand menu(It will look like 2 sheets of paper).
-
At the bottom of the explorer section, expand the collapsed Azure IoT Hub Devices menu. You should see the devices and IoT Edge devices associated with the IoT hub that you selected through the command palette.
## Creating Your Python Module:
Back in the command palette( Remember to get there you will click 'View'), search for and select Azure IoT Edge: New IoT Edge Solution. It will give you these prompts:
Select folder - Choose the location on your development machine for VS Code to create the solution files.
Provide a solution name - Choose your name or accept the default EdgeSolution.
Select module template - Choose **Python** Module.
Provide a module name - Choose your module name or accept the default SampleModule.
Provide Docker image repository for the module - We will not be using a container registry like it asks for. Your
container image is prepopulated from the name you provided in the last step (after the slash). Replace localhost:5000
with the name of your choice. We will be using a local repository. Note: If you do not change the 'localhost:5000', it
will exclude an important file when creating the module that you will need later. So, make sure this is changed.
## Select your target architecture This determines how your container builds and runs. Open the command palette and search for Azure IoT Edge: Set Default Target Platform for Edge Solution
I selected the default Linux AMD64, but will research this more to make sure it is the best option.
## Customize Your Python Module You now have a python module built. In order to customize it I simply used the code found here: https://docs.microsoft.com/en-us/azure/iot-edge/tutorial-python-module Youu do not need to follow the beginning steps as you have already done those. Simply change the code where it indicates. You can also modify the module by writing your own custom python code if you wish.
## Build and Push Full Disclosure: This is where you will run into trouble if you are not connected to docker. Before you move on that is something you will have to download. Also of note, there are some dependencies you will need that are not in the Microsoft documentation.
If you have docker but are not signed in you will need to do that: Open the VS Code integrated terminal by selecting View > Terminal.
Sign in to Docker by entering the following command in the terminal: docker login -u -p
To install dependencies you will need to: pip install iotedgehubdev
Also, IoT Edge Dev(this is a bit trickier):
If you need a point of reference here is a link to it's Github: https://github.com/Azure/iotedgedev
Make sure your docker has a Shared Drive setup. To do that go to your Settings in your Docker Desktop. It does not mention this in the Github Documentation, but after doing this I had to restart Docker. This is also in your Docker Settings. After restarting, it did not come on. If this happens to you, you can go into you powershell as an Administrator and run: docker run hello-world
After this I was able to install IOT Edge Dev:
mkdir c:\temp\iotedge docker run -ti -v /var/run/docker.sock:/var/run/docker.sock -v c:/temp/iotedge:/home/iotedge microsoft/iotedgedev
Now you are ready! In the VS Code explorer, right-click the deployment.template.json file and select Build and Push IoT Edge solution.
## Deploy Module to Device If you make it this far, and wish to keep going there is more documentation found here(It will be towards the bottom of the page and under Deploy Module to Device): https://docs.microsoft.com/en-us/azure/iot-edge/tutorial-python-module