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
include/net/mqtt_helper.h
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_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
-
enumerator MQTT_STATE_UNINIT
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>
-
struct mqtt_helper_cfg
- #include <mqtt_helper.h>
-
struct mqtt_helper_conn_params
- #include <mqtt_helper.h>
-
typedef void (*mqtt_helper_on_connack_t)(enum mqtt_conn_return_code return_code)