📜 ⬆️ ⬇️

IoT-project for a smart home: building a prototype

Recently, we talked about the approach to work on IoT-projects. Last time we were most interested in the technique, the stages of transforming an idea first into a prototype, and then into a product ready for production. Today we offer to delve into the technical details. Namely, let's talk about how to create a functional prototype of a smart home.



The project involved Intel IoT Commercial Development Kit, a small form factor computer Intel NUC Kit DE3815TYKHE, an Arduino 101 board and some additional components. Having mastered this material, you will be able to do the same that we did, even if your experience in creating IoT solutions is small.
')
Here is what you learn by mastering this guide:


The code and additional documentation can be found on GitHub .

About functionality


Our project is a working model of a smart home, namely, the following is implemented here:


How the system works


The smart home system that we are talking about works on the basis of the following information supplied by its sensors:


Data exchange in the system is made through the cloud environment. For example, if the owner of the house opens the garage door, the corresponding team is transferred to the cloud, and from there to the mechanisms of the garage door. This approach allows you to process information about the state of the system in the cloud, allows remote access to them. So, if the owner of the house does not remember whether the garage door is closed, he can find out about it from anywhere, and if the door is still not closed, he is able to close it remotely.

In this example, we limit ourselves to the above capabilities, not including additional functionality. But it can be fully realized by expanding the system (in particular, using cloud resources).

Configuring Intel NUC and Arduino 101


Consider installing Intel IoT Gateway Software Suite on the Intel NUC Kit DE3815TYKHE computer. Please note that since the size of the device’s built-in storage is limited, we recommend that you do not create a partition on it for recovery. You can return to the factory image of the system by loading it from a USB disk.

After installing the system, the NUC, which will act as an IoT gateway, will be able to connect from the developer’s computer if the devices are on the same network. If you plan to connect the gateway to the Intel IoT Gateway Developer Hub, then to connect to the gateway, you will need to enter the corresponding IP address in the browser and go through the initial setup procedure.

In addition, if the gateway is connected to an Intel network, you will need to configure a proxy server.

We proceed to configure the Intel NUC.

  1. If you do not have an account in the Intel IoT Platform Marketplace - create it.

  2. Order the Intel IoT Gateway Software Suite and, following the instructions received by e-mail, download the image file.

  3. Unzip the downloaded archive and burn the IMG file to a USB disk of at least 4 GB in size.

    - To burn the image to disk, if you are working in Windows, you can use the application Win32 Disk Imager .
    - On Linux, use the command:

    sudo dd if=GatewayOS.img of=/dev/ sdX bs=4M; sync 

    Here the USB drive is sdX.
  4. After the image is completed, disconnect the disk from your computer and connect to the NUC. You will also need to connect a monitor, keyboard and power cable to it.

  5. Turn on the Intel NUC, and at boot time, press F2 to enter the BIOS.

  6. Configure booting from a USB drive. For this:

    - On the Advanced menu, select Boot .
    - In the Boot Configuration property of the OS Selection section, select Linux .
    - Make sure the USB checkbox is selected in the Boot Devices section.
    - Save changes and reboot the system.
    - Press F10 to enter the boot menu and select the USB drive there.

  7. Log in (name and password - root).

  8. Install Wind River Linux on your local drive:

     ~# deploytool -d /dev/mmcblk0 --lvm 0 --reset-media –F 

  9. Use the poweroff command to disable the gateway, then unplug the USB drive from it and turn it on again. The device will boot from the local disk.

  10. Connect an Ethernet cable to the NUC and use the ifconfig eth0 command to find out the IP address assigned to the gateway (it is assumed that the network to which the gateway is connected is configured to automatically configure the new devices connected to it).

  11. Use Intel IoT Gateway Developer Hub to update the MRAA and UPM repositories to the latest version, which is taken from the official source https://01.org . The same result can be achieved by executing the following commands:

     ~# smart update ~# smart upgrade ~# smart install upm 

  12. Connect the Arduino 101 board to the gateway and reboot the NUC. On the Arduino 101, a Firmata sketch will be flashed, after which you can use MRAA and UPM with it.

  13. Set up the board using these instructions.

Hardware components


Here is a list of components that are included in our project.


And here is how it all looks in the collection:


Prototype system for smart home

Installing Intel XDK IoT Edition


Intel XDK IoT Edition supports JavaScript and development for Node.js for projects in the field of the Internet of things.

Please note that if you are working in Windows, we recommend installing Bonjour Print Services software on your computer. This will allow the Intel XDK to automatically detect IoT devices connected to the network. Installing Bonjour is optional, but it makes work easier. You can connect to the device and manually enter the IP address and the necessary information to connect. If you are working on a corporate network, the firewall may block Bonjour.

To install the Intel XDK, follow these steps:

  1. Download the IDE installer for your OS from this page. The desired OS can be selected from the list.

  2. If you are running Windows or Mac OS, run the installer. Namely

    - For Windows, right-click on the downloaded file and select the Run as administrator command in the pop-up menu. If necessary, confirm the launch of the program.

    - For Mac OS, double-click on the downloaded .dmg file to extract the installer. After that, run the extracted .PKG file.

  3. If you are using Linux, follow these steps:

    - Start the terminal
    - Navigate to the folder where the downloaded archive is located with the installer. For example, if this file is in the Desktop folder, use the cd ~/Desktop/
    - In order to unpack the file (suppose its name is installername ), enter a command like tar zxvf installername .
    - Go to the folder where the files extracted from the archive are located.
    - Run the installation command ./install.sh

  4. Now, following the instructions of the Installation Wizard, you can install the Intel XDK IoT Edition on your system.

  5. Install (this step is recommended for Windows only) Bonjour Print Services. To do this, follow these steps:

    - Download the installer from this site.
    - Run the downloaded file BonjourPSSetup.exe as administrator.
    - Follow the installation wizard instructions.

  6. In order for Intel XDK IoT Edition to detect the Intel NUC, you must first install the xdk-daemon package on it, which is available in the official package repository . If this package is already installed, check if it has been updated to version 0.0.35 or higher. Here you can use the following commands:

     ~# smart update ~# smart install xdk-daemon 

  7. After installing or updating the xdk-daemon, restart the Intel NUC in order to start the corresponding service. Now you can add a gateway to the Intel XDK and remotely execute programs on it.

IBM Bluemix setup


Here we will talk about how to create a Bluemix application, how to connect MongoDB and work with data.

Creating a Bluemix Application


First, create a Bluemix application using MongoLab.


BlueMix user interface

To do this, do the following:

  1. Log in to the Bluemix console .
  2. After entering you will see the control panel (DASHBOARD).
  3. Click CREATE APP.
  4. Select the type of WEB application.
  5. Select the SDK for Node.js and click on the CONTINUE button.
  6. Give the application a name and click on the FINISH button.
  7. After the application is created in the IBM cloud, click the ADD A SERVICE OR API button.
  8. In the Data & Analytics section, select MongoLab.
  9. Click on BI to confirm the creation of the service.
  10. After the service is created, a pop-up window will appear asking you to restart the application. Click the RESTAGE button.
  11. Wait until the application is restarted. When this process is complete, a message will be displayed.

Deploying an IBM Bluemix application using Cloud Foundry


Before you start working with Cloud Foundry, you need to install the cf command line interface. It is worth considering here that working with this interface does not support Cygwin. Therefore, when working with Cloud Foundry on Windows, you need to use a different command line interpreter.

After installation, if you are not familiar with Cloud Foundry, follow the guidelines for this system to download the start-up code, and figure out how to send applications for IBM Bluemix to the cloud.

Connect to the Intel Gateway for the Internet of Things and launch applications


  1. On the Intel XDK, in the Develop window, click on the Serial Terminal.
  2. Select a card in the drop-down menu associated with the Port label.
  3. Click the Connect button to establish a connection. In this case, use root as the user name, and your own password as the password.
  4. Enter the command ifconfig to see the IP address of the system.
  5. Select Add Manual Connection and enter the IP address and password.
  6. After the connection is established, click the button with the arrow pointing down to upload the project to the device.
  7. Click the Run button.

After that, the application should start on the gateway.

Application Details


Cloud app for IBM Bluemix


Bluemix's Node.js application uses MongoDB to store data and provides REST APIs for working with them. In addition, web sockets are used to transmit real-time information to client and mobile applications.

Prototype application for the Intel NUC to which the Arduino 101 is connected


This Node.js application runs on the Intel NUC, which acts as a gateway. An Arduino 101 board is connected to it, which allows the gateway to interact with sensors and other peripheral devices. The gateway also sends sensor readings to an application that runs in the IBM Bluemix cloud, and it, in turn, saves them.

The main communication protocol is web sockets. This allows the client (Intel NUC and Arduino 101) to interact with the cloud application. If the connection to the cloud is not available, the application uses SQLite for local data storage and sends them to the cloud when the connection is restored. In addition, this application, when the cloud is unavailable, interacts with the mobile application (recall that when the connection with the cloud is present, the mobile application works with the system through it).

This application allows the user to interact with a touch sensor and a buzzer that simulate a doorbell, an illumination sensor that can detect objects, a servo motor to simulate raising and lowering a garage door, and a rotation angle sensor that supplies the system with closing and opening door data .

Administrative and mobile applications


Administrative and mobile applications are tightly integrated with applications running on the Intel NUC. Instead of providing several versions of programs as full-featured clients for various platforms (or complicating work on a project because of the need to develop cross-platform solutions), the project team decided to implement these applications in HTML5 and JavaScript using Intel XDK IoT Edition. This approach allowed us to create one version of each application that can work on different hardware platforms used by system administrators and its end users.

The administrative application displays information from the sensors, in a mode that practically corresponds to real time, and also displays an event log using the REST API. It works on a regular computer or tablet and gives a complete overview of what is happening in the smart home, including information about events and states of objects. The application allows you to view logs and work with cloud data and analytical information.

The mobile application allows the user to open and close the garage door using web sockets. It works on a smartphone or other mobile device, allowing the user, in addition to opening and closing the garage door, to track how this happens, and also to find out if the door is not locked.

findings


In this material, we demonstrated the process of creating a prototype IoT system, which literally everyone can reproduce.

Using the Intel IoT Commercial Developer Kit, Intel NUC, and the Arduino 101 board, development teams can quickly create relatively inexpensive prototypes of IoT projects.

Additional components for such projects can be found, for example, in the Grove Starter Kit Plus IoT Edition. Cloud part can be implemented on IBM Bluemix. Software that includes both server and client applications can be prepared in Intel XDK IoT Edition.

We told you about the tools for creating IoT solutions and approaches to working on them. Now it's up to you. Successful developments!

Source: https://habr.com/ru/post/397273/


All Articles