Created
June 21, 2017 00:42
-
-
Save cmsunu28/76ad2263c567817c2c6bcb4ce0b5f0c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module['exports'] = function echoHttp (hook) { | |
var https = require('https'); | |
var querystring = require('querystring'); | |
var env = hook.env; | |
var token = env.particle_access_token; | |
var deviceID = env.particle_doorbell_device_id; | |
// don't forget to define these secret variables at hook.io/env | |
var request = require('request'); | |
var nickname = hook.params["name"]; | |
var location = hook.params["loc"]; | |
console.log('incoming: ',nickname); | |
console.log('location: ',location); | |
var func=nickname; | |
var arg=location; | |
if(deviceID != undefined && arg != undefined && func != undefined){ | |
var path = "https://api.particle.io/v1/devices/" + deviceID + "/" + func | |
var data = querystring.stringify({ | |
args: arg, | |
access_token: token | |
}); | |
var options = { | |
hostname: 'api.particle.io', | |
port: 443, | |
path: path, | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded' | |
} | |
}; | |
var req = https.request(options, function(res) { | |
console.log('statusCode: ', res.statusCode); | |
console.log('headers: ', res.headers); | |
res.setEncoding('utf8'); | |
res.on('data', function(d) { | |
}); | |
res.on('end', function () { | |
// console.log(result); | |
hook.res.end(returnValue); | |
}); | |
}); | |
req.on('error', function(error){ | |
hook.res.end("Error: " + returnValue); | |
}); | |
// console.log(data); | |
req.write(data); | |
req.end(); | |
} | |
else{ | |
hook.res.end(returnValue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment