Click here to Skip to main content
13,254,366 members (56,803 online)
Click here to Skip to main content
Add your own
alternative version

Stats

3.3K views
1 bookmarked
Posted 18 May 2017

Fire alarm in JavaScript

, 18 May 2017
Rate this:
Please Sign up or sign in to vote.
This smart fire alarm application is part of a series of how-to 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.

Editorial Note

This article is 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 smart fire alarm application is part of a series of how-to 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 Arduino 101* (branded Genuino 101* outside the U.S.) 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.
  • Connect to a server using IoT Hub from Microsoft Azure*, IoT from IBM Bluemix*, IoT from Amazon Web Services (AWS)*, AT& M2X*, Predix* from GE, or SAP Cloud Platform* IoT, different cloud-based IoT platforms for machine to machine communication.
  • Invoke the services of the Twilio* API for sending text messages.

What it is

Using an Intel® Edison board or Intel® IoT Gateway, this project lets you create a smart fire alarm that:

  • constantly monitors for unsafe temperature levels.
  • issues an audible notification using the buzzer.
  • issues a visual notification using the LCD.
  • keeps track of fire events, using cloud-based data storage.
  • sends text messages to alert others of a possible fire.

How it works

This smart fire alarm monitors the ambient temperature using the connected temperature sensor.

If the temperature exceeds a certain threshold (set to 28 degrees Celsius in this example), it sounds an alarm through the buzzer and displays an alert on the LCD.

In addition, it can send a text message to a specified number through Twilio*, warning the recipient of a possible fire danger.

Optionally, data can be stored using your own Microsoft Azure*, IBM Bluemix*, AT&T M2X*, AWS*, Predix*, or SAP* account.

Hardware requirements

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

Grove* Starter Kit Plus, containing:

  1. Intel® Edison module with an Arduino* breakout board or Intel® IoT Gateway with Arduino 101
  2. Grove* Temperature Sensor
  3. Grove* Buzzer
  4. Grove* RGB LCD

DFRobot* Starter Kit for Intel® Edison, containing:

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

Software requirements

  1. Intel® XDK IoT Edition
  2. Microsoft Azure*, IBM Bluemix*, AT&T M2X*, AWS*, Predix*, or SAP* account (optional)
  3. Twilio* account (optional)

How to set up

To begin, clone the How-To 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:

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 board 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 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* Temperature Sensor, and connect the other end to the A0 port on the Grove* Shield.

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

  3. 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* Shield.

Connecting the DFRobot* sensors

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

  1. Plug one end of a DFRobot* cable into the Analog Temperature Sensor, and connect the other end to the A3 port on the LCD Keypad Shield.

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

Manual Intel® Edison board setup

If you're running this code on your Intel® Edison board 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 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 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 101.

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

Twilio* API key

To optionally send text messages, you need to register for an account and get an API key from the Twilio* website:

https://www.twilio.com

You cannot send text messages without obtaining a Twilio API key first. You can still run the example, but without the text messages.

Pass your Twilio* API key and authentication token to the sample program by modifying the TWILIO_ACCT_SID and TWILIO_AUTH_TOKEN keys in the config.json file as follows:

{
  "ALARM_THRESHOLD": 28,
  "TWILIO_ACCT_SID": "YOURAPIKEY",
  "TWILIO_AUTH_TOKEN": "YOURTOKEN"
}

IoT cloud setup

You can optionally store the data generated by this sample program using cloud-based IoT platforms from Microsoft Azure*, IBM Bluemix*, AT&T M2X*, AWS*, Predix*, or SAP*.

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

https://github.com/intel-iot-devkit/iot-samples-cloud-setup

Data store server setup

Optionally, you can store the data generated by this sample program in a back-end 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

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",
  "ALARM_THRESHOLD": 28
}

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

{
  "kit": "grove",
  "platform": "firmata",
  "ALARM_THRESHOLD": 28
}

To configure the example for sending optional text messages, obtain an API key from the Twilio* web site as explained above, and then add the TWILIO_ACCT_SID and TWILIO_AUTH_TOKEN keys to the config.json file as follows:

{
  "kit": "grove",
  "ALARM_THRESHOLD": 28,
  "TWILIO_ACCT_SID": "YOURAPIKEY",
  "TWILIO_AUTH_TOKEN": "YOURTOKEN"
}

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 as follows:

{
  "kit": "grove",
  "ALARM_THRESHOLD": 28,
  "SERVER": "http://intel-examples.azurewebsites.net/logger/fire-alarm",
  "AUTH_TOKEN": "s3cr3t"
}

To configure the example for both the text messages and the Microsoft Azure*, IBM Bluemix*, or AWS data store, add the TWILIO_ACCT_SID, TWILIO_AUTH_TOKEN, SERVER, and AUTH_TOKEN keys in the config.json file as follows:

{
  "kit": "grove",
  "ALARM_THRESHOLD": 28,
  "TWILIO_ACCT_SID": "YOURAPIKEY",
  "TWILIO_AUTH_TOKEN": "YOURTOKEN",
  "SERVER": "http://intel-examples.azurewebsites.net/logger/fire-alarm",
  "AUTH_TOKEN": "s3cr3t"
}

For information on how to configure the example for an optional Microsoft Azure*, IBM Bluemix*, AT&T M2X*, AWS*, Predix*, or SAP* IoT cloud server, go to:

https://github.com/intel-iot-devkit/iot-samples-cloud-setup

Running the program using Intel® XDK IoT Edition

When you're ready to run the example, make sure you have 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.

Running the program manually

To run the example manually on the Intel® Edison board, establish an SSH connection to the board and execute the following command:

node index.js

Determining the Intel® Edison board 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.

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

44 members


You may also be interested in...

Pro

Comments and Discussions

 
Question[My vote of 2] No. Just no. Pin
jtmueller23-May-17 8:01
memberjtmueller23-May-17 8:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 18 May 2017
Article Copyright 2017 by Intel Corporation
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid