Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const FEED_ID = "";
- const API_KEY = "";
- function send_xively(data){
- /* A JSON request is composed of URL, headers and body. Use one line for each. */
- local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".json"; //format xively url
- local headers = {"X-ApiKey":API_KEY, "Content-Type":"application/json", "User-Agent":"xively-Imp-Lib/1.0"};
- local body = http.jsonencode(data);
- // server.log(body);
- /* send data to your web service */
- local response = http.put(xively_url, headers, body).sendsync();
- if(response.statuscode != 200) {
- server.log("error sending message: " + response.body);
- }
- // server.log("#####RESPONSE#####");
- // server.log(response.statuscode + " OK"); //status
- // server.log(response.body); //body
- }
- /** Prepares to send to Xively */
- device.on("accessLog", function(s){
- local dataToSend = {
- version = "1.0.0",
- datastreams = [
- {
- id = "AccessLog",
- current_value = s
- }
- ]
- }
- send_xively(dataToSend);
- });
- /** Prepares to send to Xively */
- device.on("unlockedLog", function(s){
- local dataToSend = {
- version = "1.0.0",
- datastreams = [
- {
- id = "UnlockedLog",
- current_value = s
- }
- ]
- }
- send_xively(dataToSend);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement