Skip to content

Latest commit

 

History

History
179 lines (107 loc) · 6.48 KB

ubuntu-IoT-scada-server-java.md

File metadata and controls

179 lines (107 loc) · 6.48 KB
platform device language
Ubuntu
IoT SCADA SERVER
java

Run a simple JAVA sample on IoT SCADA SERVER device running Ubuntu


Table of Contents

# Introduction

About this document

This document describes how to connect IoT SCADA SERVER device running Ubuntu 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

The IoT SCADA SERVER is sold with a pre-installed Ubuntu based operating system.

Step 3: Build SDK and Run the sample

## 3.1 Install Azure IoT Device SDK and prerequisites on device
  • Open a PuTTY session and connect to the 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 Java JDK 8

    sudo apt-get update        
    sudo apt-get install openjdk-8-jdk 
    
  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
  1. Install GIT

    sudo apt-get install git
    
### 3.1.4 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.