Click here to Skip to main content
14,092,869 members
Click here to Skip to main content
Add your own
alternative version

Stats

14.8K views
1 bookmarked
Posted 18 Apr 2016
Licenced CPOL

How-To Intel® IoT Technology Code Samples: Access control in C++

, 18 Apr 2016
This access control system application is part of a series of how-to Intel® IoT Technology code sample exercises using theIntel® IoT Developer Kit, Intel® Edison board, cloud platforms, APIs, and other technologies.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Get access to the new Intel® IoT Developer Kit, a complete hardware and software solution that allows developers to create exciting new solutions with the Intel® Galileo and Intel® Edison boards. Visit the Intel® Developer Zone for IoT.

Introduction

This access control system application is part of a series of how-to Intel® IoT Technology code sample exercises using the
Intel® IoT Developer Kit, Intel® Edison board, cloud platforms, APIs, and other technologies.

From this exercise, developers will learn how to:

  • Connect the Intel® Edison board, which is a computing platform designed for prototyping and producing IoT and wearable computing products.
  • Interface with the Intel® Edison board IO and sensor repository using MRAA and UPM from the Intel® IoT Developer Kit, which is a complete hardware and software solution to help developers explore the IoT and implement innovative projects.
  • Run these code samples in the Intel® System Studio IoT Edition (Eclipse* IDE for C/C++ and Java* development) for creating applications that interact with sensors and actuators, enabling a quick start for developing software for the Intel® Edison or Intel® Galileo board.
  • Set up a web application server to let users enter the access code to disable the alarm system, and store this alarm data using Azure* Redis Cache from Microsoft, Redis Store from IBM Bluemix*, or ElastiCache* using Redis* from Amazon Web Services* (AWS), different cloud services for connecting IoT solutions including data analysis, machine learning, and a variety of productivity tools to simplify the process of connecting your sensors to the cloud and getting your IoT project up and running quickly.

What it is

Using an Intel® Edison board, this project shows you how to create a smart access control system that:

  • monitors a motion sensor to detect when a person is in an area that requires authorization;
  • can be accessed with your mobile phone via a built-in web interface to disable the alarm;
  • keeps track of access data, using cloud-based storage.

How it works

This access control system provides the following user flow:

  1. PIR Motion Sensor looks for motion.
  2. User sets off the motion detector, then has 30 seconds to enter the correct code from a browser.
  3. If the user fails to enter the code in time, the alarm will go off.
  4. If the user enters the correct code, the system will wait for 2 minutes to allow the user to pass.

Additionally, various events (motion-detected, invalid-code, etc.) are logged.

Optionally, all data can be stored using the Intel IoT Examples Datastore running in your own Microsoft Azure, IBM Bluemix, or AWS account.

Hardware requirements

Grove* Transportation & Safety Kit containing:

  1. Intel® Edison board with an Arduino* breakout board
  2. Grove* Base Shield V2
  3. Grove* PIR Motion Sensor
  4. Grove* RGB LCD

Software requirements

  1. Intel System Studio IoT Edition (Eclipse IDE for C/C++ and Java development)
  2. Microsoft Azure, IBM Bluemix, or AWS account

How to set up

To begin, clone the How-To Intel IoT Technology code samples repository onto your computer with Git* as follows:

$ git clone https://github.com/intel-iot-devkit/how-to-code-samples.git

Want to download a .zip file? In your web browser, go to https://github.com/intel-iot-devkit/how-to-code-samples and click the Download ZIP button on the lower right-hand side. Once the .zip file is downloaded, uncompress it, and then use the files in the directory for this example.

Adding the program to Eclipse

In Eclipse*, select Import Wizard to import an existing project into the workspace as follows:

  1. From the main menu, select File > Import.
  2. The Import Wizard dialog box opens. Select General > Existing Project into Workspace and click Next.
  3. Click Select root directory and then the associated Browse button to locate the directory that contains the project files.
  4. Under Projects, select the directory with the project files you'd like to import and click OK and then Finish to import the files into Eclipse*.
  5. Your main .cpp program is now displayed in your workspace under the src folder.

Connecting the Grove sensors

You need to have a Grove Base Shield V2 connected to an Arduino-compatible breakout board to plug all the Grove devices into the Grove Base Shield V2. Make sure you have the tiny VCC switch on the Grove* Base Shield V2 set to 5V.

  1. Plug one end of a Grove*= cable into the Grove* PIR Motion Sensor, and connect the other end to the D4 port on the Grove* Base Shield V2.
  2. Plug one end of a Grove* cable into the Grove* RGB LCD, and connect the other end to any of the I2C ports on the Grove* Base Shield V2.

Intel® Edison board setup

This example uses the restclient-cpp library to perform REST calls to the remote data server. The code can be found in thelib directory. The restclient-cpp library requires the libcurl package, which is already installed on the Intel® Edison board by default.

This example also uses the Crow* web micro-framework to provide a simple-to-use, yet powerful web server. The Crow library requires the libboost package be installed on the Intel® Edison board, as well as adding the needed include and lib files to the Eclipse* Cross G++ Compiler and Cross G++ Linker.

  1. Update opkg base feeds so you can install the needed dependencies. Establish an SSH connection to the Intel® Edison board and run the following command:

    vi /etc/opkg/base-feeds.conf
  2. Edit the file so that it contains the following:

    src/gz all http://repo.opkg.net/edison/repo/all
    src/gz edison http://repo.opkg.net/edison/repo/edison
    src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32
  3. Save the file by pressing Esc, then :, then q, and Enter.

This only needs to be done once per Intel® Edison board, so if you've already done it, you can skip to the next step.

Install the boost libraries onto the Intel® Edison board by running the following command:

opkg update
opkg install boost-dev

Copy the libraries

You need to copy the libraries and include files from the board to your computer where you're running Eclipse so the Cross G++ Compiler and Cross G++ Linker can find them. The easiest way to do this is by running the scp command from your computer (NOT the Intel® Edison board), as follows:

scp -r USERNAME@xxx.xxx.x.xxx:/usr/include/boost ~/Downloads/iotdk-ide-linux/devkit-x86/sysroots/i586-poky-linux/usr/include
scp USERNAME@xxx.xxx.x.xxx:/usr/lib/libboost* ~/Downloads/iotdk-ide-linux/devkit-x86/sysroots/i586-poky-linux/usr/lib

Change USERNAME@xxx.xxx.x.xxx to match whatever username and IP address you set your board to.

Change ~/Downloads/iotdk-ide-linux to match the location on your computer where you installed the Intel IoT Developer Kit.

Copy the libraries on Windows*

We have a helpful link to get this set up here:

using-winscp.md

Note: you need to turn SSH on by running the configure_edison --password command on the board. Once you set the password, make sure you write it down. You only need to do this once and it is set when you reboot the Intel® Edison board.

Datastore server setup

Optionally, you can store the data generated by this sample program in a backend database deployed using Microsoft* Azure*, IBM* Bluemix*, or AWS*, along with Node.js*, and a Redis* data store.

Get more help installing and using WinSCP

Connecting your Intel® Edison board to Eclipse

  1. In the bottom left corner, right-click anywhere on the Target SSH Connections tab and select New > Connection.
  2. The Intel® IoT Target Connection window appears. In the Filter field, type the name of your board.
  3. In the Select one of the found connections list, select your device name and click OK.
  4. On the Target SSH Connections tab, right-click your device and select Connect.

If prompted for the username and password, the username is root and the password is whatever you specified when configuring the Intel® Edison board.

Running the example with the cloud server

To run the example with the optional backend data store, you need to set the SERVER and AUTH_TOKEN environment variables. You can do this in Eclipse* as follows:

  1. From the Run menu, select Run Configurations.
    The Run Configurations dialog box is displayed.
  2. Under C/C++ Remote Application, click doorbell.
    This displays the information for the application.
  3. In the Commands to execute before application field, add the environment variables using the server and authentication token that correspond to your own setup, as shown in the example below:

    chmod 755 /tmp/access-control; export SERVER="http://intel-examples.azurewebsites.net/logger/access-control"; export AUTH_TOKEN="YOURTOKEN"
  4. Click Apply to save your new environment variables.

Now, when you run your program using the Run button, it should be able to call your server to save the data right from the
Intel® Edison board.

Running the code on the Intel® Edison board

When you're ready to run the example, click Run at the top menu bar in Eclipse.

This compiles the program using the Cross G++ Compiler, links it using the Cross G++ Linker, transfers the binary to the Intel® Edison board, and then executes it on the board itself.

After running the program, you should see output similar to the one in the image below.

Regenerating the HTML and CSS

If you make any changes to either the index.html or styles.css file, you need to regenerate the .hex file used to serve up the assets via the built-in Crow* web server. Learn more about how to use the shell script.

Disabling the alarm

The alarm is disabled using a single-page web interface served directly from the Intel® Edison board while the sample program is running.

The web server runs on port 3000, so if the Intel® Edison board is connected to Wi-Fi* on 192.168.1.13, the address to browse to if you are on the same network is http://192.168.1.13:3000.

For a complete list of the 18 How-To Intel IoT Technology code samples in C++, read the 18 How-To Intel® IoT® Technology Code Samples Now Available in C++ blog post on the Intel® Developer Zone .

For a complete list of the 18 How-To Intel IoT Technology code samples in JavaScript*, read the Announcing 18 New How-To Intel® IoT Technology Code Samples blog post on the Intel® Developer Zone .

For more details about this code sample, go to GitHub*.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Intel Corporation
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
Group type: Organisation

43 members


You may also be interested in...

Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190518.1 | Last Updated 18 Apr 2016
Article Copyright 2016 by Intel Corporation
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid