Jump to content

Brickv stört callbacks?


Recommended Posts

Hi

Folgendes simple node.js Programm:

var TF = require('tinkerforge');

var HOST = 'myhost';
var PORT = 4223;

var ipcon = new TF.IPConnection();
var masterBrick = new TF.BrickMaster('6esCZX', ipcon);
var tempBricklet = new TF.BrickletTemperature('dCf', ipcon);
var distUSBricklet = new TF.BrickletDistanceUS('nY3', ipcon);

ipcon.connect(HOST, PORT, function(error) {
    console.log("Could not open connection: "+error);        
});

ipcon.on(TF.IPConnection.CALLBACK_CONNECTED, function(connectReason) {
    // Configure Bricklets
    masterBrick.setWifiPowerMode(TF.BrickMaster.WIFI_POWER_MODE_LOW_POWER);
    tempBricklet.setI2CMode(TF.BrickletTemperature.I2C_MODE_SLOW); // to prevent outlier
    tempBricklet.setTemperatureCallbackPeriod(5000);
    distUSBricklet.setMovingAverage(100);
    distUSBricklet.setDistanceCallbackPeriod(5000);
    
});

tempBricklet.on(TF.BrickletTemperature.CALLBACK_TEMPERATURE, function(temp){
    console.log('Temperature: '+temp/100);
}); 

distUSBricklet.on(TF.BrickletDistanceUS.CALLBACK_DISTANCE, function(distance) {
    console.log('Distance: '+distance);
});

 

Alle 5 Sekunden wird Temperatur und US Distanz angegeben.

 

Starte ich nun den Brickv und gehe auf das DistanceUS Brickelt, dann sehe ich in meinem Node.js Program sehr viele und schnell hintereinander folgende Ausgaben:

Temperature: 11.37
Temperature: 11.31
Distance: 1234
Temperature: 11.37
Distance: 1233
Distance: 1234
Distance: 1233
Distance: 1234
Distance: 1233
Distance: 1232
Distance: 1231
Distance: 1232
Distance: 1231
Distance: 1232
Distance: 1231
Distance: 1232
Distance: 1233
Distance: 1232
Distance: 1233
Distance: 1232
Distance: 1231
Distance: 1232
Distance: 1231
Distance: 1232
Distance: 1231
Distance: 1232

 

Warum beeinflusst der Bickv mein node Script? Es sollten doch unterschiedliche IPConnectios sein ?

Link zu diesem Kommentar
Share on other sites

Warum beeinflusst der Bickv mein node Script? Es sollten doch unterschiedliche IPConnectios sein ?

 

Callbacks werden nicht per IP Connection eingestellt, sondern die Callback Einstellungen sind auf dem Brick(let)s und somit global über alle IP Connections hinweg. Daher können sich zwei Programme die die gleichen Callbacks nutzen in die quere kommen.

Link zu diesem Kommentar
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.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...