Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last Will not working? #1990

Closed
SCHoschY opened this issue May 6, 2024 · 2 comments
Closed

Last Will not working? #1990

SCHoschY opened this issue May 6, 2024 · 2 comments
Labels
question It is a question regarding the project

Comments

@SCHoschY
Copy link

SCHoschY commented May 6, 2024

Describe your question

Im Currently testing LW and cant get it working.

Which project is your question related to?

  • Client

Im currently testing with this example
I have extended the Optionsbuilder for credentials and last will. The credentials are working fine, but LW seems to not work.

        string topicLW = "test/LW";
        string messageLW = "Cya, im gone";

        ...
        var options = new MqttClientOptionsBuilder()
                          .WithClientId(clientId)
                          .WithTcpServer(broker, port)
                          .WithCredentials(username, password)
                          .WithCleanSession()
                          .WithKeepAlivePeriod(TimeSpan.FromSeconds(30)) 
                          //.WithWillDelayInterval(10) -> Im Using 3.1 - not implemented
                          .WithWillQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce)
                          .WithWillRetain(true)
                          .WithWillTopic(topicLW)
                          .WithWillPayload(messageLW)
                          .Build();

Am i missing a OptionsBuilder parameter or is something off in general?


The program sends 0-9 with these OptionsBuilder settings, but my "test/LW" topic does not get changed.

Im also Testing with Retained and clearing - noted here, to explain the 3rd screenshots with "missing" topic ;)

Initial Subscription
image

in the middle of my test-run:
image

10 min. after the test:
image

if i test it with another subscriber i get the same result:

run 1

schoschy@NB105:~$ mosquitto_sub -t test/LW -h 192.168.42.6

run 2 to verify that the normal messages do work

schoschy@NB105:~$ mosquitto_sub -t test/csharp -h 192.168.42.6
Hello, MQTT! Message number 0
Hello, MQTT! Message number 1
Hello, MQTT! Message number 2
Hello, MQTT! Message number 3
Hello, MQTT! Message number 4
Hello, MQTT! Message number 5
Hello, MQTT! Message number 6
Hello, MQTT! Message number 7
Hello, MQTT! Message number 8
Hello, MQTT! Message number 9

a Wireshark trace seems to be okay aswell.

Other applications of mine do offer a working LW retained message

schoschy@NB105:~$ mosquitto_sub -t Availability/Webio-20 -h 192.168.42.6 -v
Availability/Webio-20 Online
+pulled Eth Cable
Availability/Webio-20 Offline
+linked Eth Cable
Availability/Webio-20 Online

i did start a test-instance of mosquitto to check if there are problems with my Test-broker, that did also not help.


Thanks for your help and have a nice week

Schoschy

@SCHoschY SCHoschY added the question It is a question regarding the project label May 6, 2024
@chkr1011
Copy link
Collaborator

In the sample the client gets disconnected properly by calling DisconnectAsync. This will indicate a clean disconnect. The last will ist only published if the client is disconnected in a non clean way.

This means losing network connection or a crashing application. You can also try to make in non clean by avoiding the call of DisconnectAsync and instead calling Dispose. Or you simply close your application 😄

@SCHoschY
Copy link
Author

I did test that behaviour and came to the same conclusion this weekend.

Working for years with MQTT applications that run 24/7 i never noticed that the LW is only triggered on an ungracefull disconnect, because i do only get those. :)

Thanks for the reminder!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question It is a question regarding the project
Projects
None yet
Development

No branches or pull requests

2 participants