Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Geschrieben

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.

Geschrieben

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);

Geschrieben
  • Autor

Hi Photron,

 

vielen Dank für die Erklärung. Das war zumindest für mich wirklich nicht ersichtlich aus der Doku. Nun geht es :).

 

Beste Grüße,

Jonathan.

Join the conversation

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

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.