This Internet of Things (IoT) path-to-product project is part of a series of articles that portray how to develop a commercial IoT solution from the initial idea stage, through prototyping and refinement, to create a viable product. It uses the Grove* IoT Commercial Developer Kit, with the prototype built on an Intel® Next Unit of Computing (NUC) Kit DE3815TYKHE small-form-factor PC and Arduino* 101 board.
This document demonstrates how to build a prototype and utilize these same technologies in deploying an Intel IoT Gateway and industrial sensors. It does not require special equipment or deep expertise, and as such, it is intended to be instructive toward developing generalized prototyping phases for IoT projects.
Note: Known in the US as “Arduino* 101,” this board is known elsewhere as “Genuino* 101.” It is referred to throughout the rest of this document as the “Arduino 101” board.
This article contains a how to on building an Intelligent Vending Machine Prototype. To see the making of, see IoT Path-to-Product: The Making of an Intelligent Vending Machine.
Visit GitHub for this project's latest code samples and documentation.
Introduction
The completed intelligent vending machine is shown in Figure 1. From this exercise, developers will learn to do the following:
- Connect to the Intel NUC Kit DE3815TYKHE.
- Interface with the IO and sensor repository for the NUC using MRAA and UPM from the Intel® IoT Developer Kit, a complete hardware and software solution to help developers explore IoT and implement innovative projects.
- Run this code sample in Intel® System Studio, an IDE for creating applications that interact with sensors and actuators, enabling a quick start for developing software for Intel IoT platforms.
- Set up and connect to cloud services using the Microsoft Azure* platform, which provides cloud analytics and a communications hub for various parts of the solution.
What it does
This project enables you to simulate the following functionality of an intelligent vending machine:
- Vend multiple products
- Track inventory levels of products in the vending machine
- Send alerts when the inventory levels fall below a preset threshold
- Identify power start-up and malfunctions
- Notify when the vending machine door is open
- Display coil status
- Monitor and send alerts on internal temperature of the machine
- Provide a visual log of past maintenance, inventory, and events
- Provide a companion app for purchasing products
How it works
This intelligent vending machine prototype utilizes sensors to trigger a variety of different actions:
- Buttons simulate the selection of specific products from the vending machine
- Stepper motor turns to dispense product
- Red and green LEDs indicate failure and OK status
- Temperature sensor monitors interior of vending machine
- LCD displays vending machine status
All data flows occur through the cloud as an intermediary. For example, if a customer selects a product using the mobile application, the selection is passed to the cloud and then to the vending machine itself. This approach enables inventory levels to be maintained in the cloud.
Similarly, data related to product offerings, pricing, and maintenance events are centrally managed in the cloud, enabling comprehensive trend analysis and reporting. Maintenance alerts, for example, can also be sent to service personnel as well as updating the administration application for tracking purposes. Note that while the potential for these capabilities is considered within the design of the intelligent vending machine prototype, they are not implemented as part of this demo.
Set up the Intel NUC Kit DE3815TYKHE
This section gives instructions for installing the Intel® IoT Gateway Software Suite on the NUC.
Note: If you have acquired a Grove IoT Commercial Developer Kit, the Intel IoT Gateway Software Suite is already pre-installed on the NUC.
- Create an account on the Intel® IoT Platform Marketplace if you do not already have one.
- Download the Intel IoT Gateway Software Suite and follow the instructions received by email to download the image file.
- Unzip the archive and write the .img file to a 4GB USB drive.
On Microsoft Windows*, you can use a tool like Win32 Disk Imager*: https://sourceforge.net/projects/win32diskimager.
On Linux*, usesudo dd if=GatewayOS.img of=/dev/sdX bs=4M; sync
, wheresdX
is your USB drive. - Unplug the USB drive from your system and plug it into the NUC, along with a monitor, keyboard, and power cable.
- Turn on the NUC and enter the BIOS by pressing F2 at boot time.
- Boot from the USB drive, as follows:
a. From the Advanced menu, select Boot.
b. From Boot Configuration, under OS Selection, select Linux.
c. Under Boot Devices, make sure the USB check box is selected.
d. Save the changes and reboot.
e. Press F10 to enter the boot selection menu and select the USB drive. - Log in to the system with root:root.
- Install Wind River Linux on local storage with the following command:
~# deploytool -d /dev/mmcblk0 --lvm 0 --reset-media –F
Note: Due to the limited size of the local storage drive, we recommend against setting a recovery partition. You can return to the factory image by using the USB drive again.
- Use the
poweroff
command to shut down your gateway. Then, unplug the USB drive, and turn the gateway back on to boot from the local storage device. - Plug in an Ethernet cable and use the command
ifconfig eth0
to find the IP address assigned to your gateway (assuming you have a proper network setup).
You can now use your gateway remotely from your development machine if you are on the same network as the gateway. If you would like to use the Intel® IoT Gateway Developer Hub instead of the command line, enter the IP address into your browser and go through the first-time setup. - Use the Intel® IoT Gateway Developer Hub to update the MRAA and UPM repositories to the latest versions from the official repository (https://01.org). You can achieve the same result by entering these commands:
~# smart update ~# smart upgrade ~# smart install upm
- Use the following commands to install Java* 8 support (after executing the previous commands). These remove the precompiled OpenJDK* 7 and install OpenJDK* 8 , which works with MRAA and UPM:
~# smart remove openjdk-bin ~# smart install openjdk-8-jre
- Plug in an Arduino 101 board and reboot the NUC. The Firmata* sketch is flashed onto the Arduino 101, and you are now ready to use MRAA and UPM with it.
Set up the Arduino* 101 board
Setup instructions for the Arduino* 101 board are available at https://www.arduino.cc/en/Guide/Arduino101.
Connect other components
This section covers making the connections from the NUC to the rest of the hardware components. The bill of materials for the prototype is summarized in Table 1, and the assembly of those components is illustrated in Figure 2.
Table 1. Intelligent vending machine prototype components.
Component | Details | |
---|---|---|
Base System | Intel® NUC Kit DE3815TYKHE | |
Arduino* 101 Board | ||
USB Type A to Type B Cable | For connecting Arduino 101 board to NUC | |
Components from Grove* Starter Kit Plus IoT Edition | Base Shield V2 | |
Gear Stepper Motor with Driver | http://www.seeedstudio.com/depot/Gear-Stepper-Motor-with-Driver-p-1685.html | |
Button Module | ||
Temperature Sensor Module | http://www.seeedstudio.com/depot/Grove-Temperature-Sensor-p-774.html | |
Green LED | ||
Red LED | ||
Touch | http://www.seeedstudio.com/depot/Grove-Touch-Sensor-p-747.html | |
LCD with RGB Backlight Module | http://www.seeedstudio.com/depot/Grove-LCD-RGB-Backlight-p-1643.html |
Install Intel® System Studio
Intel® System Studio is a plug-in for Eclipse* that allows you to connect to, update, and program IoT projects on an Intel NUC or other compatible board. It helps you write applications in C, C++, and Java languages and provides two libraries, specially designed for the Intel® IoT Developer Kit:
MRAA is a low-level library that offers a translation from the input/output interfaces to the pins available on your IoT board.
UPM is a sensor library with multiple language support that utilizes MRAA. UPM allows you to conveniently use or create sensor representations for your projects.
Install on Windows*
Note: 7-Zip* supports extended path names, which some files in the compressed file have, so use only 7-Zip software to extract the installer file.
- Download the 7-Zip software from http://www.7-zip.org/download.html.
- Right-click on the downloaded executable and select Run as administrator.
- Click Next and follow the instructions in the installation wizard to install the application.
- Using 7-Zip, extract the installer file.
Warning: Be sure to extract the installer file to a folder location that does not include any spaces in the path name. For example, the folder C:\My Documents\ISS will not work, while C:\Document\ISS will.
Install on Linux*
- Download the Intel® System Studio installer file for Linux*.
- Open a new Terminal window.
- Navigate to the directory that contains the installer file.
- Enter the command:
tar -jxvf file
to extract the tar.bz2 file, wherefile
is the name of the installer file. For example,tar -jxvf iss-iot-linux.tar.bz2
. The command to enter may vary slightly depending on the name of your installer file.
Install on Mac* OS X*
- Download the Intel System Studio installer file for Mac* OS X*.
- Open a new Terminal window.
- Navigate to the directory that contains the installer file.
- Enter the command:
tar -jxvf file
to extract the tar.bz2 file, wherefile
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 see a message that says "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
- Navigate to the directory you extracted the contents of the installer file to.
- Launch Intel System Studio as follows:
- On Windows*, double-click iss-iot-launcher.bat to launch Intel System Studio.
- On Linux*, run iss-iot-launcher.sh.
- On Mac* OS X*, run iss-iot-launcher.
Note: Using the iss-iot-launcher file (instead of the Intel® System Studio executable) will launch Intel System Studio with all the necessary environment settings. Use the iss-iot-launcher file to launch Intel® System Studio every time.
Install Microsoft* Azure* components
The Azure* cloud maintains information about product inventory on intelligent vending machines in the network, keeps track of the events received from vending machines, and could provide future functionality to analyze this data and trigger responses to various conditions (e.g., low inventory or mechanical failure).
Implement the Azure* C++ API
Connecting to Azure* using the C++ API requires compilation of all the following libraries to build the Casablanca project:
- Boost:http://www.boost.org/doc/libs/1_59_0/more/getting_started/index.html
- GlibMM: http://ftp.gnome.org/pub/GNOME/sources/glibmm/2.40/
- SigC++: http://ftp.gnome.org/pub/GNOME/sources/libsigc++/2.5/
- XML++: http://ftp.gnome.org/pub/GNOME/sources/libxml++/2.37/ (Installed older version - dependency glib 2.40 or less)
- util-linux: https://www.kernel.org/pub/linux/utils/util-linux/v2.25/ (Required for uuid)
- Casablanca: https://casablanca.codeplex.com/wikipage?title=Setup%20and%20Build%20on%20Linux&referringTitle=Documentation
- Azure CPP SDK:https://github.com/Azure/azure-storage-cpp
Create a web app in Azure*
- Create an Azure* account. See https://azure.microsoft.com/en-us/documentation/articles/storage-create-storage-account/.
- Create Azure* App service. See https://tryappservice.azure.com/. Click on Web app | Next | Empty site | Create.
- Create Azure* table storage. See https://azure.microsoft.com/en-us/documentation/articles/storage-nodejs-how-to-use-table-storage/.
- To view the tables in the UI, use Azure* storage explorer. See https://azurestorageexplorer.codeplex.com/.
Compile Boost
wget -O boost_1_58_0.tar.gz ‘http://downloads.sourceforge.net/project/boost/boost/1.58.0/boost_1_58_0.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F1.58.0%2F&ts=1438814166&use_mirror=iweb’ tar czvf boost_1_58_0.tar.gz cd boost_1_58_0 ./bootstrap.sh ./b2
Compile Casablanca
Clone Casablanca:
git clone https://git.codeplex.com/casablanca
https://github.com/Microsoft/cpprestsdk
Compile Casablanca:
https://casablanca.codeplex.com/wikipage?title=Setup%20and%20Build%20on%20Linux&referringTitle=Documentation git clone https://github.com/Azure/azure-storage-cpp.git
https://github.com/Azure/azure-storage-cpp.git
SQLite3 installation and table initialization
SQLite3 IPK package installation:
root@galileo:~# opkg install sqlite3 Installing sqlite3 (3:3.8.6.0-r0.0) on root. Downloading http://iotdk.intel.com/repos/1.5/iotdk/i586/sqlite3_3.8.6.0-r0.0_i586.ipk. Configuring sqlite3.
Products database creation and initialization:
root@galileo:~# sqlite3 Vending_Prototype/products.sqlite3 SQLite version 3.8.6 2014-08-15 11:46:33 Enter ".help" for usage hints. sqlite> create table products(name varchar(255) primary key, price smallint, quantity smallint); sqlite> insert into products values('Coke',150,2); sqlite> insert into products values('Pepsi',130,3);
Events database creation and initialization:
root@galileo:~# sqlite3 Vending_Prototype/events.sqlite3 SQLite version 3.8.6 2014-08-15 11:46:33 Enter ".help" for usage hints. sqlite> sqlite> create table events(time INT, type smallint, key varchar(255), value smallint);
SQLite3 Node.js package installation:
npm install sqlite3
Azure* installation
npm install azure-storage
Conclusion
As this how-to document demonstrates, IoT developers can build prototypes with gateway, administrative, mobile, and cloud software functionality at relatively low cost and without specialized skill sets. Using the Grove* IoT Commercial Developer Kit and an Arduino* 101 board, project teams can conduct rapid prototyping to test the viability of IoT concepts as part of the larger path-to-product process.