Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.