MQTT helper

This library simplifies Zephyr MQTT API and socket handling.

Configuration

To use the MQTT helper library, enable the CONFIG_MQTT_HELPER Kconfig option.

Additionally, configure the following options as per the needs of your application:

API documentation

Header file: include/net/mqtt_helper.h
Source file: subsys/net/lib/mqtt_helper/mqtt_helper.c
group mqtt_helper

Convenience library that simplifies Zephyr MQTT API and socket handling.

Typedefs

typedef void (*mqtt_helper_handler_t)(struct mqtt_evt *evt)
typedef void (*mqtt_helper_on_connack_t)(enum mqtt_conn_return_code return_code)
typedef void (*mqtt_helper_on_disconnect_t)(int result)
typedef void (*mqtt_helper_on_publish_t)(struct mqtt_helper_buf topic_buf, struct mqtt_helper_buf payload_buf)
typedef void (*mqtt_helper_on_puback_t)(uint16_t message_id, int result)
typedef void (*mqtt_helper_on_suback_t)(uint16_t message_id, int result)
typedef void (*mqtt_helper_on_pingresp_t)(void)
typedef void (*mqtt_helper_on_error_t)(enum mqtt_helper_error error)

Enums

enum mqtt_state

Values:

enumerator MQTT_STATE_UNINIT
enumerator MQTT_STATE_DISCONNECTED
enumerator MQTT_STATE_TRANSPORT_CONNECTING
enumerator MQTT_STATE_CONNECTING
enumerator MQTT_STATE_TRANSPORT_CONNECTED
enumerator MQTT_STATE_CONNECTED
enumerator MQTT_STATE_DISCONNECTING
enumerator MQTT_STATE_COUNT
enum mqtt_helper_error

Values:

enumerator MQTT_HELPER_ERROR_MSG_SIZE

The received payload is larger than the payload buffer.

Functions

int mqtt_helper_init(struct mqtt_helper_cfg *cfg)

Initialize the MQTT helper.

Return values
  • 0 – if successful.

  • -EOPNOTSUPP – if operation is not supported in the current state.

Returns

Otherwise a negative error code.

int mqtt_helper_connect(struct mqtt_helper_conn_params *conn_params)

Connect to an MQTT broker.

Return values
  • 0 – if successful.

  • -EOPNOTSUPP – if operation is not supported in the current state.

Returns

Otherwise a negative error code.

int mqtt_helper_disconnect(void)

Disconnect from the MQTT broker.

Return values
  • 0 – if successful.

  • -EOPNOTSUPP – if operation is not supported in the current state.

Returns

Otherwise a negative error code.

int mqtt_helper_subscribe(struct mqtt_subscription_list *sub_list)

Subscribe to MQTT topics.

Return values
  • 0 – if successful.

  • -EOPNOTSUPP – if operation is not supported in the current state.

Returns

Otherwise a negative error code.

int mqtt_helper_publish(const struct mqtt_publish_param *param)

Publish an MQTT message.

Return values
  • 0 – if successful.

  • -EOPNOTSUPP – if operation is not supported in the current state.

Returns

Otherwise a negative error code.

int mqtt_helper_deinit(void)

Deinitialize library. Must be called when all MQTT operations are done to release resources and allow for a new client. The client must be in a disconnected state.

Return values
  • 0 – if successful.

  • -EOPNOTSUPP – if operation is not supported in the current state.

Returns

Otherwise a negative error code.

struct mqtt_helper_buf
#include <mqtt_helper.h>

Public Members

char *ptr

Pointer to buffer.

size_t size

Size of buffer.

struct mqtt_helper_cfg
#include <mqtt_helper.h>
struct mqtt_helper_conn_params
#include <mqtt_helper.h>