Skip to content

Instantly share code, notes, and snippets.

@alexander-daniel
Last active August 29, 2015 13:57
Show Gist options
  • Save alexander-daniel/9454822 to your computer and use it in GitHub Desktop.
Save alexander-daniel/9454822 to your computer and use it in GitHub Desktop.
Espruino POST
var wlan = require("CC3000").connect();
var http = require("http");
var options = {
hostname: 'https://plot.ly/clientresp/',
port: 80,
method: 'POST'
};
wlan.connect( "sw", "nomodernjesus", function (s) {
if (s=="dhcp") {
console.log('wifi connected!');
request();
}
});
var data = [{
x : 0,
y : 1,
type : "scatter",
mode : "markers"
}];
var layout = {
fileopt : "extend",
filename : "Espruino"
};
var payload = {
un : "electricimp",
key : "6hpu3v8jaf",
origin : "plot",
platform : "rest",
args : JSON.stringify(data),
kwargs : JSON.stringify(layout),
version : "0.0.1"
};
function request() {
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write(url.parse(payload));
req.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment