oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
MQTT Client

Lightweight MQTT 3.1.1 client for IoT pub/sub messaging. More...

Data Structures

struct  ove_mqtt_config_t
 MQTT connection configuration. More...
 

Macros

#define OVE_MQTT_QOS0   ((ove_mqtt_qos_t)0)
 
#define OVE_MQTT_QOS1   ((ove_mqtt_qos_t)1)
 

Typedefs

typedef uint8_t ove_mqtt_qos_t
 MQTT QoS level.
 
typedef void(* ove_mqtt_msg_cb) (const char *topic, size_t topic_len, const void *payload, size_t payload_len, void *user_data)
 MQTT message callback.
 

Functions

int ove_mqtt_client_init (ove_mqtt_client_t *client, ove_mqtt_client_storage_t *storage)
 Initialise an MQTT client from caller-supplied storage.
 
void ove_mqtt_client_deinit (ove_mqtt_client_t client)
 De-initialise an MQTT client.
 
int ove_mqtt_connect (ove_mqtt_client_t client, const ove_mqtt_config_t *cfg)
 Connect to an MQTT broker.
 
void ove_mqtt_disconnect (ove_mqtt_client_t client)
 Disconnect from the MQTT broker.
 
int ove_mqtt_publish (ove_mqtt_client_t client, const char *topic, const void *payload, size_t payload_len, ove_mqtt_qos_t qos)
 Publish a message.
 
int ove_mqtt_subscribe (ove_mqtt_client_t client, const char *topic, ove_mqtt_qos_t qos)
 Subscribe to a topic.
 
int ove_mqtt_unsubscribe (ove_mqtt_client_t client, const char *topic)
 Unsubscribe from a topic.
 
int ove_mqtt_loop (ove_mqtt_client_t client, uint64_t timeout_ns)
 Process incoming packets and send keep-alive pings.
 
int ove_mqtt_client_create (ove_mqtt_client_t *client)
 Heap-allocate and initialise an MQTT client.
 
void ove_mqtt_client_destroy (ove_mqtt_client_t client)
 Destroy a heap-allocated MQTT client.
 

Detailed Description

Lightweight MQTT 3.1.1 client for IoT pub/sub messaging.

Supports CONNECT, PUBLISH (QoS 0/1), SUBSCRIBE, keep-alive, and optional TLS. Uses the oveRTOS socket layer for transport.

Note
Requires CONFIG_OVE_NET_MQTT (implies CONFIG_OVE_NET). When disabled every function is replaced by a no-op stub.

Macro Definition Documentation

◆ OVE_MQTT_QOS0

#define OVE_MQTT_QOS0   ((ove_mqtt_qos_t)0)

At most once.

◆ OVE_MQTT_QOS1

#define OVE_MQTT_QOS1   ((ove_mqtt_qos_t)1)

At least once.

Typedef Documentation

◆ ove_mqtt_msg_cb

typedef void(* ove_mqtt_msg_cb) (const char *topic, size_t topic_len, const void *payload, size_t payload_len, void *user_data)

MQTT message callback.

Parameters
[in]topicTopic string (not NUL-terminated).
[in]topic_lenTopic length in bytes.
[in]payloadMessage payload.
[in]payload_lenPayload length in bytes.
[in]user_dataOpaque pointer supplied at connect time.

Function Documentation

◆ ove_mqtt_client_init()

int ove_mqtt_client_init ( ove_mqtt_client_t client,
ove_mqtt_client_storage_t *  storage 
)

Initialise an MQTT client from caller-supplied storage.

Parameters
[out]clientHandle written on success.
[in]storageCaller-allocated storage.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_mqtt_client_deinit()

void ove_mqtt_client_deinit ( ove_mqtt_client_t  client)

De-initialise an MQTT client.

Parameters
[in]clientHandle returned by ove_mqtt_client_init().

◆ ove_mqtt_connect()

int ove_mqtt_connect ( ove_mqtt_client_t  client,
const ove_mqtt_config_t cfg 
)

Connect to an MQTT broker.

Parameters
[in]clientMQTT client handle.
[in]cfgConnection configuration.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_mqtt_disconnect()

void ove_mqtt_disconnect ( ove_mqtt_client_t  client)

Disconnect from the MQTT broker.

Parameters
[in]clientMQTT client handle.

◆ ove_mqtt_publish()

int ove_mqtt_publish ( ove_mqtt_client_t  client,
const char *  topic,
const void *  payload,
size_t  payload_len,
ove_mqtt_qos_t  qos 
)

Publish a message.

Parameters
[in]clientMQTT client handle.
[in]topicTopic string (NUL-terminated).
[in]payloadMessage payload.
[in]payload_lenPayload length in bytes.
[in]qosQoS level.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_mqtt_subscribe()

int ove_mqtt_subscribe ( ove_mqtt_client_t  client,
const char *  topic,
ove_mqtt_qos_t  qos 
)

Subscribe to a topic.

Parameters
[in]clientMQTT client handle.
[in]topicTopic filter (NUL-terminated).
[in]qosMaximum QoS level.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_mqtt_unsubscribe()

int ove_mqtt_unsubscribe ( ove_mqtt_client_t  client,
const char *  topic 
)

Unsubscribe from a topic.

Parameters
[in]clientMQTT client handle.
[in]topicTopic filter (NUL-terminated).
Returns
OVE_OK on success, negative error code on failure.

◆ ove_mqtt_loop()

int ove_mqtt_loop ( ove_mqtt_client_t  client,
uint64_t  timeout_ns 
)

Process incoming packets and send keep-alive pings.

Must be called periodically (typically in a loop or timer).

Parameters
[in]clientMQTT client handle.
[in]timeout_nsMaximum time to wait for incoming data.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_mqtt_client_create()

int ove_mqtt_client_create ( ove_mqtt_client_t client)

Heap-allocate and initialise an MQTT client.

Parameters
[out]clientHandle written on success.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_mqtt_client_destroy()

void ove_mqtt_client_destroy ( ove_mqtt_client_t  client)

Destroy a heap-allocated MQTT client.

Parameters
[in]clientHandle returned by ove_mqtt_client_create().