Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
.jshintrc
LICENSES.md Use standard Intel outbound license Apr 20, 2016
README.md
app.json
config.json
datastore.js Update all code files with correct license Jun 28, 2016
dfrobot.js Pin mapping changes for DFRobot kit air quality sensor in JS Dec 15, 2016
grove.js
icon.png Add icon.png and app.json files to javascript folders to support Inte… Jul 14, 2016
index.js Modify JS examples for somewhat more informative messages when logging Oct 13, 2016
mqtt.js Update all code files with correct license Jun 28, 2016
package.json WIP on final updates for JS examples using DFRobot kit on gateway Dec 15, 2016

README.md

Air quality sensor in JavaScript*

Introduction

This air quality monitor application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison board, Intel® IoT Gateway, cloud platforms, APIs, and other technologies.

From this exercise, developers will learn how to:

  • Connect the Intel® Edison board or Intel® IoT Gateway, computing platforms designed for prototyping and producing IoT and wearable computing products.
  • Interface with the Intel® Edison board or Intel® Arduino/Genuino 101 board IO and sensor repository using MRAA and UPM from the Intel® IoT Developer Kit, a complete hardware and software solution to help developers explore the IoT and implement innovative projects.
  • Run this code sample in Intel® XDK IoT Edition, an IDE for creating applications that interact with sensors and actuators, enabling a quick start for developing software for the Intel® Edison board or Intel® IoT Gateway.
  • 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* Azure*, 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.
  • Set up a MQTT-based server using IoT Hub from Microsoft* Azure*, IoT from IBM* Bluemix*, or IoT from Amazon Web Services* (AWS), different cloud machine to machine messaging services based on the industry standard MQTT protocol.

What it is

Using an Intel® Edison board or Intel® IoT Gateway, this project lets you create an air quality monitor that:

  • continuously checks the air quality for airborne contaminants.
  • sounds an audible warning when the air quality is unhealthy.
  • stores a record of each time the air quality sensor detects contaminants, using cloud-based data storage.

How it works

This shop air quality monitor uses the sensor to constantly keep track of airborne contaminants.

If the sensor detects one of several different gases and the detected level exceeds a defined threshold, it makes a sound through the speaker to indicate a warning.

Also, optionally, the monitor stores the air quality data using the Intel® IoT Examples Datastore or an MQTT server running in your own Microsoft* Azure*, IBM* Bluemix*, or AWS account.

Hardware requirements

This sample can be used with either the Grove* Home Automation Kit from Seeed Studio, or else the DFRobot* Edison Starter Kit.

Grove* Home Automation Kit, containing:

  1. Intel® Edison with an Arduino* breakout board or Intel® IoT Gateway with Intel® Arduino/Genuino 101
  2. Grove* Air Quality Sensor
  3. Grove* Speaker

DFRobot* Starter Kit for Intel® Edison, containing:

  1. Intel® Edison with an Arduino* breakout board or Intel® IoT Gateway with Intel® Arduino/Genuino 101
  2. Analog Gas Sensor.
  3. Buzzer.
  4. LCD Keypad Shield

Software requirements

  1. Intel® XDK IoT Edition
  2. Microsoft* Azure*, IBM* Bluemix*, or AWS account (optional)

How to set up

To begin, clone the How-To Intel IoT Code Samples repository with Git* on your computer as follows:

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

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 at the lower right. Once the .zip file is downloaded, uncompress it, and then use the files in the directory for this example.

Adding the program to Intel® XDK IoT Edition

In Intel® XDK IoT Edition, select Import Your Node.js Project:

On the New Project screen, click on the folder icon:

Then, navigate to the directory where the example project exists, and select it:

Choose a name for the project and click on the Create button. Then click on the Continue button to finish creating your project:

You need to connect to your Intel® Edison board from your computer to send code to it.

Click the IoT Device menu at the bottom left. If your Intel® Edison is automatically recognized, select it.

Otherwise, select Add Manual Connection. In the Address field, type 192.168.2.15. In the Port field, type 58888. Click Connect to save your connection.

Installing the program manually on the Intel® Edison board

Alternatively, you can set up the code manually on the Intel® Edison board.

Clone the How-To Intel IoT Code Samples repository to your Intel® Edison board after you establish an SSH connection to it, as follows:

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

Then, navigate to the directory with this example.

To install Git* on the Intel® Edison board (if you don’t have it yet), establish an SSH connection to the board and run the following command:

$ opkg install git

Connecting the Grove* sensors

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

  1. Plug one end of a Grove* cable into the Grove* Air Quality Sensor, and connect the other end to the AO port on the Grove* Shield.

  2. Plug one end of a Grove* cable into the Grove* Speaker, and connect the other end to the D5 port on the Grove* Shield.

Connecting the DFRobot* sensors

You need to have a DFRobot* LCD Keypad Shield connected to an Arduino*-compatible breakout board to plug all the DFRobot* devices into the DFRobot* LCD Keypad Shield.

  1. Plug one end of a DFRobot* cable into the Buzzer, and connect the other end to the A1 port on the DFRobot* LCD Keypad Shield.

  2. Plug one end of a DFRobot* cable into the Air Quality Sensor, and connect the other end to the A3 port on the DFRobot* LCD Keypad Shield.

Installing the program manually on the Intel® Edison board

If you're running this code on your Intel® Edison manually, you need to install some dependencies.

To obtain the Node.js* modules needed for this example to execute on the Intel® Edison board, run the following command:

npm install

Intel® IoT Gateway setup

You can run this example using an Intel® IoT Gateway connected to an Arduino*/Genuino* 101.

Make sure your Intel® IoT Gateway is setup using Intel® IoT Gateway Software Suite, by following the directions on the web site here:

https://software.intel.com/en-us/getting-started-with-intel-iot-gateways-and-iotdk

You must install the Intel® XDK on the Intel® IoT Gateway, by following the directions on the above link, under the section "Connecting to the Intel® XDK".

The Arduino*/Genuino* 101 needs to have the Firmata* firmware installed. If you have IMRAA installed on your gateway, this will be done automatically. Otherwise, install the StandardFirmata or ConfigurableFirmata sketch manully on to your Arduino*/Genuino* 101.

You will also need to configure the config.json in the example to use the Arduino*/Genuino* 101. See the section "Configuring the example" below.

Data store 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.

For information on how to set up your own cloud data server, go to:

https://github.com/intel-iot-devkit/intel-iot-examples-datastore

MQTT server setup

You can also optionally store the data generated by this sample program using MQTT, a machine-to-machine messaging server. You can use MQTT to connect to Microsoft* Azure*, IBM* Bluemix*, or AWS.

For information on how to connect to your own cloud MQTT messaging server, go to:

https://github.com/intel-iot-devkit/intel-iot-examples-mqtt

Configuring the example

To configure the example for the Grove* kit, just leave the kit key in the config.json set to grove. To configure the example for the DFRobot* kit, change the kit key in the config.json to dfrobot as follows:

{
  "kit": "dfrobot",
  "THRESHOLD": 50
}

To configure the example for the Arduino*/Genuino* 101, add a platform key with the value firmata to the config.json, as follows:

{
  "kit": "grove",
  "platform": "firmata",
  "THRESHOLD": 50
}

To configure the example for the optional Microsoft* Azure*, IBM* Bluemix*, or AWS data store, add the SERVER and AUTH_TOKEN keys in the config.json file below the "THRESHOLD" value as follows:

{
  "kit": "grove",
  "THRESHOLD": 50,
  "SERVER": "http://intel-examples.azurewebsites.net/logger/access-control",
  "AUTH_TOKEN": "s3cr3t"
}

For information on how to configure the example for the optional Microsoft* Azure*, IBM* Bluemix*, or AWS MQTT messaging server, go to:

https://github.com/intel-iot-devkit/intel-iot-examples-mqtt/

Running the program using Intel® XDK IoT Edition

When you're ready to run the example, make sure you saved all the files.

Click the Upload icon to upload the files to the Intel® Edison board.

Click the Run icon at the bottom of Intel® XDK IoT Edition. This runs the code on the Intel® Edison board.

If you made changes to the code, click Upload and Run. This runs the latest code with your changes on the Intel® Edison board.

You will see output similar to the above when the program is running.

Determining the Intel® Edison IP address

You can determine what IP address the Intel® Edison board is connected to by running the following command:

ip addr show | grep wlan

You will see output similar to the following:

3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    inet 192.168.1.13/24 brd 192.168.1.255 scope global wlan0

The IP address is shown next to inet. In the example above, the IP address is 192.168.1.13.

IMPORTANT NOTICE: This software is sample software. It is not designed or intended for use in any medical, life-saving or life-sustaining systems, transportation systems, nuclear systems, or for any other mission-critical application in which the failure of the system could lead to critical injury or death. The software may not be fully tested and may contain bugs or errors; it may not be intended or suitable for commercial release. No regulatory approvals for the software have been obtained, and therefore software may not be certified for use in certain countries or environments.