Last active
December 17, 2015 00:19
-
-
Save xively-gists/5519538 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
const FEED_ID = "FEED_ID_HERE"; | |
const API_KEY = "API_KEY_HERE"; | |
function send_xively(body) { //take in csv value | |
local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".csv"; //setup url for csv | |
server.log(xively_url); | |
server.log(body); //pring body for testing | |
local req = http.put(xively_url, {"X-ApiKey":API_KEY, "Content-Type":"text/csv", "User-Agent":"Xively-Imp-Lib/1.0"}, body); //add headers | |
local res = req.sendsync(); //send request | |
if(res.statuscode != 200) { | |
server.log("error sending message: "+res.body); | |
}else device.send("status", (res.statuscode + " OK")); //sends status to uart. this can be removed if not desired | |
} | |
device.on("data", function(feedCSV) { //take csv body in from device | |
server.log("device on"); | |
//send preformatted multi-ds csv | |
send_xively(feedCSV); //send to function to call xively | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment