Skip to content

Instantly share code, notes, and snippets.

@PsyChip PsyChip/app.js
Created Jun 22, 2016

Embed
What would you like to do?
/* global os */
var request = require('sync-request/index.js');
var raspi = require("raspi");
var conf = {
server: "192.168.1.125",
port: "8484",
devid: "200616-004",
debug: true,
const: {
proto: "http",
shtimeout: "3000"
},
services: [
'transmission-daemon'
]
};
function init() {
conf._s = conf.const.proto + '://' + conf.server + ':' + conf.port;
if (conf.debug) {
console.log("disabling console for production, no more messages after this point.");
console.log = function () {};
}
}
console.log("Initializing judithprobe..");
init();
console.log("Launching internal services..");
setInterval(function () {
var start = new Date().getTime();
try {
var packet = {};
packet.thrm = raspi.getThrm();
packet.vcc = raspi.getVcc();
var payload = "";
payload += "id=" + conf.devid;
payload += "|";
payload += "uptime=" + raspi.uptime();
payload += "|";
payload += "thrm=" + packet.thrm;
payload += "|";
payload += "vcc=" + packet.vcc;
payload += "|";
packet.latency = new Date().getTime() - start;
payload += "latc=" + (packet.latency);
var response = request('GET', conf._s + "/c/pushdata/" + payload).getBody().toString();
response = null;
packet = null;
start = null;
payload = null;
} catch (e) {
console.log('[error]: ' + e);
}
}, 1000);
console.log("Launching external services..");
setTimeout(function () {
for (var i = 0; i < conf.services.length; i++) {
console.log("[service]: starting " + conf.services[i]);
raspi.serviceStart(conf.services[i]);
}
}, 3000);
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.