/app.js Secret
Created
February 10, 2019 14:49
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
const https = require("https"); | |
const http = require("http"); | |
http.createServer(function (request, response) { | |
response.writeHead(200, {'Content-Type': 'application/json'}); | |
const req = https.request('https://xxxxxxxxxxxxx.com/data.json', (res) => { | |
console.log(`STATUS: ${res.statusCode}`); | |
console.log(`HEADERS: ${JSON.stringify(res.headers)}`); | |
res.setEncoding('utf8'); | |
res.on('data', (chunk) => { | |
const data = JSON.parse(chunk); | |
const sensors = []; | |
for (const id in data.readings) { | |
const sensor = {}; | |
const sourceSensor = data.sensors[id]; | |
sensor.label = sourceSensor.label; | |
const readings = data.readings[id]; | |
for (const k of ["hum_temp", "stamp", "hum_hum", "lux", "bar_pres_rel", "vbat", "vreg", "id"]) { | |
if (k === 'stamp') { | |
sensor[k] = readings[k] * 1000 | |
} else { | |
sensor[k] = readings[k] | |
} | |
} | |
sensors.push(sensor); | |
} | |
response.end(JSON.stringify(sensors)); | |
}); | |
res.on('end', () => { | |
console.log('No more data in response.'); | |
}); | |
}); | |
req.end(); | |
}).listen(8081); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment