Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Unable to use MQTT Last Will and Testament with dynamic data #5162

Closed
doandzhi opened this issue Feb 28, 2018 · 3 comments · Fixed by #4173
Closed

Unable to use MQTT Last Will and Testament with dynamic data #5162

doandzhi opened this issue Feb 28, 2018 · 3 comments · Fixed by #4173

Comments

@doandzhi
Copy link
Contributor

I am using ESH version 0.9.0 io.transport.mqtt bundle and trying to implement a custom plugin for MQTT. Having a look into the code I saw that it is pretty straightforward and well structured, thanks for this!

One concern of mine is the MQTT Last Will and Testament functionality. Creating an instance of the given class MqttWillAndTestament and passing it to the .setLastWill() method of the MqttBrokerConnection didn't work at all.

Digging into the code of this MqttBrokerConnection class I see that this field is used for building the MqttConnectOptions object in the createMqttOptions(). This object is passed to the .connect() method of org.eclipse.paho.client.mqttv3.MqttAsyncClient later in the MqttBrokerConnection.start().

My headaches start here: When I configure the MqttService for a given brokername and later use its .getBrokerConnection() method passing the corresponding broker name the mentioned things has already happened. Although I get a proper connection and I am able to publish or subscribe using this connection I have no LWT. The problem comes when I have to set this Last Will which by the time of creation of this connection is null. With apologies for my ignorance I ask you for advice/ help.

@davidgraeff Since you are deeply involved in the io.transport.mqtt bundle's implementation I would be very glad if you share your opinion on this one.

@htreu
Copy link
Contributor

htreu commented Mar 1, 2018

Hi @doandzhi,

how do you configure the MQTTService? In case you do it by a service *.cfg file you can use the lwt property to configure Last Will and Testament. Have a look at the MqttWillAndTestament#fromString method for details on the format.

@doandzhi
Copy link
Contributor Author

doandzhi commented Mar 2, 2018

Thanks for the answer @htreu , really appreciated! I was more interested in building the payload with a timestamp and some dynamic data that is not possible to hardcode at the moment. Maybe the best approach is starting the connection 'by hand' and not rely on .getBrokerConnection() at all. Do you have any thoughts on this one?

@doandzhi doandzhi changed the title Unable to use MQTT Last Will and Testament Unable to use MQTT Last Will and Testament with dynamic data Mar 2, 2018
@davidgraeff
Copy link
Contributor

The API needs adjustment. It is a valid Use-case to change the lw even after the session is initiated

davidgraeff pushed a commit to davidgraeff/smarthome that referenced this issue Mar 19, 2018
davidgraeff pushed a commit to davidgraeff/smarthome that referenced this issue Mar 29, 2018
…more.

* Remove name from MqttBrokerConnection. This is only necessary for the MqttService.
  Consumers of MqttBrokerConnection should not be bothered with that detail.
* Remove textConfigured flag. Again this is not interesting for anything outside MqttService.
* Don't parse configuration parameters ourself, but use a configuration values class instead.
* Adapt to Nullable usage.
* Mqtt: Introduce service factory service MqttBrokerConnectionServiceInstance
* ESH compatible implementation of the service factory pattern including a config description for GUIs
* Add MqttService.setLastWill method. Fixes eclipse-archived#5162

Signed-off-by: David Graeff <david.graeff@web.de>
htreu pushed a commit that referenced this issue Mar 29, 2018
…more. (#4173)

* Remove name from MqttBrokerConnection. This is only necessary for the MqttService.
  Consumers of MqttBrokerConnection should not be bothered with that detail.
* Remove textConfigured flag. Again this is not interesting for anything outside MqttService.
* Don't parse configuration parameters ourself, but use a configuration values class instead.
* Adapt to Nullable usage.
* Mqtt: Introduce service factory service MqttBrokerConnectionServiceInstance
* ESH compatible implementation of the service factory pattern including a config description for GUIs
* Add MqttService.setLastWill method. Fixes #5162

Signed-off-by: David Graeff <david.graeff@web.de>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants