This guide demonstrates a rapid path-to-product IoT solution for retail using cloud data analytics. This proof of concept was created using the UP Squared* Grove* IoT Development Kit that was scaled to an industrial solution using an UP²* board, industrial sensors, Intel® System Studio, and Microsoft Azure* cloud services. This solution monitors the inventory, product sales, and maintenance of a vending machine.
The intelligent vending machine solution uses sensors connected to the UP Squared board, sample code, and the Intel® System Studio running on a Linux* operating system. The development and runtime environment is setup using Linux* and Intel® System Studio on a desktop or laptop. Events are monitored to see whether the intelligent vending machine was opened or closed. The temperature is read using the temperature sensor and events are sent based on temperature status (too high, too low or returned to normal). The sample code includes enabling the stepper motor, setting the speed for the motor and dispensing the product. The LCD display writes out to the screen when the product is being dispensed.
-
UP Squared* board with Grove* Pi+
-
LCD Display
-
Sensors
- Stepper Motor
- Temperature Sensor
- Red LED
- Green LED
- Touch Sensor
- Button
- Stepper Driver
-
HDMI* or VGA port
-
USB Keyboard
-
Ethernet Cable
-
Ubuntu* 16.04
-
Intel® System Studio
-
Node.js
-
MongoDB*
-
Compass
This section describes how to set up all the required hardware for the Intelligent Vending Machine: UP Squared* and Grove Sensors.
Setting up the UP² board for this solution consists of the following steps:
- 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 UP² board 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.
- Plug in the power supply for the UP² board but DO NOT press the power button yet. First connect the GrovePi and other hardware components and then power on the UP² board.
- Connect GrovePi+ board to the UP² board.
- Connect sensors to the GrovePi+ board in the following manner:
-
Jhd1313m1 LCD display -> I2C pin
-
Button -> D7 Pin
-
Touch Sensor -> D8 Pin
-
Green Led Light -> D3 Pin
-
Red Led Light -> D2 Pin
-
Temperature sensor -> A0 Pin
-
Stepper Driver -> IN1 -> 11
-
IN2 -> 15
-
IN3 -> 16
-
IN4 -> 18
-
GND -> GND
-
VCC -> 5V
-
Stepper Motor -> Stepper Driver
This section gives instructions for: installation of the operating system, connecting the UP² board to the Internet, installing required software libraries, and finally cloning the project sources from a GitHub* repository.
The UP Squared board comes with a preinstalled version of the Ubuntu* 16.04 operating system. Follow the instructions here to install Ubuntu on a UP² board, if not already installed.
This section describes how to connect the UP² board 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 sections describe the commands that need to be entered into a terminal (shell) on the UP² board:
-
Once Ubuntu is installed, restart the UP² board and login using your user account.
-
Type in the command
ifconfig
and find the interface namedenp3s0
in the list. In some cases, this might show up aseth0
instead. Use the name displayed here for the following step. -
Open the network interface file using the command:
vim /etc/network/interfaces
and the following lines to it:auto enp3s0 iface enp3s0 inet dhcp
-
Save and exit the file and restart the network service using the following command:
/etc/init.d/networking restart
. -
If you are connecting to external networks via a proxy, you will need to set it up as well.
In order to put UPM and MRAA on your system, you can just use MRAA:PPA to update the libraries. The instructions are as follows:
sudo add-apt-repository ppa:mraa/mraa
sudo apt-get update
sudo apt-get install libupm-dev libupm-java python-upm python3-upm node-upm upm-examples
sudo apt-get install sqlite3 libsqlite3-dev
Note: Now we can disconnect monitor and keyboard from UP² board, as we can remote access UP² board using its IP address, which needs our Laptop/Desktop to be on the same network as UP² board.
- Download Intel® System Studio from https://software.intel.com/en-us/system-studio and extract.
- Open a new terminal window and navigate to the directory you extracted the contents of the installer file to.
- Run
install.sh
script and follow the instructions provided there to install Intel® System Studio.
This section gives the steps to add the solution to Intel® System Studio, including creating a new project and populating it with the files needed to build and run it.
-
Open Intel® System Studio. It will start by asking for a workspace directory; choose one and then click OK.
-
From the Intel® System Studio , select File > New > Project, Then choose
Create a C/C++ project for building in a container and running on Linux
under Application Development in New Project.Figure 2. New project
Figure 3. New project
-
Give the project a name, such as
IntelligentVendingMachine
, and in the examples choose theDisplay Temperature on LCD
under C++ > Grove Starter Kit and then click Next.Figure 4. Adding Project Name.
-
To copy the code from the control application directory to the new project source folder perform the following:
- Copy over the
control-app.cpp
from control-application directory into the new project's src folder in Intel® System Studio - Next right click on the project name and follow the sequence: Properties > C/C++ Build > Settings > GNU 64-bit G++ Linker > Libraries and then Add libraries: mraa, upm-uln200xa, sqlite3, upm-jhd1313m1, upm-grove. This can be done by clicking on the small green '+' icon on the top right side of the libraries view.
Figure 5. Adding libraries to the build path
-
In order to run this project, connect to the UP² board first using the IP address already provided. Follow the instructions provided in https://software.intel.com/en-us/developing-projects-with-intel-system-studio-c-creating-an-ssh-connection to connect to the UP² board as root (root privileges are required to use pins on board).
-
Before running the project we need to copy and run a Node.js* script which communicates with the Cloud.
-
azure-storage and sqlite3 node packages are required: Install using:
npm install azure-storage sqlite3
.Copy the Cloud folder on the UP² board using scp command from your desktop/laptop:
scp -r /home/ubuntu/intelligent-vending-machine/Cloud upsquared@###.###.###.###:/home/upsquared/
Then remote login to the UP² board using ssh (
ssh upsquared@##.###.###.###
) and run shell script comm_azure.sh:sh comm_azure.sh ivm.db
(If behind proxy, edit proxy details in
comm_azure.sh
)
- In Intel® System Studio run the project : Run > Run.
Requirements: Node.js, npm, MongoDB*, compass (Sass-based Stylesheet Framework - http://compass-style.org/install/)
-
Open a terminal (shell) on laptop.
-
Go to admin-customer-application folder. Run script using:
sh build.sh
Note: If behind a proxy modify build.sh accordingly.
-
Run server:
./server/bin/www
-
In the browser, goto
http://localhost:9000
to open the webapp. Enter MAC address of UP² in the textbox provided and click Start, it will open admin app. To open customer mobile app Navigate tohttp://localhost:9000/#/mobile