Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Callback for NinjaBlocks devices that will post device data to Xively through Parse.com http://forums.ninjablocks.com/index.php?p=/discussion/490/unofficial-how-to-posting-from-the-dashboard-to-cosm-pachube/p1
Parse.Cloud.define("hello", function(request, response) {
var xivelyKey = 'YOUR XIVELY KEY';
var feedId = 713578059;
var device = request.params.D;
var channels = {
31: 'Temperature',
30: 'Humidity'
};
var channel = channels[device];
var incomingdata = request.params.DA;
var timest = new Date(request.params.timestamp);
var timest1 = timest.getFullYear()+'-'+("0" + (timest.getMonth() + 1)).slice(-2)+'-'+("0" + timest.getDate()).slice(-2) +'T'+("0"+timest.getHours()).slice(-2)+':'+("0"+timest.getMinutes()).slice(-2)+':'+("0"+timest.getSeconds()).slice(-2)+'Z';
var datap = { datapoints: []};
datap.datapoints.push
({
"at" : timest1,
"value" : incomingdata
});
var requestOptions = {
method: 'POST',
url: 'http://api.xively.com/v2/feeds/' + feedId + '/datastreams/' + channel + '/datapoints',
headers:{
'X-ApiKey': xivelyKey,
'Content-Type': 'application/json'
},
body: datap,
success: function(httpResponse) {
console.log(httpResponse.text);
response.success('Xively ' + channel + ' Updated!');
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
response.error('Xively ' + channel + ' not updated');
}
};
Parse.Cloud.httpRequest(requestOptions);
});
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.