This file contains hidden or 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 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); | |
This file contains hidden or 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
| 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) { |
This file contains hidden or 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
| agent.on("json", function(value) { //receive data from agent | |
| server.log("agent is on"); | |
| //server.log(value); //uncomment to print the data first | |
| hardware.uart57.write("\n" + value); //write data to UART | |
| }); |
This file contains hidden or 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
| local index = 0; | |
| local masterUART = array(100); //serial buffer | |
| //these should be changed to non character values | |
| local startbit = 124; //which is | | |
| local endbit = 126; //which is ~ | |
| //uart initialization | |
| function startUART() | |
| { | |
| hardware.configure(UART_57); | |
| hardware.uart57.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS); //baud:19200, dataBits:8, parity, stopbit |
This file contains hidden or 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); |
NewerOlder