Jump to content

UID in Listener


Recommended Posts

Hallo,

gibt es eine Möglichkeit in einem Listener an die UID des auslösenden Bricklets zu kommen ?

Ich würde den Messwert gerne an eine queue weitergeben damit ich aber nachher identifizieren kann aus welchem Sensor das ganze stammt würde ich gerne die UID mitgeben.

                        temp.addListener(new BrickletTemperature.TemperatureListener() {

                            public void temperature(short temperature) {
                                messwert m = new messwert();
                                m.setSensor(null);
                                m.setTime(new Timestamp(System.currentTimeMillis()));
                                m.setWert(temperature / 100.0f);
                                queue.put(m);
                            }
                        });

Link to comment
Share on other sites

Öh, könntest du nicht sowas machen:

 

public static void addTempListener(final String name, BrickletTemperature temp) {
temp.addListener(new BrickletTemperature.TemperatureListener() {
	private final String temp_name = name;

	public void temperature(short temperature) {
		messwert m = new messwert();
		m.setSensor(null);
		m.setTime(new Timestamp(System.currentTimeMillis()));
		m.setWert(temperature / 100.0f);
		queue.put(m);
		System.out.println("name: "  + temp_name);
		System.out.println("Temperature: " + temperature/100.0 + " °C");

	}
});
}

 

und dann aufrufen mit

 

addTempListener("Sensor 1", temp1);
addTempListener("Sensor 2", temp2);

 

(ungetestet)

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...