IoT Reference Implementation: How to Build an Environment Monitor Solution

Published on February 23, 2017

Translating...

This is a computer translation of the original content. It is provided for general information only and should not be relied upon as complete or accurate.

This guide demonstrates how existing IoT solutions can be adapted to address more complex problems (e.g., solutions that require more sensor monitoring). The solution we present here, an Environment Monitor, incorporates additional hardware and extends the use of IoT software libraries (sensors and I/O). Also, the solution has been adapted so the gateway can work with multiple operating systems.

The Environment Monitor solution, shown in Figure 1, is built using an Intel® NUC Kit DE3815TYKHE, an Arduino 101* (branded Genuino 101* outside the U.S.) board, and Grove* sensors available from Seeed Studio*. The solution runs on Ubuntu* Server with the Intel® System Studio IoT Edition IDE which creates the code to enable the sensors.

Figure 1. Adapted Environment Monitor Solution

The Intel® NUC acts as a gateway for the solution. The Intel® NUC provides plenty of compute power to function as a router, run higher-level services such as a web server, and to interact with other cloud services (AWS, MQTT, etc.). However it does not provide any I/O ports for interfacing directly with sensors. Hence, the Arduino 101* acts an edge device/sensor hub. Firmata*, a communication protocol, is used to control the Arduino 101 from the application running on the Intel® NUC. In turn, the gateway can be programmed using Intel® System Studio IoT Edition from the host computer.

This solution is built around MRAA (I/O library) and UPM (sensor library) from the Intel® IoT Developer Kit to interface with platform I/O and sensor data. In this case, the MRAA library provides an abstraction layer for the hardware to enable direct access to I/O on the Arduino 101 board using Firmata*. The UPM sensor library was developed on top of MRAA and exposes a user-friendly API that will allow the user to capture sensor data with just a few lines of code. Data is then sent periodically to Amazon Web Services (AWS)* using MQTT*.

The exercise in this document describes how to build the Environment Monitor solution.

Setup the System Hardware

This section describes how to set up all the required hardware for the Environment Monitor solution: the Intel® NUC Kit DE3815TYKHE, the Arduino 101 board, and Grove* sensors.

Intel® NUC Setup

Figure 2. Intel® NUC with bootable USB

Figure 3. Back of the Intel® NUC

Setting up the Intel® NUC for this solution consists of the following steps:

Follow the Intel® NUC DE3815TYKHE User Guide (available online here) and determine if additional components, such as system memory, need to be installed. Optionally, an internal drive and/or wireless card can be added.

Connect a monitor via the HDMI or VGA port and a USB keyboard. These are required for OS deployment and can be removed after the Intel® NUC has been connected to the network and a connection from the development environment has been established.

Plug in an Ethernet cable from your network’s router. This step can be omitted if a wireless network card has been installed instead.

Plug in the power supply for the Intel® NUC but DO NOT press the power button yet. First connect the Arduino 101 and other hardware components and then power on the Intel® NUC.

Note: The Intel® NUC provides a limited amount of internal eMMC storage (4 GB). Consider using an internal drive or a USB thumb drive to extend the storage capacity.

Arduino 101 Setup

In general, the Arduino 101 board will be ready to use out of the box without any additional changes. A USB Type A to Type B cable is required to connect the Arduino 101 to the Intel® NUC.

Note: here a green LED is used but any color LED (red, blue, etc.) can be used as an indicator.

Figure 4. Sensor connections to the Arduino 101

Figure 5. Sensors and pin connections

Install and Configure the Required Software

This section gives instructions for installation of the operating system and connecting the Intel® NUC to the Internet, installing required software libraries, and finally cloning the project sources from a GitHub* repository.

When you've created a bootable USB stick/drive (i.e., Ubuntu operating system has been downloaded onto the USB stick/drive), insert it into a USB port on the back of the Intel® NUC and then power on the gateway.

Choose to install Ubuntu from the menu.

Select to install ssh server when prompted during the Ubuntu installation.

Connecting the Intel® NUC to the Internet

This section describes how to connect the Intel® NUC to your network, which will enable you to deploy and run the project from a different host on the same network (i.e. your laptop). Internet access is required in order to download the additional software libraries and the project code.

The following steps list commands to be entered into a terminal (shell) on the Intel® NUC. You can connect to the Internet through an Ethernet cable or Wi-Fi*.

Ethernet

After Ubuntu is installed, restart the Intel® NUC and login with your user ID.

Type in the command ifconfig and locate the interface named enp3s0 (or eth0). Use the interface name for the next step.

Open the network interface file using the command: vim /etc/network/interfaces and type:

auto enp3s0
iface enp3s0 inet dhcp

Save and exit the file and restart the network service using:/etc/init.d/networking restart

Note: If you are connecting to external networks via a proxy, setting up a network connection is also required.

Wi-Fi (optional)

This is an optional step that only applies if a wireless card has been added to the Intel® NUC.

Once these are in place, check your Wi-Fi* interface name using ifconfig. This examples uses wlp2s0. Now run these commands:

Add the wifi interface to the interfaces file at: /etc/network/interfaces by adding the following lines:

auto wlp2s0iface wlp2s0 inet dhcp

Restart the networking service: /etc/init.d/networking restart

Run: nmcli networking and nmcli n connectivity and nmcli radio, these commands tell you whether the network is actually enabled or not, in case either of them days not enabled then you’ll have to enable full connectivity. For enabling radio use the following command: nmcli radio wifi on

Running nmcli c should show you the connection you have tried to connect to. In case you are trying to connect to an enterprise network, you might have to make changes to /etc/NetworkManager/system-connections/[network-name]

Now bring up the connection and the network interfaces:

nmcli con up [network-name]ifdown wlp2s0ifup wlp2s0

You can now use the Intel® NUC remotely from your development machine if you are on the same network.

Installing the MRAA and UPM libraries

In order to put UPM and MRAA on your system you can just use the MRAA:PPA to update the libraries. The instructions are as follows:

Plug in an Arduino 101* board and reboot the Intel® NUC. The Firmata* sketch is flashed onto the Arduino 101, you are ready to use MRAA and UPM. If you have an error, run the command imraa –a. If you are missing dfu-util then install it after setting the MRAA PPA to get the dfu that is included with MRAA.

Cloning the Git* repository

Clone the reference implementation repository with Git* on your development computer using:

Alternatively, you can download the repository as a .zip file. To do so, from your web browser (make sure you are signed in to your GitHub account) click the Clone or download button on the far right (green button in Figure 6 below). Once the .zip file is downloaded, unzip it, and then use the files in the directory for this example.

Figure 6

Create the Development and Runtime Environment

This section gives instructions for setting up the rest of the computing environment needed to support the Environment Monitor solution, including installation of Intel® System Studio IoT Edition, creating a project, and populating it with the files needed to build the solution.

Install Intel® System Studio IoT Edition

Intel® System Studio IoT Edition allows you to connect to, update, and program IoT projects on the Intel® NUC.

Windows Installation

Note: Some files in the archive have extended paths. We recommend using 7-Zip*, which supports extended path names, to extract the installer files.

Linux* Installation

Enter the command: tar -jxvf file to extract the tar.bz2 file, where file is the name of the installer file. For example, ss-iot-linux.tar.bz2. The command to enter may vary slightly depending on the name of your installer file.

Mac OS X® Installation

Enter the command: tar -jxvf file to extract the tar.bz2 file, where file is the name of the installer file. For example, tar -jxvf iss-iot-mac.tar.bz2. The command to enter may vary slightly depending on the name of your installer file.

Note: If you get a message "iss-iot-launcher can’t be opened because it is from an unidentified developer", right-click the file and select Open with. Select the Terminal app. In the dialog box that opens, click Open.

Launch Intel® System Studio IoT Edition

Navigate to the directory where you extracted the contents of the installer file.

Note: Using the iss-iot-launcher file (instead of the Intel® System Studio IoT Edition executable) will open Intel® System Studio IoT Edition with all the necessary environment settings. Use the iss-iot-launcher file to launch Intel® System Studio IoT Edition every time.

Add the Solution to Intel® System Studio IoT Edition

This section provides the steps to add the solution to Intel® System Studio IoT Edition, including creating a project and populating it with the files needed to build and run.

Open Intel® System Studio IoT Edition. When prompted, choose a workspace directory and click OK.

From the Intel® System Studio IoT Edition, select File | New | Create a new Intel Project for IoT. Then choose Intel® Gateway 64-Bit, as shown in Figure 7 and click next until you reach the Create or select the SSH target connection screen, as shown in Figure 8. Input IP address of the Intel® NUC (run command: ifconfig on the Intel® NUC if you don't know the IP address).

Figure 7. New Intel® IoT Project.Figure 8. Adding Target Connection.

Now give the project the name “Environment Monitor” and in the examples choose the “Air Quality Sensor” as the How To Code Sample (shown in Figure 9) and then click Next.

Figure 9. Adding Project Name.

The preceding steps will have created a How to Code Sample project. Now we have to do a couple of small things in order to convert this into Environment Monitor Project:

Copy over the air-quality-sensor.cpp and grovekit.hpp files from the git repository's src folder into the new project's src folder in Intel® System Studio IoT Edition. This will overwrite the local files.

Next right click on the project name and follow the sequence Right Click → C/C++ Build → Settings → IoT WRS 64-Bit G++ Linker → Libraries and then add the libraries as shown in the following screen shot. This can be done by clicking on the small green '+' icon on the top right side of the libraries view. The red 'x' next to green '+' icon deletes the libraries.

Figure 10. Adding libraries to the build path

In order to run this project, connect to the Intel® NUC first using the IP address (already provided). This can be done from the Target Selection View tab, but you can also right click on the target (gateway device) and choose the “Connect” option. Enter username/password for the Intel® NUC when prompted.

Note: Ensure the Intel® NUC and the laptop (running Intel® System Studio IoT Edition) are connected to the same network.

Setup and Connect to a Cloud Service

Amazon Web Services (AWS)*

This solution was designed to send sensor data using the MQTT* protocol to AWS*. In order to connect the application to a cloud service, first setup and create an account.

MQTT_SERVER - use the host value you obtained by running the aws iot describe-endpoint command, along with the ssl:// (for C++) or mqtts:// protocol (for JavaScript*)

MQTT_CLIENTID - use \<your device name\>

MQTT_TOPIC - use devices/ \<your device name\>

MQTT_CERT - use the filename of the device certificate as described above

MQTT_KEY - use the filename of the device key as described above

MQTT_CA - use the filename of the CA certificate (/etc/ssl/certs/VeriSign_Class_3_Public_Primary_Certification_Authority_-_G5.pem)

Additional Setup for C++ Projects

When running your C++ code on the Intel® NUC, set the MQTT* client parameters in Eclipse* as outlined in the steps below: Go to Run configurations and in the commands to execute before application field, type: