|
| 1 | +--- |
| 2 | +platform: custom linux |
| 3 | +device: vt-m2m-qk |
| 4 | +language: python |
| 5 | +--- |
| 6 | + |
| 7 | +Run a simple PYTHON sample on VT-M2M-QK device running Custom Linux |
| 8 | +=== |
| 9 | +--- |
| 10 | + |
| 11 | +# Table of Contents |
| 12 | + |
| 13 | +- [Introduction](#Introduction) |
| 14 | +- [Step 1: Prerequisites](#Prerequisites) |
| 15 | +- [Step 2: Prepare your Device](#PrepareDevice) |
| 16 | +- [Step 3: Build and Run the Sample](#Build) |
| 17 | + |
| 18 | +<a name="Introduction"></a> |
| 19 | +# Introduction |
| 20 | + |
| 21 | +**About this document** |
| 22 | + |
| 23 | +This document describes how to connect VT-M2M-QK device running Custom Linux with Azure IoT SDK. This multi-step process includes: |
| 24 | +- Configuring Azure IoT Hub |
| 25 | +- Registering your IoT device |
| 26 | +- Build and deploy Azure IoT SDK on device |
| 27 | + |
| 28 | +<a name="Prerequisites"></a> |
| 29 | +# Step 1: Prerequisites |
| 30 | + |
| 31 | +You should have the following items ready before beginning the process: |
| 32 | + |
| 33 | +- [Prepare your development environment][setup-devbox-python] |
| 34 | +- [Setup your IoT hub][lnk-setup-iot-hub] |
| 35 | +- [Provision your device and get its credentials][lnk-manage-iot-hub] |
| 36 | +- VT-M2M-QK device |
| 37 | + |
| 38 | +<a name="PrepareDevice"></a> |
| 39 | +# Step 2: Prepare your Device |
| 40 | + |
| 41 | +The URL for the device is <http://vantrontech.com/hardwares/VT-M2M-QK.htm> |
| 42 | + |
| 43 | +The Python module builds on the Azure IoT device SDK for C. Please make sure you can build the C samples as described in [setup-devbox] before you continue in this section. |
| 44 | + |
| 45 | +The Python iothub_client supports python versions 2.7.x, 3.4.x or 3.5.x. Know the appropriate version you would like to build the library with for the following instructions. |
| 46 | + |
| 47 | + 1. Ensure that the desired Python version (2.7.x, 3.4 or 3.5.x) is installed and active. Run `python --version` or `python3 --version` at the command line to check the version. |
| 48 | + 2. Open a shell and navigate to the folder **python/build_all/linux** in your local copy of the repository. |
| 49 | + 3. Run the `./setup.sh` script to install the prerequisite packages and the dependent libraries. |
| 50 | + * Setup will default to python 2.7 |
| 51 | + * To setup dependencies for python 3.4 or 3.5, run `./setup.sh --python-version 3.4` or `./setup.sh --python-version 3.5` respectively |
| 52 | + 4. Run the `./build.sh` script. |
| 53 | + * Build will default to python 2.7 |
| 54 | + * To build with python 3.4 or 3.5, run `./build.sh --build-python 3.4` or `./build.sh --build-python 3.5` respectively |
| 55 | + |
| 56 | + |
| 57 | +<a name="Build"></a> |
| 58 | +# Step 3: Build and Run the sample |
| 59 | +## 3.1 Build SDK and sample |
| 60 | + |
| 61 | +- Open a XShell session and connect to the device. |
| 62 | + |
| 63 | +- Install the prerequisite packages for the Microsoft Azure IoT Device SDK for Python by issuing the following commands from the command line on your board: |
| 64 | + |
| 65 | + sudo apt-get update |
| 66 | + |
| 67 | + sudo apt-get install -y curl libcurl4-openssl-dev build-essential cmake git python2.7-dev libboost-python-dev |
| 68 | + |
| 69 | +- Download the Microsoft Azure IoT Device SDK to the board by issuing the following command on the board:: |
| 70 | + |
| 71 | + git clone --recursive https://github.com/Azure/azure-iot-sdks.git |
| 72 | + |
| 73 | +- Run following commands to build the SDK: |
| 74 | + |
| 75 | + cd python/build_all/linux |
| 76 | + sudo ./build.sh |
| 77 | + |
| 78 | +- After a successful build, the `iothub_client.so` Python extension module is copied to the **python/device/samples** folder. |
| 79 | + |
| 80 | +- Navigate to samples folder by executing following command: |
| 81 | + |
| 82 | + cd azure-iot-sdks/python/device/samples/ |
| 83 | + |
| 84 | +- Edit the following file using any text editor of your choice: |
| 85 | + |
| 86 | + nano iothub_client_sample.py |
| 87 | + |
| 88 | +- Find the following place holder for device connection string: |
| 89 | + |
| 90 | + connection_string = "[device connection string]" |
| 91 | + |
| 92 | +- Replace the above placeholder with device connection string you obtained in [Step 1](#Prerequisites) and save the changes. |
| 93 | + |
| 94 | +## 3.2 Send Device Events to IoT Hub: |
| 95 | + |
| 96 | +- Run the sample application using the following command: |
| 97 | + |
| 98 | + python iothub_client_sample.py -p mqtt |
| 99 | + |
| 100 | +- See [Manage IoT Hub][lnk-manage-iot-hub] to learn how to observe the messages IoT Hub receives from the application. |
| 101 | + |
| 102 | +## 3.3 Receive messages from IoT Hub |
| 103 | + |
| 104 | +- See [Manage IoT Hub][lnk-manage-iot-hub] to learn how to send cloud-to-device messages to the application. |
| 105 | + |
| 106 | +[setup-devbox-python]: https://github.com/Azure/azure-iot-sdks/blob/master/doc/get_started/python-devbox-setup.md |
| 107 | +[lnk-setup-iot-hub]: ../../setup_iothub.md |
| 108 | +[lnk-manage-iot-hub]: ../../manage_iot_hub.md |
0 commit comments