Skip to content

Instantly share code, notes, and snippets.

@xively-gists
Last active December 17, 2015 00:18
Show Gist options
  • Save xively-gists/5519557 to your computer and use it in GitHub Desktop.
Save xively-gists/5519557 to your computer and use it in GitHub Desktop.
function get_xively() {
//wakeup
imp.wakeup(30.0, get_xively); //schedule when to wakeup again
local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".json"; //format xively url
server.log(xively_url);
local getreq = http.get(xively_url, {"X-ApiKey":API_KEY, "User-Agent":"xively-Imp-Lib/1.0"}); //add headers
local res = getreq.sendsync(); //actuallty send request
if(res.statuscode != 200) {
server.log("error sending message: " + res.body);
}
server.log("#####RESPONSE#####");
server.log(res.statuscode + " OK"); //status
server.log(res.body); //body
//format data into table - uncomment to use
// local resTable = http.jsondecode(res.body);
// server.log("table:");
// server.log(resTable.title);
// server.log(resTable.id);
// //print ds0
// server.log(resTable.datastreams[0].id);
// server.log(resTable.datastreams[0].current_value + " at " + resTable.datastreams[0].at);
//send to device
//device.send("value", resTable.datastreams[0].current_value); //send custom data from table
device.send("json", res.body); //send json
}
get_xively(); //initialize first get request. will continue to call itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment