Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Latest commit

 

History

History
382 lines (249 loc) · 17.2 KB

iot-suite-v1-gateway-kit-get-started-sensortag.md

File metadata and controls

382 lines (249 loc) · 17.2 KB
title description services suite documentationcenter author manager editor ms.service ms.devlang ms.topic ms.tgt_pltfrm ms.workload ms.date ms.author
Connect a gateway to Azure IoT Suite using an Intel NUC | Microsoft Docs
Use the Microsoft IoT Commercial Gateway Kit and the remote monitoring preconfigured solution. Use the Azure IoT Edge gateway to enable a SensorTag device to connect to the remote monitoring solution, send telemetry to the cloud, and respond to methods invoked from the solution dashboard.
iot-suite
dominicbetts
timlt
iot-suite
c
article
na
na
11/02/2017
dobett

Connect your Azure IoT Edge gateway to the remote monitoring preconfigured solution and send telemetry from a SensorTag

This tutorial shows you how to use Azure IoT Edge to send temperature and humidity data from SensorTag device to the remote monitoring preconfigured solution. The SensorTag connects to the Intel NUC gateway using Bluetooth. The tutorial uses:

  • Azure IoT Edge to implement a sample gateway.
  • The IoT Suite remote monitoring preconfigured solution as the cloud-based back end.

Overview

In this tutorial, you complete the following steps:

  • Deploy an instance of the remote monitoring preconfigured solution to your Azure subscription. This step automatically deploys and configures multiple Azure services.
  • Set up your Intel NUC gateway device to communicate with your computer and the remote monitoring solution.
  • Set up your Intel NUC gateway to receive telemetry from a SensorTag device and send it to the remote monitoring dashboard.

Prerequisites

To complete this tutorial, you need an active Azure subscription.

Note

If you don't have an account, you can create a free trial account in just a couple of minutes. For details, see Azure Free Trial.

Required software

You need SSH client on your desktop machine to enable you to remotely access the command line on the Intel NUC.

  • Windows does not include an SSH client. We recommend using PuTTY.
  • Most Linux distributions and Mac OS include the command-line SSH utility.

Required hardware

A desktop computer to enable you to connect remotely to the command line on the Intel NUC.

IoT Commercial Gateway Kit. This tutorial uses the following items from the kit:

  • Intel® NUC Kit DE3815TYKE with 4G Memory and Bluetooth expansion card
  • Power adaptor

Texas Instruments BLE SensorTag. This tutorial retrieves telemetry data over Bluetooth from the SensorTag device.

Provision the solution

If you haven't already provisioned the remote monitoring preconfigured solution in your account:

  1. Log on to azureiotsuite.com using your Azure account credentials, and click + to create a solution.
  2. Click Select on the Remote monitoring tile.
  3. Enter a Solution name for your remote monitoring preconfigured solution.
  4. Select the Region and Subscription you want to use to provision the solution.
  5. Click Create Solution to begin the provisioning process. This process typically takes several minutes to run.

Wait for the provisioning process to complete

  1. Click the tile for your solution with Provisioning status.
  2. Notice the Provisioning states as Azure services are deployed in your Azure subscription.
  3. Once provisioning completes, the status changes to Ready.
  4. Click the tile to see the details of your solution in the right-hand pane.

Note

If you are encountering issues deploying the pre-configured solution, review Permissions on the azureiotsuite.com site and the FAQ. If the issues persist, create a service ticket on the portal.

Are there details you'd expect to see that aren't listed for your solution? Give us feature suggestions on User Voice.

Warning

The remote monitoring solution provisions a set of Azure services in your Azure subscription. The deployment reflects a real enterprise architecture. To avoid unnecessary Azure consumption charges, delete your instance of the preconfigured solution at azureiotsuite.com when you have finished with it. If you need the preconfigured solution again, you can easily recreate it. For more information about reducing consumption while the remote monitoring solution runs, see Configuring Azure IoT Suite preconfigured solutions for demo purposes.

View the solution dashboard

The solution dashboard enables you to manage the deployed solution. For example, you can view telemetry, add devices, and invoke methods.

  1. When the provisioning is complete and the tile for your preconfigured solution indicates Ready, choose Launch to open your remote monitoring solution portal in a new tab.

    Launch the preconfigured solution

  2. By default, the solution portal shows the dashboard. Navigate to other areas of the solution portal using the menu on the left-hand side of the page.

    Remote monitoring preconfigured solution dashboard

Add a device

For a device to connect to the preconfigured solution, it must identify itself to IoT Hub using valid credentials. You can retrieve the device credentials from the solution dashboard. You include the device credentials in your client application later in this tutorial.

To add a device to your remote monitoring solution, complete the following steps in the solution dashboard:

  1. In the lower left-hand corner of the dashboard, click Add a device.

    Add a device

  2. In the Custom Device panel, click Add new.

    Add a custom device

  3. Choose Let me define my own Device ID. Enter a Device ID such as device01, click Check ID to verify you haven't already used the name in your solution, and then click Create to provision the device.

    Add device ID

  4. Make a note the device credentials (Device ID, IoT Hub Hostname, and Device Key). Your client application on the Intel NUC needs these values to connect to the remote monitoring solution. Then click Done.

    View device credentials

  5. Select your device in the device list in the solution dashboard. Then, in the Device Details panel, click Enable Device. The status of your device is now Running. The remote monitoring solution can now receive telemetry from your device and invoke methods on the device.

Prepare your Intel NUC

To complete the hardware setup, you need to:

  • Connect your Intel NUC to the power supply included in the kit.
  • Connect your Intel NUC to your network using an Ethernet cable.

You have now completed the hardware setup of your Intel NUC gateway device.

Sign in and access the terminal

You have two options to access a terminal environment on your Intel NUC:

  • If you have a keyboard and monitor connected to your Intel NUC, you can access the shell directly. The default credentials are username root and password root.

  • Access the shell on your Intel NUC using SSH from your desktop machine.

Sign in with SSH

To sign in with SSH, you need the IP address of your Intel NUC. If you have a keyboard and monitor connected to your Intel NUC, use the ifconfig command to find the IP address. Alternatively, connect to your router to list the addresses of devices on your network.

Sign in with username root and password root.

Optional: Share a folder on your Intel NUC

Optionally, you may want to share a folder on your Intel NUC with your desktop environment. Sharing a folder enables you to use your preferred desktop text editor (such as Visual Studio Code or Sublime Text) to edit files on your Intel NUC instead of using nano or vi.

To share a folder with Windows, configure a Samba server on the Intel NUC. Alternatively, use the SFTP server on the Intel NUC with an SFTP client on your desktop machine.

Configure Bluetooth connectivity

Configure Bluetooth on the Intel NUC to enable the SensorTag device to connect and send telemetry.

Find the MAC address of the SensorTag

  1. In the shell on the Intel NUC, run the following command to unblock the Bluetooth service:

    sudo rfkill unblock bluetooth
  2. Run the following commands to start the Bluetooth service on the Intel NUC and enter the Bluetooth shell:

    sudo systemctl start bluetooth
    bluetoothctl
  3. Run the following command to power on the Bluetooth controller:

    power on

    When the controller is on, you see a message Changing power on succeeded.

  4. Run the following command to scan for nearby Bluetooth devices:

    scan on
  5. Press the power button on the SensorTag to make it discoverable. The green LED flashes.

  6. When you see a message in the shell that the controller has discovered the SensorTag, make a note of the MAC address of the device. The MAC address looks like A0:E6:F8:B5:F6:00. You need the MAC address later in the tutorial when you configure the gateway.

  7. Run the following command to turn off Bluetooth scanning:

    scan off
  8. Run the following command to verify that you can connect to the SensorTag device:

    connect <SensorTag MAC address>

    If you connect successfully, the shell shows the message Connection successful and prints information about the SensorTag device. If you cannot connect, check the SensorTag is still powered on.

  9. You can now disconnect from the SensorTag and exit the Bluetooth shell by running the following commands:

    disconnect
    exit

Build IoT Edge

This tutorial uses custom IoT Edge modules to communicate with the remote monitoring preconfigured solution. Therefore, you need to build the IoT Edge modules from custom source code. The following sections describe how to install IoT Edge and build the custom IoT Edge module.

Install IoT Edge

The following steps describe how to install the pre-compiled IoT Edge software on the Intel NUC:

  1. Configure the required smart package repositories by running the following commands on the Intel NUC:

    smart channel --add IoT_Cloud type=rpm-md name="IoT_Cloud" baseurl=http://iotdk.intel.com/repos/iot-cloud/wrlinux7/rcpl13/ -y
    smart channel --add WR_Repo type=rpm-md baseurl=https://distro.windriver.com/release/idp-3-xt/public_feeds/WR-IDP-3-XT-Intel-Baytrail-public-repo/RCPL13/corei7_64/

    Enter y when the command prompts you to Include this channel?.

  2. Update the smart package manager by running the following command:

    smart update
  3. Install the Azure IoT Edge package by running the following command:

    smart config --set rpm-check-signatures=false
    smart install packagegroup-cloud-azure -y
  4. Verify the installation by running the "Hello world" sample. This sample writes a hello world message to the log.txT file every five seconds. The following commands run the "Hello world" sample:

    cd /usr/share/azureiotgatewaysdk/samples/hello_world/
    ./hello_world hello_world.json

    Ignore any invalid argument messages when you stop the sample.

    Use the following command to view the contents of the log file:

    cat log.txt | more

