var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'jKy'; // Change to your UID

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var rs = new Tinkerforge.BrickletRemoteSwitch(UID, ipcon); // Create device object

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) {
        // Switch on a type A socket with house code 17 and receiver code 1.
        // House code 17 is 10001 in binary (least-significant bit first)
        // and means that the DIP switches 1 and 5 are on and 2-4 are off.
        // Receiver code 1 is 10000 in binary (least-significant bit first)
        // and means that the DIP switch A is on and B-E are off.
        rs.switchSocketA(17, 1, Tinkerforge.BrickletRemoteSwitch.SWITCH_TO_ON);
    }
);

console.log("Press any key to exit ...");
process.stdin.on('data',
    function(data) {
        ipcon.disconnect();
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Dust Detector Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var dd = new Tinkerforge.BrickletDustDetector(UID, ipcon); // Create device object

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) {
        // Get current dust density
        dd.getDustDensity(
            function (dustDensity) {
                console.log('Dust Density: ' + dustDensity + ' µg/m³');
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');
 function (data) {
     ipcon.disconnect();
     process.exit(0);
 }
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Distance US Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var dus = new Tinkerforge.BrickletDistanceUS(UID, ipcon); // Create device object

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) {
        // Get current distance value
        dus.getDistanceValue(
            function (distance) {
                console.log('Distance Value: ' + distance);
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Barometer Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var b = new Tinkerforge.BrickletBarometer(UID, ipcon); // Create device object

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) {
        // Get threshold callbacks with a debounce time of 10 seconds (10000ms)
        b.setDebouncePeriod(10000);

        // Configure threshold for air pressure "greater than 1025 mbar"
        b.setAirPressureCallbackThreshold('>', 1025*1000, 0);
    }
);

// Register air pressure reached callback
b.on(Tinkerforge.BrickletBarometer.CALLBACK_AIR_PRESSURE_REACHED,
    // Callback function for air pressure reached callback
    function (airPressure) {
        console.log('Air Pressure: ' + airPressure/1000.0 + ' mbar');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Distance US Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var dus = new Tinkerforge.BrickletDistanceUS(UID, ipcon); // Create device object

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 distance value callback to 0.2s (200ms)
        // Note: The distance value callback is only called every 0.2 seconds
        //       if the distance value has changed since the last call!
        dus.setDistanceCallbackPeriod(200);
    }
);

// Register distance value callback
dus.on(Tinkerforge.BrickletDistanceUS.CALLBACK_DISTANCE,
    // Callback function for distance value callback
    function (distance) {
        console.log('Distance Value: ' + distance);
    }
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var SECRET = 'My Authentication Secret!';

ipcon = new Tinkerforge.IPConnection(); // Create IP connection
ipcon.connect(HOST, PORT,
    function(error) {
        console.log('Error: '+error);
    }
); // Connect to brickd

// Disable auto reconnect mechanism, in case we have the wrong secret.
// If the authentication is successful, reenable it.
ipcon.setAutoReconnect(false);

// Register Connected Callback
ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED,
    // Authenticate each time the connection got (re-)established
    function(connectReason) {
        switch(connectReason) {
        case Tinkerforge.IPConnection.CONNECT_REASON_REQUEST:
            console.log('Connected by request');
            break;
        case Tinkerforge.IPConnection.CONNECT_REASON_AUTO_RECONNECT:
            console.log('Auto-Reconnected');
            break;
        }
        ipcon.authenticate(SECRET,
            function() {
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Joystick Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var j = new Tinkerforge.BrickletJoystick(UID, ipcon); // Create device object

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) {
        // Get threshold callbacks with a debounce time of 0.2 seconds (200ms)
        j.setDebouncePeriod(200);

        // Configure threshold for position "outside of -99, -99 to 99, 99"
        j.setPositionCallbackThreshold('o', -99, 99, -99, 99);
    }
);

// Register position reached callback
j.on(Tinkerforge.BrickletJoystick.CALLBACK_POSITION_REACHED,
    // Callback function for position reached callback
    function (x, y) {
        if(y === 100) {
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your OLED 64x48 Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var oled = new Tinkerforge.BrickletOLED64x48(UID, ipcon); // Create device object

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) {
        // Clear display
        oled.clearDisplay();

        // Write "Hello World" starting from upper left corner of the screen
        oled.writeLine(0, 0, 'Hello World');
    }
);

console.log('Press key to exit');
process.stdin.on('data',
    function (data) {
        ipcon.disconnect();
        process.exit(0);
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Rotary Encoder Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var re = new Tinkerforge.BrickletRotaryEncoder(UID, ipcon); // Create device object

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) {
        // Get current count without reset
        re.getCount(false,
            function (count) {
                console.log('Count: ' + count);
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = '7bA'; // Change to your UID

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var h = new Tinkerforge.BrickletHumidity(UID, ipcon); // Create device object

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 rh callback to 1s (1000ms)
        // Note: The callback is only called every second if the
        // humidity has changed since the last call!
        h.setHumidityCallbackPeriod(1000);
    }
);

// Register humidity callback
h.on(Tinkerforge.BrickletHumidity.CALLBACK_HUMIDITY,
    // Callback function for humidity callback (parameter has unit %RH/10)
    function(humidity) {
        console.log('Relative Humidity: '+humidity/10+' %RH');
    }
Beispiel #12
0
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XXYYZZ'; // Change XXYYZZ to the UID of your IMU Brick

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var imu = new Tinkerforge.BrickIMU(UID, ipcon); // Create device object

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) {
        // Get current quaternion
        imu.getQuaternion(
            function (x, y, z, w) {
                console.log('Quaternion [X]: ' + x);
                console.log('Quaternion [Y]: ' + y);
                console.log('Quaternion [Z]: ' + z);
                console.log('Quaternion [W]: ' + w);
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Voltage Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var v = new Tinkerforge.BrickletVoltage(UID, ipcon); // Create device object

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) {
        // Get current voltage
        v.getVoltage(
            function (voltage) {
                console.log('Voltage: ' + voltage/1000.0 + ' V');
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'jmQ'; // Change to your UID

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var b = new Tinkerforge.BrickletBarometer(UID, ipcon); // Create device object

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 air pressure and altitude callbacks to 1s (1000ms)
        // Note: The air pressure and altitude callbacks are only called every second
        // if the air pressure or altitude has changed since the last call!
        b.setAirPressureCallbackPeriod(1000);
        b.setAltitudeCallbackPeriod(1000);
    }
);

// Register air pressure callback
b.on(Tinkerforge.BrickletBarometer.CALLBACK_AIR_PRESSURE,
    // Callback function for air pressure callback (parameter has unit mbar/1000)
    function(ap) {
        console.log('Air pressure: '+ap/1000+' mbar');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'ek5'; // Change to your UID

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var poti = new Tinkerforge.BrickletRotaryPoti(UID, ipcon); // Create device object

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) {
        // Get current position of poti (return value has range -150 to 150)
        poti.getPosition(
            function(position) {
                console.log('Position: '+position);
            },
            function(error) {
                console.log('Error: '+error);
            }
        );
    }
);

console.log("Press any key to exit ...");
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Sound Intensity Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var si = new Tinkerforge.BrickletSoundIntensity(UID, ipcon); // Create device object

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) {
        // Get threshold callbacks with a debounce time of 1 second (1000ms)
        si.setDebouncePeriod(1000);

        // Configure threshold for intensity "greater than 2000"
        si.setIntensityCallbackThreshold('>', 2000, 0);
    }
);

// Register intensity reached callback
si.on(Tinkerforge.BrickletSoundIntensity.CALLBACK_INTENSITY_REACHED,
    // Callback function for intensity reached callback
    function (intensity) {
        console.log('Intensity: ' + intensity);
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Current25 Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var c = new Tinkerforge.BrickletCurrent25(UID, ipcon); // Create device object

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) {
        // Get threshold callbacks with a debounce time of 10 seconds (10000ms)
        c.setDebouncePeriod(10000);

        // Configure threshold for current "greater than 5 A"
        c.setCurrentCallbackThreshold('>', 5*1000, 0);
    }
);

// Register current reached callback
c.on(Tinkerforge.BrickletCurrent25.CALLBACK_CURRENT_REACHED,
    // Callback function for current reached callback
    function (current) {
        console.log('Current: ' + current/1000.0 + ' A');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your PTC Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var ptc = new Tinkerforge.BrickletPTC(UID, ipcon); // Create device object

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) {
        // Get current temperature
        ptc.getTemperature(
            function (temperature) {
                console.log('Temperature: ' + temperature/100.0 + ' °C');
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Ambient Light Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var al = new Tinkerforge.BrickletAmbientLight(UID, ipcon); // Create device object

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) {
        // Get current illuminance
        al.getIlluminance(
            function (illuminance) {
                console.log('Illuminance: ' + illuminance/10.0 + ' lx');
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Tilt Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var t = new Tinkerforge.BrickletTilt(UID, ipcon); // Create device object

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) {
        // Get current tilt state
        t.getTiltState(
            function (state) {
                if(state === Tinkerforge.BrickletTilt.TILT_STATE_CLOSED) {
                    console.log('Tilt State: Closed');
                }
                else if(state === Tinkerforge.BrickletTilt.TILT_STATE_OPEN) {
                    console.log('Tilt State: Open');
                }
                else if(state === Tinkerforge.BrickletTilt.TILT_STATE_CLOSED_VIBRATING) {
                    console.log('Tilt State: Closed Vibrating');
                }
            },
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Tilt Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var t = new Tinkerforge.BrickletTilt(UID, ipcon); // Create device object

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) {
        // Enable tilt state callback
        t.enableTiltStateCallback();
    }
);

// Register tilt state callback
t.on(Tinkerforge.BrickletTilt.CALLBACK_TILT_STATE,
    // Callback function for tilt state callback
    function (state) {
        if(state === Tinkerforge.BrickletTilt.TILT_STATE_CLOSED) {
            console.log('Tilt State: Closed');
        }
        else if(state === Tinkerforge.BrickletTilt.TILT_STATE_OPEN) {
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XXYYZZ'; // Change XXYYZZ to the UID of your DC Brick

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var dc = new Tinkerforge.BrickDC(UID, ipcon); // Create device object

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) {
        dc.setDriveMode(Tinkerforge.BrickDC.DRIVE_MODE_DRIVE_COAST);
        dc.setPWMFrequency(10000); // Use PWM frequency of 10kHz
        dc.setAcceleration(5000); // Slow acceleration
        dc.setVelocity(32767); // Full speed forward
        dc.enable(); // Enable motor power
    }
);

console.log('Press key to exit');
process.stdin.on('data',
    function (data) {
        dc.disable(); // Disable motor power
        ipcon.disconnect();
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Sound Intensity Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var si = new Tinkerforge.BrickletSoundIntensity(UID, ipcon); // Create device object

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) {
        // Get current intensity
        si.getIntensity(
            function (intensity) {
                console.log('Intensity: ' + intensity);
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');
 function (data) {
     dc.disable(); // Disable motor power
     ipcon.disconnect();
     process.exit(0);
 }
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Industrial Digital Out 4 Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var ido4 = new Tinkerforge.BrickletIndustrialDigitalOut4(UID, ipcon); // Create device object

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 pins alternating high/low 10 times with 100ms delay
        for(var i = 0; i < 10; ++i) {
            setTimeout(function () {
                ido4.setValue(1 << 0);
            }, 400 * i + 100);
            setTimeout(function () {
                ido4.setValue(1 << 1);
            }, 400 * i + 200);
            setTimeout(function () {
                ido4.setValue(1 << 2);
            }, 400 * i + 300);
            setTimeout(function () {
                ido4.setValue(1 << 3);
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Piezo Speaker Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var ps = new Tinkerforge.BrickletPiezoSpeaker(UID, ipcon); // Create device object

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) {
        // Morse SOS with a frequency of 2kHz
        ps.morseCode('... --- ...', 2000);
    }
);

console.log('Press key to exit');
process.stdin.on('data',
    function (data) {
        ipcon.disconnect();
        process.exit(0);
    }
);
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Ambient Light Bricklet 2.0

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var al = new Tinkerforge.BrickletAmbientLightV2(UID, ipcon); // Create device object

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 illuminance callback to 1s (1000ms)
        // Note: The illuminance callback is only called every second
        //       if the illuminance has changed since the last call!
        al.setIlluminanceCallbackPeriod(1000);
    }
);

// Register illuminance callback
al.on(Tinkerforge.BrickletAmbientLightV2.CALLBACK_ILLUMINANCE,
    // Callback function for illuminance callback
    function (illuminance) {
        console.log('Illuminance: ' + illuminance/100.0 + ' lx');
    }
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Industrial Digital In 4 Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var idi4 = new Tinkerforge.BrickletIndustrialDigitalIn4(UID, ipcon); // Create device object

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) {
        // Get current value as bitmask
        idi4.getValue(
            function (valueMask) {
                console.log('Value Mask: ' + valueMask.toString(2));
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Dual Button Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var db = new Tinkerforge.BrickletDualButton(UID, ipcon); // Create device object

ipcon.connect(HOST, PORT,
    function (error) {
        console.log('Error: ' + error);
    }
); // Connect to brickd
// Don't use device before ipcon is connected

// Register state changed callback
db.on(Tinkerforge.BrickletDualButton.CALLBACK_STATE_CHANGED,
    // Callback function for state changed callback
    function (buttonL, buttonR, ledL, ledR) {
        if(buttonL === Tinkerforge.BrickletDualButton.BUTTON_STATE_PRESSED) {
            console.log('Left Button: Pressed');
        }
        else if(buttonL === Tinkerforge.BrickletDualButton.BUTTON_STATE_RELEASED) {
            console.log('Left Button: Released');
        }

        if(buttonR === Tinkerforge.BrickletDualButton.BUTTON_STATE_PRESSED) {
            console.log('Right Button: Pressed');
        }
        else if(buttonR === Tinkerforge.BrickletDualButton.BUTTON_STATE_RELEASED) {
var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'XYZ'; // Change XYZ to the UID of your Moisture Bricklet

var ipcon = new Tinkerforge.IPConnection(); // Create IP connection
var m = new Tinkerforge.BrickletMoisture(UID, ipcon); // Create device object

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) {
        // Get current moisture value
        m.getMoistureValue(
            function (moisture) {
                console.log('Moisture Value: ' + moisture);
            },
            function (error) {
                console.log('Error: ' + error);
            }
        );
    }
);

console.log('Press key to exit');