-
-
Save theojulienne/7286382 to your computer and use it in GitHub Desktop.
This file contains 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
'use strict'; | |
var url = require('url'); | |
var creds = require('./creds.js'); | |
var https = require('https'); | |
var scheme = 'https'; | |
var hostname = 'api.tempo-db.com'; | |
var baseUrl = scheme + '://' + hostname; | |
var auth = 'Basic ' + new Buffer(creds.key + ':' + creds.secret).toString('base64'); | |
var seriesKey = '1_D90343085872CA9C_687_0_2000'; | |
var myAgent = new https.Agent({keepAlive: true}); // undocumented magic | |
function uploadEntry(cb){ | |
var data = []; | |
data.push({t: new Date(), v: Math.random() * 50}); | |
var body = JSON.stringify(data); | |
var headers = { | |
Authorization: auth, | |
'Content-Type': 'application/json', | |
'Content-Length': body.length, | |
'Connection': 'keep-alive' | |
}; | |
var opts = { | |
host: hostname, | |
port: 443, | |
path: '/v1/series/key/' + seriesKey + '/data/', | |
method: 'POST', | |
agent: myAgent, | |
headers: headers | |
}; | |
// console.log('sending', data[0]); | |
var req = https.request(opts,cb); | |
req.on('error', function(e) { | |
console.err('error', e); | |
}); | |
req.write(body); | |
req.end(); | |
}; | |
function callback(result){ | |
console.log('statusCode', result.statusCode); | |
result.on('data', function (chunk) {}); // consume so we don't leak sockets | |
} | |
setInterval(uploadEntry.bind(null, callback), 1000); | |
setInterval(gc, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment