MQTT-C
Data Fields
mqtt_client Struct Reference

An MQTT client. More...

#include <mqtt.h>

Data Fields

mqtt_pal_socket_handle socketfd
 The socket connecting to the MQTT broker.
 
uint16_t pid_lfsr
 The LFSR state used to generate packet ID's.
 
uint16_t keep_alive
 The keep-alive time in seconds.
 
int number_of_keep_alives
 A counter counting pings that have been sent to keep the connection alive. More...
 
mqtt_pal_time_t time_of_last_send
 The timestamp of the last message sent to the buffer. More...
 
enum MQTTErrors error
 The error state of the client. More...
 
int response_timeout
 The timeout period in seconds. More...
 
int number_of_timeouts
 A counter counting the number of timeouts that have occurred.
 
double typical_response_time
 Approximately much time it has typically taken to receive responses from the broker. More...
 
void(* publish_response_callback )(void **state, struct mqtt_response_publish *publish)
 The callback that is called whenever a publish is received from the broker. More...
 
void * publish_response_callback_state
 A pointer to any publish_response_callback state information you need. More...
 
enum MQTTErrors(* inspector_callback )(struct mqtt_client *)
 A user-specified callback, triggered on each mqtt_sync, allowing the user to perform state inspections (and custom socket error detection) on the client. More...
 
void(* reconnect_callback )(struct mqtt_client *, void **)
 A callback that is called whenever the client is in an error state. More...
 
void * reconnect_state
 A pointer to some state. A pointer to this member is passed to mqtt_client::reconnect_callback.
 
struct {
   uint8_t *   mem_start
 The start of the receive buffer's memory.
 
   size_t   mem_size
 The size of the receive buffer's memory.
 
   uint8_t *   curr
 A pointer to the next writtable location in the receive buffer.
 
   size_t   curr_sz
 The number of bytes that are still writable at curr.
 
recv_buffer
 The buffer where ingress data is temporarily stored.
 
mqtt_pal_mutex_t mutex
 A variable passed to support thread-safety. More...
 
struct mqtt_message_queue mq
 The sending message queue.
 

Detailed Description

An MQTT client.

Note
All members can be manipulated via the related functions.
Examples:
bio_publisher.c, openssl_publisher.c, reconnect_subscriber.c, simple_publisher.c, and simple_subscriber.c.

Field Documentation

◆ error

enum MQTTErrors mqtt_client::error

The error state of the client.

error should be MQTT_OK for the entirety of the connection.

Note
The error state will be MQTT_ERROR_CONNECT_NOT_CALLED until you call mqtt_connect.
Examples:
reconnect_subscriber.c.

◆ inspector_callback

enum MQTTErrors(* mqtt_client::inspector_callback) (struct mqtt_client *)

A user-specified callback, triggered on each mqtt_sync, allowing the user to perform state inspections (and custom socket error detection) on the client.

This callback is triggered on each call to mqtt_sync. If it returns MQTT_OK then mqtt_sync will continue normally (performing reads and writes). If it returns an error then mqtt_sync will not call reads and writes.

This callback can be used to perform custom error detection, namely platform specific socket error detection, and force the client into an error state.

This member is always initialized to NULL but it can be manually set at any time.

◆ mutex

mqtt_pal_mutex_t mqtt_client::mutex

A variable passed to support thread-safety.

A pointer to this variable is passed to MQTT_PAL_MUTEX_LOCK, and MQTT_PAL_MUTEX_UNLOCK.

◆ number_of_keep_alives

int mqtt_client::number_of_keep_alives

A counter counting pings that have been sent to keep the connection alive.

See also
keep_alive

◆ publish_response_callback

void(* mqtt_client::publish_response_callback) (void **state, struct mqtt_response_publish *publish)

The callback that is called whenever a publish is received from the broker.

Any topics that you have subscribed to will be returned from the broker as mqtt_response_publish messages. All the publishes received from the broker will be passed to this function.

Note
A pointer to publish_response_callback_state is always passed to the callback. Use publish_response_callback_state to keep track of any state information you need.

◆ publish_response_callback_state

void* mqtt_client::publish_response_callback_state

A pointer to any publish_response_callback state information you need.

Note
A pointer to this pointer will always be publish_response_callback upon receiving a publish message from the broker.

◆ reconnect_callback

void(* mqtt_client::reconnect_callback) (struct mqtt_client *, void **)

A callback that is called whenever the client is in an error state.

This callback is responsible for: application level error handling, closing previous sockets, and reestabilishing the connection to the broker and session configurations (i.e. subscriptions).

◆ response_timeout

int mqtt_client::response_timeout

The timeout period in seconds.

If the broker doesn't return an ACK within response_timeout seconds a timeout will occur and the message will be retransmitted.

Note
The default value is 30 [seconds] but you can change it at any time.

◆ time_of_last_send

mqtt_pal_time_t mqtt_client::time_of_last_send

The timestamp of the last message sent to the buffer.

This is used to detect the need for keep-alive pings.

See also
keep_alive

◆ typical_response_time

double mqtt_client::typical_response_time

Approximately much time it has typically taken to receive responses from the broker.

Note
This is tracked using a exponential-averaging.

The documentation for this struct was generated from the following file: