platform | device | language |
---|---|---|
debian, fedora, Linux, opensuse, raspbian, Ubuntu, windows, yocto |
any |
java |
- Introduction
- Step 1: Prerequisites
- Step 2: Prepare your Device
- Step 3: Build and Run the Sample
- Command Line Arguments
About this document
This document describes how to build and run the Java sample application. 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
- Computer with Git client installed and access to the azure-iot-sdk-java GitHub public repository.
- Setup your IoT hub
- Provision your device and get its credentials
- Make sure desktop is ready as per instructions given on Prepare your development environment.
If you have successfully prepared your development environment the IoT device SDK and all samples should be built and ready to use.
-
Start a new instance of the [Device Explorer][device-explorer], select or create a new device, obtain and note the connection string for the device, and begin monitoring under the Data tab.
-
Build the client library along with the samples :
{IoT device SDK root}/java/device/>mvn install -DskipTests
On build completion, you will see summary of what got built.
-
Navigate to the folder containing the executable JAR file for the sample that you wish to run and run the samples as follows:
For example, the executable JAR file for sending and receving event, send-receive-sample can be found at:
{IoT device SDK root}/java/device/samples/send-receive-sample/target/send-event-{version}-with-deps.jar
Navigate to the directory with the sample. Run the sample using the following command:
java -jar ./send-receive-sample-{version}-with-deps.jar "{connection string}" "{number of requests to send}" "{https or amqps or mqtt or amqps_ws }"
Note that the double quotes around each argument are required, but the braces '{' and '}' should be removed.
Samples would use following command line arguments:
- [Device connection string] -
HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>
You have now learned how to run a sample application that collects sensor data and sends it to your IoT hub. To explore how to store, analyze and visualize the data from this application in Azure using a variety of different services, please click on the following lessons:
- Manage cloud device messaging with iothub-explorer
- Save IoT Hub messages to Azure data storage
- Use Power BI to visualize real-time sensor data from Azure IoT Hub
- Use Azure Web Apps to visualize real-time sensor data from Azure IoT Hub
- Weather forecast using the sensor data from your IoT hub in Azure Machine Learning
- Remote monitoring and notifications with Logic Apps
2. [Number of requests to send]: For example, 5
-
[
https | amqps | mqtt | amqps_ws
]: For example, amqps_ws (AMQP over WebSocket) -
[Path to certificate to enable 1-way authentication]: For example,
azure-iot-sdk-c\tree\master\certs\ms.der
optional argument
Path to certificate is an optional argument and would be needed in case you want to point it to the local copy of the Server side certificate. Please note that this option is used by client for validating Root CA sent by Azure IoT Hub Server as part of TLS handshake. It is for 1-way TLS authentication and is not for specifying client side certificate (2-way TLS authentication).
To learn how to create a Java application that communicates with an IoT hub from scratch, see Get started with Azure IoT Hub for Java.
The documentation can be found here.