Skip to content

Latest commit

 

History

History
125 lines (85 loc) · 6.96 KB

android-naougat-up-squared-java.md

File metadata and controls

125 lines (85 loc) · 6.96 KB
platform device language
android nougat (v7.1)
up-squared
java

Run a simple Java sample on UP-Squared device running Android Nougat (v7.1)


Table of Contents

Introduction

About this document

This document describes how to connect UP-Squared running Android Nougat (v7.1) 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:

  • Prepare your development environment:
    • Download and install latest JDK from here.
    • Download Android Studio on your Windows machine and follow the installation instructions.
  • 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
  • UP-Squared device.

Step 2: Prepare your Device

Step 3: Build and Validate the sample using Java client libraries

3.1 Prepare your development environment

  • Download and install latest JDK from here.

  • Download Android Studio on your Windows machine and follow the installation instructions.

  • Plug in your device to your development machine with a USB cable. If you're developing on Windows, you might need to install the appropriate USB driver for your device. For help installing drivers, see the OEM USB Drivers document.

  • Enable USB debugging on your device. On Android 4.0 and newer, go to Settings > Developer options.

    Note: On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.

3.2 Build the samples

  1. Start a new instance of Android Studio and open Android project from here:

    azure-iot-sdk-java/device/iot-device-samples/android-sample/

  2. Go to MainActivity.java, replace the [device connection string] placeholder with connection string of the device you have created in Provision your device and get its credentials and save the file. An example of IoT Hub Connection String is as below:

    HostName=[YourIoTHubName];SharedAccessKeyName=[YourAccessKeyName];SharedAccessKey=[YourAccessKey] Also replace the device ID with AAEON-UP-SQUARED-ANDROID device ID

  3. Build your project by going to Build menu > Make Project.

3.3 Run and Validate the Samples

In this section you will run the Azure IoT client SDK samples to validate communication between your device and Azure IoT Hub. You will send messages to the Azure IoT Hub service and validate that IoT Hub has successfully receive the data. You will also monitor any messages sent from the Azure IoT Hub to client.

3.3.1 Run the Sample:

Run on the Device

  • Select one of your project's files and click Run from the toolbar.

  • In the Choose Device window that appears, select the Choose a running device radio button, select AAEON-UP APL01 device, and click OK.

  • Android Studio will install the app on your connected device and starts it.

3.3.2 Send Device Events to IoT Hub:

  • See Manage IoT Hub to learn how to observe the messages IoT Hub receives from the application.
  • As soon as you run the app on your device, it will start sending messages to IoTHub.
  • Check the Android Monitor window in Android Studio. Verify that the confirmation messages show an OK. If not, then you may have incorrectly copied the device hub connection information.
  • use device explorer application in Azure Iot SDK to watch the sent messages

3.3.3 Receive messages from IoT Hub

  • See Manage IoT Hub to learn how to send cloud-to-device messages to the application.
  • Click the Receive Messages button from the sample App UI.
  • Check the Android Monitor window in Android Studio. You should be able to see the command received.
  • use device explorer application in Azure Iot SDK to watch the received messages

Next Steps

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: