Jump to content

Javascript API callback beim Remote Switch Bricklet


Recommended Posts

Hallo,

 

ich habe ein Problem mit der Javascript API des Remote Switch Bricklet. Laut API sieht die Funktion zum Schalten einer Steckdose Typ B so aus:

BrickletRemoteSwitch.switchSocketB(address, unit, switchTo[, returnCallback][, errorCallback])

.

 

Leider werden die callback Funktionen bei mir nicht aufgerufen, der Code dazu sieht wie folgt aus (Anpassung des node.js Beispiels).

 

var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;
var UID = 'nXN'; // 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) {
        rs.switchSocketB(
            30,
            3,
            Tinkerforge.BrickletRemoteSwitch.SWITCH_TO_ON,
            function() {console.log("Success")},
            function(err) {console.log(err)});
    }
);

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

 

Mache ich etwas falsch oder ist das ein Bug?

 

Beste Grüße,

Jonathan.

Link to comment
Share on other sites

Das ist leider nicht gut genug dokumentiert. Damit du von normalen Settern den Return Callback musst du folgenden Aufruf vor ipcon.Connect() einfügen:

 

rs.setResponseExpected(Tinkerforge.BrickletRemoteSwitch.FUNCTION_SWITCH_SOCKET_B, true);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...