Giter VIP home page Giter VIP logo

Comments (1)

LiamBindle avatar LiamBindle commented on May 28, 2024

Yeah, no problem. The 8th argument to mqtt_connect are the connect flags. These flags are enumerated in enum MQTTConnectFlags on line 587 of mqtt.h.

MQTT-C/include/mqtt.h

Lines 587 to 597 in dc96097

enum MQTTConnectFlags {
MQTT_CONNECT_RESERVED = 1u,
MQTT_CONNECT_CLEAN_SESSION = 2u,
MQTT_CONNECT_WILL_FLAG = 4u,
MQTT_CONNECT_WILL_QOS_0 = (0u & 0x03) << 3,
MQTT_CONNECT_WILL_QOS_1 = (1u & 0x03) << 3,
MQTT_CONNECT_WILL_QOS_2 = (2u & 0x03) << 3,
MQTT_CONNECT_WILL_RETAIN = 32u,
MQTT_CONNECT_PASSWORD = 64u,
MQTT_CONNECT_USER_NAME = 128u,
};

For example, if you want to set "clean session" you would pass MQTT_CONNECT_CLEAN_SESSION as the 8th argument to mqtt_connect.

If you want to set multiple flags, for example, "clean session" and a will with QoS level 2, you would pass MQTT_CONNECT_CLEAN_SESSION | MQTT_CONNECT_WILL | MQTT_CONNECT_WILL_QOS_2.


It should be noted that the following flags are the only flags that need to be set explicitly:

  • MQTT_CONNECT_CLEAN_SESSION
  • MQTT_CONNECT_WILL_QOS_X
  • MQTT_CONNECT_WILL_RETAIN

All the other flags are automatically determined based on the arguments to mqtt_connect (for example if the user_name argument is not NULL then MQTT-C will automatically set MQTT_CONNECT_USER_NAME). This means that in the multi-flag example given above the MQTT_CONNECT_WILL is not mandatory as is automatically set when will_topic and will_message are not NULL.


Does this clarify things?

Regards,

Liam

from mqtt-c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.