var AWS = require('aws-sdk'), util = require('util'), async = require('async');
//var gpio = require('pi-gpio');

// configure AWS
AWS.config.loadFromPath('./config/aws_config.json');
//AWS.config.update({ 'region': 'us-east-1', 'accessKeyId': 'AKIAIPADUMAIHXBKKNKQ', 'secretAccessKey': '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' });

var sqs = new AWS.SQS().client;

//function delayPinWrite(pin, value, callback) {
//    setTimeout(function() {
//        gpio.write(pin, value, callback);
//    }, config.RELAY_TIMEOUT);
//}

process.on( 'SIGINT', function() {
    console.log( "\nGracefully shutting down from SIGINT (Ctrl-C)" );
    // some other closing procedures go here
    process.exit( );
})

function readMessage() {
    sqs.receiveMessage({
        "QueueUrl": "https://sqs.us-east-1.amazonaws.com/990510411818/bells-walk-garage-door-queue",
        "MaxNumberOfMessages": 1,
        "VisibilityTimeout": 30,
        "WaitTimeSeconds": 20
        }, function (err, data) {
            var sqs_message_body;
            if ((data.Messages) && (typeof data.Messages[0] !== 'undefined' && typeof data.Messages[0].Body !== 'undefined')) {
                //sqs msg body
                sqs_message_body = JSON.parse(data.Messages[0].Body);
                console.log(sqs_message_body);
                /* async.series([
                        function(callback) {
                        // Open pin for output
                        gpio.open(config.LEFT_GARAGE_PIN, "output", callback);
                        },
                        function(callback) {
                        // Turn the relay on
                        gpio.write(config.LEFT_GARAGE_PIN, config.RELAY_ON, callback);
                        },
                        function(callback) {
                        // Turn the relay off after delay to simulate button press
                        delayPinWrite(config.LEFT_GARAGE_PIN, config.RELAY_OFF, callback);
                        },
                        function(err, results) {
                        setTimeout(function() {
                            // Close pin from further writing
                            gpio.close(config.LEFT_GARAGE_PIN);
                            // Return json
                            res.json("ok");
                            }, config.RELAY_TIMEOUT);
                        }
                ]); */

                //delete message from queue
                sqs.deleteMessage({
                    "QueueUrl" : "https://sqs.us-east-1.amazonaws.com/990510411818/bells-walk-garage-door-queue",
                    "ReceiptHandle" :data.Messages[0].ReceiptHandle
                    }, function(err, data){                
                    });
            }
            readMessage();                
        });
    }          
readMessage();        


@@ -75,15 +75,46 @@
 nc')
-;%0A//var
+, pushover = require('node-pushover'),
  gpi
@@ -140,26 +140,10 @@
 o');
+ 
 %0A
-%0A// configure AWS
 %0AAWS
@@ -196,194 +196,202 @@
 ');%0A
-//AWS.config.update(%7B 'region': 'us-east-1', 'accessKeyId': 'AKIAIPADUMAIHXBKKNKQ', 'secretAccessKey': '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' %7D);%0A%0Avar sqs = new AWS.SQS().client
+%0Avar sqs = new AWS.SQS().client;%0Avar push = new pushover(%7B token: pushover_token, user: pushover_user %7D);%0A%0Avar config = %7B%0A    PIN: 7,%0A    RELAY_ON: 0,%0A    RELAY_OFF: 1,%0A    RELAY_TIMEOUT: 5%0A%7D
 ;%0A%0A
-//
 func
@@ -429,26 +429,24 @@
 callback) %7B%0A
-//
     setTimeo
@@ -461,18 +461,16 @@
 ion() %7B%0A
-//
         
@@ -503,18 +503,16 @@
 lback);%0A
-//
     %7D, c
@@ -537,188 +537,11 @@
 T);%0A
-//
 %7D%0A%0A
-process.on( 'SIGINT', function() %7B%0A    console.log( %22%5CnGracefully shutting down from SIGINT (Ctrl-C)%22 );%0A    // some other closing procedures go here%0A    process.exit( );%0A%7D)%0A%0A
 func
@@ -1125,16 +1125,24 @@
 age_body
+.Message
 );%0A     
@@ -1154,17 +1154,16 @@
       /*
- 
 async.se
@@ -1181,36 +1181,32 @@
                 
-    
 function(callbac
@@ -1202,36 +1202,32 @@
 ion(callback) %7B%0A
-    
                 
@@ -1269,28 +1269,26 @@
             
-    
+//
 gpio.open(co
@@ -1288,36 +1288,24 @@
 open(config.
-LEFT_GARAGE_
 PIN, %22output
@@ -1334,35 +1334,27 @@
             
-    %7D,%0A    
+%7D,%0A
             
@@ -1374,36 +1374,32 @@
 ion(callback) %7B%0A
-    
                 
@@ -1439,28 +1439,26 @@
             
-    
+//
 gpio.write(c
@@ -1459,36 +1459,24 @@
 rite(config.
-LEFT_GARAGE_
 PIN, config.
@@ -1512,35 +1512,27 @@
             
-    %7D,%0A    
+%7D,%0A
             
@@ -1572,36 +1572,32 @@
                 
-    
 // Turn the rela
@@ -1659,20 +1659,18 @@
         
-    
+//
 delayPin
@@ -1682,28 +1682,16 @@
 (config.
-LEFT_GARAGE_
 PIN, con
@@ -1732,35 +1732,27 @@
             
-    
 %7D,%0A
-    
             
@@ -1804,20 +1804,16 @@
         
-    
 setTimeo
@@ -1824,28 +1824,24 @@
 unction() %7B%0A
-    
             
@@ -1906,28 +1906,26 @@
             
-    
+//
 gpio.close(c
@@ -1934,30 +1934,14 @@
 fig.
-LEFT_GARAGE_
 PIN);%0A
-    
     
@@ -2003,32 +2003,85 @@
     
-    res.json(%22ok%22);%0A    
+push.send(%22Door command successful%22, %22Garage door has been opened/closed!%22);%0A
     
@@ -2138,36 +2138,32 @@
                 
-    
 %7D%0A              
@@ -2172,16 +2172,109 @@
 %5D); */%0A%0A
+                push.send(%22Door command successful%22, %22Garage door has been opened/closed!%22);%0A
         
@@ -2719,9 +2719,8 @@
        %0A
-%0A

add push, clean up