Merged
Merge Request #8 · created by Steven de Ridder


added LWT ( last will & testament ) option to mqtt connect.

added support for a last will & testament message. LWT settings are not required for connection, but can be provided as optional parameter when calling the mqttclient connect function. ( see publisher test case ). The parameters to be added are the topic to publish on and the message to be published in case of a connection disruption.


From feat/sridder/will_set into development

Merged by Peter M. Groen

Source branch has been removed
2 participants
    Steven de Ridder started a discussion on the diff
    last updated by Steven de Ridder
    examples/pub/publisher.cpp
    29 29  
    30 30 }
    31 31  
    32   -void Publisher::connect( const std::string &hostname, int portnumber, const std::string &username, const std::string &password )
      32 +void Publisher::connect(const std::string &hostname, int portnumber, const std::string &username, const std::string &password, const std::string &lwt_topic, const std::string &lwt_message)
    1
    Peter M. Groen started a discussion on the outdated diff
    last updated by Peter M. Groen
    examples/pub/publisher.cpp
    29 29  
    30 30 }
    31 31  
    32   -void Publisher::connect( const std::string &hostname, int portnumber, const std::string &username, const std::string &password )
      32 +void Publisher::connect(const std::string &hostname, int portnumber, const std::string &username, const std::string &password, const std::string &topic, const std::string &message)
    1
    • Peter M. Groen @pgroen

      I would prefer if these parameters had a prefix with "lwt" to distinguish them from "normal" mqtt messages during publish and subscribe..

      Edit in fullscreen
      Comments are parsed with GitLab Flavored Markdown
      Attach files by dragging & dropping or selecting them.
    Steven de Ridder started a discussion on the diff
    last updated by Steven de Ridder
    examples/pub/publisher.h
    36 36  
    37 37 virtual ~Publisher() {}
    38 38  
    39   - void connect( const std::string &hostname, int portnumber = 1883, const std::string &username = std::string(), const std::string &password = std::string() );
      39 + void connect( const std::string &hostname, int portnumber = 1883, const std::string &username = std::string(), const std::string &password = std::string()
      40 + , const std::string &lwt_topic = std::string(), const std::string &lwt_message = std::string() );
    1
    Peter M. Groen started a discussion on the outdated diff
    last updated by Peter M. Groen
    examples/pub/publisher.h
    36 36  
    37 37 virtual ~Publisher() {}
    38 38  
    39   - void connect( const std::string &hostname, int portnumber = 1883, const std::string &username = std::string(), const std::string &password = std::string() );
      39 + void connect( const std::string &hostname, int portnumber = 1883, const std::string &username = std::string(), const std::string &password = std::string()
      40 + , const std::string &topic = std::string(), const std::string &message = std::string() );
    1
    Steven de Ridder started a discussion on the diff
    last updated by Steven de Ridder
    include/imqttclient.h
    59 60 * @param port The port to use.
    60 61 * @param credentials The credentials to use.
    61 62 */
    62   - virtual void connect(const std::string& host, int port, const Credentials& credentials) = 0;
      63 + virtual void connect(const std::string& host, int port, const Credentials& credentials, const mqtt_LWT &lwt = mqtt_LWT() ) = 0;
    1
    Peter M. Groen started a discussion on the outdated diff
    last updated by Peter M. Groen
    include/imqttclient.h
    59 60 * @param port The port to use.
    60 61 * @param credentials The credentials to use.
    61 62 */
    62   - virtual void connect(const std::string& host, int port, const Credentials& credentials) = 0;
      63 + virtual void connect(const std::string& host, int port, const Credentials& credentials, const mqtt_LWT &lvt = mqtt_LWT() ) = 0;
    1
    Steven de Ridder started a discussion on the diff
    last updated by Steven de Ridder
    include/imqttclient.h
    59 60 * @param port The port to use.
    60 61 * @param credentials The credentials to use.
    61 62 */
    62   - virtual void connect(const std::string& host, int port, const Credentials& credentials) = 0;
      63 + virtual void connect(const std::string& host, int port, const Credentials& credentials, const mqtt_LWT &lwt = mqtt_LWT() ) = 0;
    63 64  
    64 65 /**
    65 66 * @brief Connect to the endpoint
    66 67 * @param endpoint an uri endpoint description.
    67 68 */
    68   - virtual void connect(const std::string& endpoint) = 0;
      69 + virtual void connect(const std::string& endpoint, const mqtt_LWT &lwt = mqtt_LWT() ) = 0;
    1
    Peter M. Groen started a discussion on the outdated diff
    last updated by Peter M. Groen
    include/imqttclient.h
    59 60 * @param port The port to use.
    60 61 * @param credentials The credentials to use.
    61 62 */
    62   - virtual void connect(const std::string& host, int port, const Credentials& credentials) = 0;
      63 + virtual void connect(const std::string& host, int port, const Credentials& credentials, const mqtt_LWT &lvt = mqtt_LWT() ) = 0;
    63 64  
    64 65 /**
    65 66 * @brief Connect to the endpoint
    66 67 * @param endpoint an uri endpoint description.
    67 68 */
    68   - virtual void connect(const std::string& endpoint) = 0;
      69 + virtual void connect(const std::string& endpoint, const mqtt_LWT &lvt = mqtt_LWT() ) = 0;
    1
    Steven de Ridder started a discussion on the diff
    last updated by Steven de Ridder
    include/mqttclient.h
    91 92 /**
    92 93 * @see IMqttClient
    93 94 */
    94   - virtual void connect(const std::string& host, int port, const Credentials& credentials) override;
      95 + virtual void connect( const std::string& host, int port, const Credentials &credentials, const mqtt_LWT &lwt = mqtt_LWT() ) override;
    1
    Peter M. Groen started a discussion on the outdated diff
    last updated by Peter M. Groen
    include/mqttclient.h
    91 92 /**
    92 93 * @see IMqttClient
    93 94 */
    94   - virtual void connect(const std::string& host, int port, const Credentials& credentials) override;
      95 + virtual void connect( const std::string& host, int port, const Credentials &credentials, const mqtt_LWT &lvt = mqtt_LWT() ) override;
    1
  • Peter M. Groen @pgroen

    Please fix the comments on the code and add the following :

    • If a connection was made and the connection is lost ( e.g. the network connection is disabled ) the LWT needs to get published.
    • If the connection is restored, make sure data is being send again.
    • Again, disable the network connection and check to see if the LWT is again being published. If not, make sure it gets re-issued if a connection is restored. The LWT needs to be stored in a member-variable of clientpaho...
    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Peter M. Groen @pgroen

    Reassigned to @sridder

    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Steven de Ridder @sridder

    Added 1 commit:

    • 8f3a48db - fixed minor typos and changed the parameters to be more clear
    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Steven de Ridder @sridder

    Added 1 commit:

    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Steven de Ridder @sridder

    fixed the code relevant to the comments. looking into the connection issues now.

    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Steven de Ridder @sridder

    Reassigned to @pgroen

    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Steven de Ridder @sridder

    LWT is correctly published on connection interruption. date is picked up again once connection is restored and LWT is also published again once interrupted again.

    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Peter M. Groen @pgroen

    Tested and looking good. Merging to Development and Master

    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Peter M. Groen @pgroen
    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.
  • Peter M. Groen @pgroen

    Status changed to merged

    Edit in fullscreen
    Comments are parsed with GitLab Flavored Markdown
    Attach files by dragging & dropping or selecting them.