Troubleshooting

If you receive the error "No package provides util-linux-dev", try rebooting the Intel NUC.

Build the custom IoT Edge module

You can now build the custom IoT Edge module that enables the gateway to send messages to the remote monitoring solution. For more information about configuring a gateway and IoT Edge modules, see Azure IoT Edge concepts.

Download the source code for the custom IoT Edge modules from GitHub using the following commands:

cd ~
git clone https://github.com/Azure-Samples/iot-remote-monitoring-c-intel-nuc-gateway-getting-started.git

Build the custom IoT Edge module using the following commands:

cd ~/iot-remote-monitoring-c-intel-nuc-gateway-getting-started/basic
chmod u+x build.sh
sed -i -e 's/\r$//' build.sh
./build.sh

The build script places the libsensor2remotemonitoring.so custom IoT Edge module in the build folder.

Configure and run the IoT Edge gateway

You can now configure the IoT Edge gateway to send telemetry from your SensorTag device to your remote monitoring dashboard. For more information about configuring a gateway and IoT Edge modules, see Azure IoT Edge concepts.

Tip

In this tutorial, you use the standard vi text editor on the Intel NUC. If you have not used vi before, you should complete an introductory tutorial, such as Unix - The vi Editor Tutorial to familiarize yourself with this editor. Alternatively, you can install the more user-friendly nano editor using the command smart install nano -y.

Open the sample configuration file in the vi editor using the following command:

vi ~/iot-remote-monitoring-c-intel-nuc-gateway-getting-started/basic/remote_monitoring.json

Locate the following lines in the configuration for the IoTHub module:

"args": {
  "IoTHubName": "<<Azure IoT Hub Name>>",
  "IoTHubSuffix": "<<Azure IoT Hub Suffix>>",
  "Transport": "http"
}

Replace the placeholder values with the IoT Hub information you created and saved at the start of this tutorial. The value for IoTHubName looks like yourrmsolution37e08, and the value for IoTSuffix is typically azure-devices.net.

Locate the following lines in the configuration for the mapping module:

args": [
  {
    "macAddress": "<<AA:BB:CC:DD:EE:FF>>",
    "deviceId": "<<Azure IoT Hub Device ID>>",
    "deviceKey": "<<Azure IoT Hub Device Key>>"
  }
]

Replace the macAddress placeholder with the MAC address of your SensorTag you noted previously. Replace the deviceID and deviceKey placeholders with the IDs and keys for the two devices you created in the remote monitoring solution previously.

Locate the following lines in the configuration for the SensorTag module:

"args": {
  "controller_index": 0,
  "device_mac_address": "<<AA:BB:CC:DD:EE:FF>>",
  ...
}

Replace the device_mac_address placeholder with the MAC address of your SensorTag you noted previously.

Save your changes.

You can now run the gateway using the following commands:

cd ~/iot-remote-monitoring-c-intel-nuc-gateway-getting-started/basic
/usr/share/azureiotgatewaysdk/samples/ble_gateway/ble_gateway remote_monitoring.json

The IoT Edge gateway starts on the Intel NUC and sends telemetry from the SensorTag to the remote monitoring solution:

IoT Edge gateway sends telemetry from the SensorTag

Press Ctrl-C to exit the program at any time.

View the telemetry

The gateway is now sending telemetry from the SensorTag device to the remote monitoring solution. You can view the telemetry on the solution dashboard. You can also send commands to your SensorTag device through the gateway from the solution dashboard.

  • Navigate to the solution dashboard.
  • Select the device you configured in the gateway that represents the SensorTag in the Device to View dropdown.
  • The telemetry from the SensorTag device displays on the dashboard.

Display telemetry from the SensorTag devices

Warning

If you leave the remote monitoring solution running in your Azure account, you are billed for the time it runs. For more information about reducing consumption while the remote monitoring solution runs, see Configuring Azure IoT Suite preconfigured solutions for demo purposes. Delete the preconfigured solution from your Azure account when you have finished using it.

Next steps

Visit the Azure IoT Dev Center for more samples and documentation on Azure IoT.