Created
December 15, 2022 08:39
-
-
Save nicolsc/5798f520da82bdfbbf0dadac0313c128 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
{ | |
"celsius": 25, | |
"farenheit": 75, | |
"kelvin": 300 | |
} |
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'; | |
const fs = require('fs'); | |
const http = require('http'); | |
const delayInMillisecond = 5000; | |
var body; | |
//Main loop | |
setInterval(() => { | |
fs.readFile('telemetry.json', (err, data) => { | |
if (err) throw err; | |
let telemetry = JSON.parse(data); | |
body = JSON.stringify(telemetry) | |
console.log(`Sending data to Harvest: ${body}`) | |
let options = { | |
hostname: "harvest.soracom.io", | |
path: "/", | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
"Content-Length": Buffer.byteLength(body) | |
} | |
} | |
http | |
.request(options, res => { | |
let data = "" | |
res.on("data", d => { | |
data += d | |
}) | |
res.on("end", () => { | |
console.log(`Sending complete: ${data}`) | |
}) | |
}) | |
.on("error", () => { | |
console.log(`Error sending data: ${console.error}`) | |
}) | |
.end(body) | |
}); | |
}, delayInMillisecond) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment