platform | device | language |
---|---|---|
debian |
meshlium |
java |
# Introduction
About this document
This document describes how to connect Meshlium device running Debian GNU/Linux 8 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:
- Computer with GitHub installed and access to the azure-iot-sdks GitHub public repository.
- Meshlium device.
- Setup your IoT hub
- Provision your device and get its credentials
-
Open a PuTTY session and connect to the IP your Meshlium has assigned. If you are connected to the Meshlium WiFi Access Point, the IP will be 10.10.10.1. On the other hand, if you are connected to the Ethernet network, you will have to be able to identify the IP your Meshlium has assigned by DHCP in order to access to the Manager System. If your network does not offer DHCP service, Meshlium starts with a default IP (192.168.1.100)
-
The credentials are:
- user: root
- password: libelium
- Install the prerequisite packages by issuing the following commands from the command line on the device.
-
Install openjdk-8
sudo apt-get update sudo apt-get install openjdk-8-jdk
Note: If openjdk-8-jdk package is not available, use following steps to add source in sources.list and rerun above commands again.
-
Edit /etc/apt/sources.list
-
Add below line and save the changes.
deb http://ftp.debian.org/debian testing main
-
-
Update the PATH environment variable to include the full path to the bin folder containing Java. To ensure the correct path of Java run below command:
which java
-
Ensure that the directory shown by the
which java
command matches one of the directories shown in your $PATH variable. You can confirm this by running following command.echo $PATH
-
If Java path is missing in PATH environment variable, run following command to set the same.
export PATH=[PathToJava]/bin:$PATH
NOTE: Here [PathToJava] is output of
which java
command. For example, ifwhich java
output is /usr/bin/java, then export command will be export PATH=/usr/bin/java/bin:$PATH -
Make sure that the JAVA_HOME environment variable includes the full path to the JDK. Use below command to get the JDK path.
update-alternatives --config java
-
Take note of the JDK location.
update-alternatives
output will show something similar to /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java. The JDK directory would then be /usr/lib/jvm/java-8-openjdk-amd64/. -
Run the following command to set JAVA_HOME environment variable.
export JAVA_HOME=[PathToJDK]
Note: Here [PathToJDK] is JDK directory. For example if jdk directory is /usr/lib/jvm/java-8-openjdk-amd64/, export command will be export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
-
Install maven
sudo apt-get install maven
-
Update the PATH environment variable to include the full path to the bin folder containing maven. To ensure the correct path of maven, run below command:
which mvn
-
Ensure that the directory shown by the
which mvn
command matches one of the directories shown in your $PATH variable. You can confirm this by running following command.echo $PATH
-
If maven path is missing in PATH environment variable, run following command to set the same.
export PATH=[PathToMvn]/bin:$PATH
Note: Here [PathToMvn] is output of
which mvn
. For example ifwhich mvn
output is /usr/bin/mvn, export command will be export PATH=/usr/bin/mvn/bin:$PATH -
You can verify that the environment variables necessary to run Maven 3 have been set correctly by running
mvn --version
.
sudo apt-get install git
-
Clone the repository for Qpid JMS.
git clone https://github.com/avranju/qpid-jms.git
-
Install Qpid JMS by executing following commands in sequence:
cd qpid-jms mvn install | tee Qpid_Build_Logs.txt cd ..
Note: We have noticed that certain unit tests can fail when running
mvn install
as given above with the latest version of JDK 8 (1.8.0_60 at the time this document was written). It works fine with older versions however. If this occurs please skip running unit tests using following command:mvn install -DskipTests
-
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.
-
Run the following commands on device in sequence to build Azure IoT SDK.
cd azure-iot-sdks/java/device mvn install | tee JavaSDK_Build_Logs.txt
-
Above command will generate the compiled JAR files with all dependencies. This bundle can be found at:
azure-iot-sdks/java/device/iothub-java-client/target/iothub-java-client-{version}-with-deps.jar
-
Navigate to the folder containing the executable JAR file for send event sample.
cd azure-iot-sdks/java/device/samples/send-event/target
-
Run the sample by issuing following command.
java -jar ./send-event-{version}-with-deps.jar "{connection string}" "{number of requests to send}" "amqps"
Replace the following in above command:
{version}
: Version of binaries you have build{connection string}
: Your device connection string{number of requests to send}
: Number of messages you want to send to IoT Hub
-
See Manage IoT Hub to learn how to observe the messages IoT Hub receives from the application.
-
Navigate to the folder containing the executable JAR file for the receive message sample.
cd azure-iot-sdks/java/device/samples/handle-messages/target
-
Run the sample by issuing following command.
java -jar ./handle-messages-{version}-with-deps.jar "{connection string}" "amqps"
Replace the following in above command:
{version}
: Version of binaries you have build{connection string}
: Your device connection string{number of requests to send}
: Number of messages you want to send to IoT Hub
-
See Manage IoT Hub to learn how to send cloud-to-device messages to the application.