Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* global console */
/* global require */
var tessel = require('tessel');
var http = require('http');
var mainLoop = function() {
var options = {
hostname: '192.168.1.106',
port: 3000,
path: '/sensor_readings',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
};
var data = {temperature_f: 100.0};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function () {
console.log('Response received.');
});
res.on('end', function(){
// after the request is finished, loop again
setTimeout(mainLoop, 5000);
});
});
req.on('error', function(e) {
console.log('problem with request: ', e.message);
// on error loop again
setTimeout(mainLoop, 5000);
});
req.write(JSON.stringify({secret_token: 'cookie', sensor_reading: data}));
console.log('Pushed data.');
req.end();
};
console.log('Tessel started!');
setImmediate(mainLoop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.