Things used in this project

Hardware components:
Intel.web.720.405
Intel Edison
×1
Grove 20starter 20kit 20plus 20  20intel c2 ae 20iot2 01
SeeedStudio Grove starter kit plus for Intel Edison
×1
Intel Grove GPS
×1
09590 01
LED (generic)
We use the Green LED to display system health. Every 5 secs it flashes to show that system is working. We use Red LED to show that the Web service call is successfully made and there by indicating the acknowledgement of the emergency by the system. In our system user is required to press and hold the push button till the user sees the Red light. Once the user sees the red light he can release the button
×2
Software apps and online services:
Wordmark red
Twilio SMS Messaging API
We use Twilio to send SMS.
Google Cloud Platform
We use Google Cloud Platform for the backend Web service. In the backend we make Twilio API calls to send SMS.

Code

Node JS code JavaScript
Once the push button is pressed and held for 5 sec, the system detects the event, retrieves the GPS coordinates and invokes a Web service with the details.
/* This program captures the push button press and retrieves the GPS location and invokes a webservice to log the button press event.
    Copyright (C) 2016 Jayashree Ravi and Pramoda Ravi

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
// Leave the above lines for propper jshinting
//Type Node.js Here :)

console.log("Distress System for Elderly  Copyright (C) 2016  Jayashree Ravi and Pramoda Ravi");


var pushButtonSensor = require('jsupm_grove');

var mraa = require('mraa'); //require mraa

var gpsSensor = require('jsupm_ublox6');

// Create the button object using GPIO pin 4
var button = new pushButtonSensor.GroveButton(4);

// Instantiate a Ublox6 GPS device on uart 0.
var myGPSSensor = new gpsSensor.Ublox6(0);

// Green LED on Digital pin 6
var greenLed = new mraa.Gpio(6);
greenLed.dir(mraa.DIR_OUT);

//Red LED on Digital pin 8
var redLed = new mraa.Gpio(8);
redLed.dir(mraa.DIR_OUT);

if (!myGPSSensor.setupTty(gpsSensor.int_B9600))
{
    console.log("Failed to setup tty port parameters");
    process.exit(0);
}


// Read the input and print, waiting 5 seconds between readings
function readButtonValue() {
    // Turn the green LED on
    greenLed.write(1);
    console.log(button.name() + " value is " + button.value());
    
    if(button.value()==1) {
         
        var gpsStr = encodeURIComponent(getGPSInfo());
        console.log(gpsStr);
        const http = require('http');
        // Turn the red LED on
        redLed.write(1);
        http.get('http://www.mobibootcamp.com/sendMessage?uname=%22j%22&phoneNumber=%227347xxxxxx%22&gps='+gpsStr, function(res) {
            console.log('statusCode: ', res.statusCode);
            console.log('headers: ', res.headers);

            res.on('data', function(d) {
                console.log("data received");
                console.log(d.toString());
                redLed.write(0);
            });

        }).on('error', function(e) {
            console.error(e);
        });
    }
     setTimeout(greenLed.write(0),1000); 
}


function getGPSInfo()
{

    var bufferLength = 256;
    var nmeaBuffer  = new gpsSensor.charArray(bufferLength);
    var latlon;
    // we don't want the read to block in this example, so
    // check to see if data is available first.

    while(myGPSSensor.dataAvailable())
    {
        var rv = myGPSSensor.readData(nmeaBuffer, bufferLength);

        var GPSData, dataCharCode, isNewLine, lastNewLine;
        var numlines= 0;
        if (rv > 0)
        {
            GPSData = "";
            // read only the number of characters
            // specified by myGPSSensor.readData
            for (var x = 0; x < rv; x++)
                GPSData += nmeaBuffer.getitem(x);

            console.log(GPSData);
            var gpsArray = GPSData.toString().split('\n');
            for(var i=0; i<gpsArray.length; i++){
                console.log(gpsArray[i]);
                if(gpsArray[i].indexOf('GPGGA') !== -1){
                    var gpsparts = gpsArray[i].split(',');
                    var lat = gpsparts[2];
                    var lon = gpsparts[4];
                    if(lat && lon){
                        console.log("GPGGA reading:" + gpsArray[i]);
                        return (convertToDecimal(lat)+",-"+convertToDecimal(lon));
                    }else {
                        continue;
                    }
                }

                if(gpsArray[i].indexOf('GPRMC') !== -1){
                    var gpsparts2 = gpsArray[i].split(',');
                    var lat2 = gpsparts[3];
                    var lon2 = gpsparts[5];
                    if(lat2 && lon2){
                        return (convertToDecimal(lat2)+",-"+convertToDecimal(lon2));
                    } else {
                        continue;
                    }
                }
            }
        }

        if (rv < 0) // some sort of read error occured
        {
            console.log("Port read error.");
            process.exit(0);
        }
    }
}

function convertToDecimal(lat){
    var firstpart = +(lat.substring(0,lat.length-7));
    var secondpart = +(lat.substring(lat.length-7));
    var latdecimal = firstpart+(secondpart/60);
    return latdecimal;
}
setInterval(readButtonValue, 5000);

Credits

13466539 10154298772777238 1411769646677120225 n
Pramoda Ravi

I enjoy the art of making cars go fast by using the technology our day and age are able to provide us.

Contact

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

LoRaCatKitty Build IoT Applications with LoRaWAN in 3 Steps
Intermediate
  • 1,003
  • 7

Protip

LoRaCatKitty Build IoT Applications with LoRaWAN in 3 steps with The Thing Networks and Cayenne.

Build Your Own Amazon Echo Using a RPI and ReSpeaker HAT
Intermediate
  • 6,404
  • 33

Full instructions

How to build your own Amazon Echo using a Raspberry Pi and ReSpeaker 2-Mics HAT.

Smart Shoes (Auto-lacing and Generating Electricity)
Intermediate
  • 543
  • 7

Full instructions

Features of smart shoes: generates electricity, auto lacing, step counting, etc.

Bare Conductive Leak Detector
Intermediate
  • 583
  • 1

Full instructions

Use Bare Conductive Electric Paint, an Arduino, and the anduinoWiFi shield to make a system that sends a text when a leak is detected!

Build Your Own Google Home Assistant with Android Things
Intermediate
  • 392
  • 5

Build your own Google Home Assistant with Android Things using one of the supported platforms, such as the Intel Edison or Raspberry Pi.

Arduino101 / tinyTILE BLE: Match-Making Sunglasses
Intermediate
  • 5,185
  • 20

Full instructions

You can make someone else's sunglasses see-through via BLE and check them out from far away, perhaps with your heartbeat.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login