Skip to content

Instantly share code, notes, and snippets.

@jeanfbrito
Created January 25, 2016 15:22
Show Gist options
  • Save jeanfbrito/f8269a397cc43911dec1 to your computer and use it in GitHub Desktop.
Save jeanfbrito/f8269a397cc43911dec1 to your computer and use it in GitHub Desktop.
// The received message is stored in 'msg'
// It will have at least a 'payload' property:
// console.log(msg.payload);
// The 'context' object is available to store state
// between invocations of the function
// context = {};
//expects JSON payload and destination specified in topic
var key = "your api key here";
//destination will be last part node of topic
var tokens = msg.topic.split("/");
var dest = tokens[tokens.length-1];
/*if(isNaN(dest))
{
//not a valid destination
return null;
}*/
//http://localhost:8086/write?db=greenhouse' --data-binary 'temperature,device=sensor001 value=27.5
msg.url ="http://localhost:8086/write?db=greenhouse";
msg.payload = tokens[2] + ",device=" + tokens[1] + " value=" + msg.payload;
/*msg.url += dest;
msg.url += "&json=";
msg.url += msg.payload;
msg.url += "&apikey=";
msg.url += key;*/
return msg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment