Skip to content

Instantly share code, notes, and snippets.

@nicolsc
Created December 15, 2022 08:39
Show Gist options
  • Save nicolsc/5798f520da82bdfbbf0dadac0313c128 to your computer and use it in GitHub Desktop.
Save nicolsc/5798f520da82bdfbbf0dadac0313c128 to your computer and use it in GitHub Desktop.
{
"celsius": 25,
"farenheit": 75,
"kelvin": 300
}
'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