platform | device | language |
---|---|---|
linux |
mxe-202i |
nodejs |
About this document
This document describes how to connect MXE-202i device running Linux with Azure IoT SDK. This multi-step process includes:
- Configuring Azure IoT Hub
- Registering your IoT device
- Build and deploy Azure IoT SDK on device
You should have the following items ready before beginning the process:
- [Prepare your development environment][setup-devbox-linux]
- Setup your IoT hub
- Provision your device and get its credentials
- Follow the instructions from device website.
-
Open a PuTTY session and connect to the device.
-
Choose your commands in next steps based on the OS running on your device.
-
Run following command to check if NodeJS is already installed
node --version
If version is 0.12.x or greater, then skip next step of installing prerequisite packages. Else uninstall it by issuing following command from command line on the device.
sudo apt-get remove nodejs
-
Install the prerequisite packages by issuing the following commands from the command line on the device. Choose your commands based on the OS running on your device.
curl -sL https://deb.nodesource.com/setup_4.x | sudo bash - sudo apt-get install -y nodejs
Note: To test successful installation of Node JS, try to fetch its version information by running following command:
node --version
-
Download the SDK to the board by issuing the following command in PuTTY:
git clone https://github.com/Azure/azure-iot-sdks.git
-
Verify that you now have a copy of the source code under the directory ~/azure-iot-sdks.
-
To validate the source code run the following commands on the device.
cd ~/azure-iot-sdks/node build/dev-setup.sh build/build.sh | tee LogFile.txt
-
Edit the following file using any text editor of your choice:
cd ~/azure-iot-sdks/node/device/samples
For simple_sample_http.js:
simple_sample_http.js
For send_batch_http.js:
send_batch_http.js
-
Find the following place holder for IoT connection string:
var connectionString = "[IoT Device Connection String]";
-
Replace the above placeholder with device connection string you obtained in Step 1 and save the changes.
-
Run the following command before leaving the ~/azure-iot-sdks/node/device/samples directory
npm link azure-iot-device
-
Run the sample by issuing following command and verify that data has been successfully sent and received.
node ~/azure-iot-sdks/node/device/samples/simple_sample_http.js
-
Run the sample by issuing following command and verify that data has been successfully sent and received.
node ~/azure-iot-sdks/node/device/samples/send_batch_http.js
-
See Manage IoT Hub to learn how to observe the messages IoT Hub receives from the application.
-
Run the sample to register a device by issuing following command. Verify that you receive information for new device created in the messages.
node ~/azure-iot-sdks/node/service/samples/registry_sample.js
Note: The registry_sample.js sample will create and delete a device. In order to see it in the DeviceExplorer tool you will need to refresh your devices before the sample finishes running.
- See Manage IoT Hub to learn how to send cloud-to-device messages to the application.