platform | device | language |
---|---|---|
Ubuntu |
IoT SCADA SERVER |
java |
# 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
You should have the following items ready before beginning the process:
- Prepare your development environment
- Setup your IoT hub
- Provision your device and get its credentials
- IoT SCADA SERVER device
The IoT SCADA SERVER is sold with a pre-installed Ubuntu based operating system.
## 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.
-
Install Java JDK 8
sudo apt-get update sudo apt-get install openjdk-8-jdk
-
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
.
-
Install GIT
sudo apt-get install git
-
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.