0

I am working with MQTT mosquttio open source code. All was well until I reached where I need to know the client ID from the mosquitto object. Here, I found there is a function which does that "mosquttio_client_id", however this function was missing in my version of mosquitto.lib. Then downloaded complete source code of mosquitto, built it on windows but then came to know it has missing many other functions like "mosquitto_loop_forever". After looked closely to VS solution found these two functions are present in two different projects, and both project outputs are mosquitto.lib.

Any idea on this behavior, how can we build the projects to get all the functions in one "mosquitto.lib"

rahul
  • 59
  • 1
  • 8
  • The question you reference relates to [mosquitto plugins](https://github.com/eclipse/mosquitto/blob/master/include/mosquitto_plugin.h) (auth plugin that mosquitto will call when a new client connects). `mosquitto_loop_forever` is a function in [`libmosquitto`](https://mosquitto.org/api/files/mosquitto-h.html#mosquitto_loop_forever) which is an MQTT client library (so can be used to connect to Mosquitto or other brokers). Please provide additional details re your end goal (are you writing a plugin or just trying to connect?). – Brits Jun 04 '22 at 02:33
  • I am writing a mqtt client to connect with multiple broker. End goal is my c++ application should able to connect with multiple broker and parse the payload. Right now application connected successfully with single broker, but when i want to connect with multiple i need to know from which client id I received this payload. – rahul Jun 04 '22 at 13:00
  • OK with [libmosquitto](https://mosquitto.org/api/files/mosquitto-h.html) when you create a new instance (`mosquitto_new`) you can pass in `obj` "A user pointer that will be passed as an argument to any callbacks that are specified.". That is probably the simplest option (just pass in a pointer to the relevant client id and your callback will have access to it). – Brits Jun 04 '22 at 16:12
  • Yes i am getting that object (mosquitto struct) but to read that object I need to use methods like mosqitto_client_id..which is missing in my mosquitto.lib – rahul Jun 04 '22 at 18:03
  • 1
    No `obj` not `mosq`. See [the docs](https://mosquitto.org/api/files/mosquitto-h.html#mosquitto_subscribe_callback_set) "obj - the user data provided in mosquitto_new". – Brits Jun 04 '22 at 21:26
  • @brits - thanks for that suggestion, it worked. But still I am not sure how to read mosq objects. – rahul Jun 06 '22 at 06:52
  • Why would you need to? `mosq` is an internal library structure; if the author intended you to access its members then it would be fully defined in `mosquitto.h`. If you really want to see what is in the structure then [look here](https://github.com/eclipse/mosquitto/blob/master/lib/mosquitto_internal.h#L215). – Brits Jun 06 '22 at 08:14

0 Answers0