Eclipse Paho MQTT C Client APIs
MQTT C Client API Reference
MQTTClient_create
Creates a new MQTT client object. This client is used to connect to a broker and perform publish/subscribe
operations.
Signature:
int MQTTClient_create(MQTTClient *handle, const char *serverURI, const char *clientId, int
persistence_type, void *persistence_context);
MQTTClient_connect
Connects the client to an MQTT broker using the given connection options.
Signature:
int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions *options);
MQTTClient_connectOptions_initializer
Provides a way to initialize an MQTTClient_connectOptions structure with default values.
Usage:
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
MQTTClient_publishMessage
Publishes a message to a specific topic.
Signature:
int MQTTClient_publishMessage(MQTTClient handle, const char *topicName, MQTTClient_message
*message, MQTTClient_deliveryToken *token);
MQTTClient_message_initializer
Eclipse Paho MQTT C Client APIs
Provides a default-initialized MQTTClient_message structure.
Usage:
MQTTClient_message pubmsg = MQTTClient_message_initializer;
MQTTClient_waitForCompletion
Waits for a message to be delivered, given its token.
Signature:
int MQTTClient_waitForCompletion(MQTTClient handle, MQTTClient_deliveryToken token, unsigned long
timeout);
MQTTClient_disconnect
Disconnects the client from the MQTT broker.
Signature:
int MQTTClient_disconnect(MQTTClient handle, int timeout);
MQTTClient_destroy
Frees resources associated with the MQTT client object.
Signature:
void MQTTClient_destroy(MQTTClient *handle);
MQTTClient_subscribe
Subscribes the client to a topic with a specified QoS.
Signature:
int MQTTClient_subscribe(MQTTClient handle, const char *topic, int qos);
Eclipse Paho MQTT C Client APIs
MQTTClient_setCallbacks
Registers callback functions to handle connection lost, message arrived, and delivery complete events.
Signature:
int MQTTClient_setCallbacks(MQTTClient handle, void *context, MQTTClient_connectionLost *cl,
MQTTClient_messageArrived *ma, MQTTClient_deliveryComplete *dc);
MQTTClient_freeMessage
Frees the memory allocated to an MQTTClient_message.
Signature:
void MQTTClient_freeMessage(MQTTClient_message **message);
MQTTClient_free
Frees memory allocated to the topic name or message payload.
Signature:
void MQTTClient_free(void *ptr);