Initial Commit

This commit is contained in:
2016-03-09 21:35:32 +01:00
commit 4e07942408
72 changed files with 17793 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
var Tinkerforge = require('../tinkerforge')
, Conf = require('./config.json');
var HOST = Conf.host;
var PORT = Conf.port;
var UID = Conf.uid;
var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var ai = new Tinkerforge.BrickletAnalogInV2(UID, ipcon); // Create device object
var radicalChange = false;
var readyForNextNotification = true;
ipcon.connect(HOST, PORT,
function (error) {
console.log('Error: ' + error);
}
); // Connect to brickd
// Don't use device before ipcon is connected
ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED,
function (connectReason) {
// Set period for voltage callback to 1s (1000ms)
// Note: The voltage callback is only called every second
// if the voltage has changed since the last call!
ai.setVoltageCallbackPeriod(1000);
console.log('Host: ' + Conf.host + ':' + Conf.port + ' connected');
}
);
// Register voltage callback
ai.on(Tinkerforge.BrickletAnalogInV2.CALLBACK_VOLTAGE,
// Callback function for voltage callback (parameter has unit mV)
function (voltage) {
var v = voltage/1000.0;
console.log('Voltage: ' + v + ' V');
if(v > 1) {
if(readyForNextNotification) {
radicalChange = true;
readyForNextNotification = false;
setTimeout(function() { readyForNextNotification = true; }, 10000);
} else {
radicalChange = false;
}
} else {
radicalChange = false;
}
if(radicalChange) {
console.log('Hat sich gelohnt!');
}
}
);
console.log('Press key to exit');
process.stdin.on('data',
function (data) {
ipcon.disconnect();
process.exit(0);
}
);
+5
View File
@@ -0,0 +1,5 @@
{
"host": "192.168.2.122",
"port": 4223,
"uid": "vhb"
}