Skip to content

Latest commit

 

History

History
203 lines (123 loc) · 7.69 KB

Debian-meshlium-java.md

File metadata and controls

203 lines (123 loc) · 7.69 KB
platform device language
debian
meshlium
java

Run a simple JAVA sample on Meshlium device running Debian GNU/Linux 8


Table of Contents

# 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

Step 1: Prerequisites

You should have the following items ready before beginning the process:

Step 2: Prepare your Device

  • 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

Step 3: Build SDK and Run the sample

## 3.1 Install Azure IoT Device SDK and prerequisites on device
  • Install the prerequisite packages by issuing the following commands from the command line on the device.
### 3.1.1 Install Java JDK and set up environment variables
  1. 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

  2. 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
    
  3. 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
    
  4. 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, if which java output is /usr/bin/java, then export command will be export PATH=/usr/bin/java/bin:$PATH

  5. 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
    
  6. 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/.

  7. 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/

### 3.1.2 Install Maven and set up environment variables
  1. Install maven

    sudo apt-get install maven
    
  2. 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
    
  3. 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
    
  4. 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 if which mvn output is /usr/bin/mvn, export command will be export PATH=/usr/bin/mvn/bin:$PATH

  5. You can verify that the environment variables necessary to run Maven 3 have been set correctly by running mvn --version.

### 3.1.3 Install GIT
    sudo apt-get install git
### 3.1.4 Build Qpid JMS
  1. Clone the repository for Qpid JMS.

    git clone https://github.com/avranju/qpid-jms.git
    
  2. 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
    
### 3.1.5 Build the Azure IoT Device SDK for Java
  1. Download the SDK to the board by issuing the following command in PuTTY:

    git clone https://github.com/Azure/azure-iot-sdks.git
    
  2. Verify that you now have a copy of the source code under the directory azure-iot-sdks.

  3. 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
    
  4. 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
    
## 3.2 Run and Validate the Samples ### 3.2.1 Send Device Events to IoT Hub:
  • 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.

### 3.2.2 Receive messages from IoT Hub
  • 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.