Created
June 22, 2016 23:43
-
-
Save PsyChip/0e656874659aa51ba39023b690b6528b to your computer and use it in GitHub Desktop.
visit http://psychip.net/entry/raspberry-pi-as-wireless-torrent-box for description
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
/* 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