Skip to content

Instantly share code, notes, and snippets.

@azdle
Last active December 18, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azdle/5750587 to your computer and use it in GitHub Desktop.
Save azdle/5750587 to your computer and use it in GitHub Desktop.
Exosite Imp Agents Tests Reads respond with error code 52 (CURLE_GOT_NOTHING)
// Class for Communication to Exosite
class Exosite{
//Set CIK Manually Here or
cik = "654a29f2f230a2810a28036f79ab2fef17c058c4";
// Set Provisioning Parameters to Automatically Generate New CIK
vendor = null;
model = null;
serial = null; // Consider hardware.getimpeeid() or imp.getmacaddress()
constructor(cikp = null, vendorp = null, modelp = null, serialp = null){
if(cikp == null){
server.log("No CIK, need to provision.")
if(vendorp != null, modelp != null, serialp != null){
server.error("Vender, Model, and Serial must be set to provision.")
cik = this.provision();
}
}
}
// Read from Exosite
function read(aliases){
local alias_url_format = "";
foreach(alias in aliases){
alias_url_format = alias_url_format + alias + "&";
}
local response = http.get(
"https://m2.exosite.com/onep:v1/stack/alias?"+alias_url_format,
{"Accept": "application/x-www-form-urlencoded",
"X-Exosite-CIK": cik}).sendsync();
if(response.statuscode == 200 || response.statuscode == 204){
device.send("readrecv", http.urldecode(response.body));
}else{
server.error("Could not read from the OnePlatform. HTTP Response Code: "+response.statuscode)
return null;
}
}
// Write to Exosite
function write(data){
local response = http.post(
"https://m2.exosite.com/onep:v1/stack/alias",
{"Content-Type": "application/x-www-form-urlencoded",
"X-Exosite-CIK": cik},
http.urlencode(data)
).sendsync();
if(response.statuscode != 204 || response.statuscode == 200){
server.error("Could not write to the OnePlatform. HTTP Response Code: "+response.statuscode)
}
}
function provision(){
return null;
}
}
// Setup Exosite Object
exoComms <- Exosite("654a29f2f230a2810a28036f79ab2fef17c058c4");
// Agent 'write' to datasource(s) call.
device.on("write", function(keyValuePairs) {
foreach(alias, value in keyValuePairs){
server.log("Write to "+alias+": "+value);
}
exoComms.write(keyValuePairs);
});
//Agent 'read' from datasource(s) call.
device.on("read", function(aliasArray) {
foreach(alias in aliasArray){
server.log("Read from "+alias+".");
}
local data = exoComms.read(aliasArray);
});
imp.configure("Exosite Test", [], []);
// Local Function Call
function readtest(){
imp.wakeup(10, readtest);
agent.send("read", ["data"]);
}
// Callback for 'read' Call to Agent
function readtestrecv(data){
local datastring = "";
foreach(alias, value in data){
datastring = datastring + " { " + alias + ": " + value + " }, ";
}
server.log("Received Data: " + datastring);
}
// Register with Agent
agent.on("readrecv", readtestrecv);
// Start Reading
readtest();
// End of code.
Mon Jun 10 2013 12:26:37 GMT-0500 (CDT): Downloading new code
Mon Jun 10 2013 12:26:37 GMT-0500 (CDT): Device configured to be "Exosite Test"
Mon Jun 10 2013 12:26:37 GMT-0500 (CDT): Read from data.
Mon Jun 10 2013 12:26:37 GMT-0500 (CDT): Could not read from the OnePlatform. HTTP Response Code: 52
Mon Jun 10 2013 12:26:48 GMT-0500 (CDT): Read from data.
Mon Jun 10 2013 12:26:48 GMT-0500 (CDT): Could not read from the OnePlatform. HTTP Response Code: 52
Mon Jun 10 2013 12:26:58 GMT-0500 (CDT): Read from data.
Mon Jun 10 2013 12:26:59 GMT-0500 (CDT): Could not read from the OnePlatform. HTTP Response Code: 52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment