nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
mqtt_helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef MQTT_HELPER__
8#define MQTT_HELPER__
9
16#include <stdio.h>
17#include <zephyr/net/mqtt.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
31
33};
34
38};
39
42 char *ptr;
43
45 size_t size;
46};
47
60typedef bool (*mqtt_helper_on_all_events_t)(struct mqtt_client *const client,
61 const struct mqtt_evt *const event);
62typedef void (*mqtt_helper_on_connack_t)(enum mqtt_conn_return_code return_code,
63 bool session_present);
64typedef void (*mqtt_helper_on_disconnect_t)(int result);
65typedef void (*mqtt_helper_on_publish_t)(struct mqtt_helper_buf topic_buf,
66 struct mqtt_helper_buf payload_buf);
67typedef void (*mqtt_helper_on_puback_t)(uint16_t message_id, int result);
68typedef void (*mqtt_helper_on_suback_t)(uint16_t message_id, int result);
69typedef void (*mqtt_helper_on_pingresp_t)(void);
70typedef void (*mqtt_helper_on_error_t)(enum mqtt_helper_error error);
71
73 struct {
82 } cb;
83};
84
86 /* The hostname must be null-terminated. */
91};
92
100
101
109
117
124int mqtt_helper_subscribe(struct mqtt_subscription_list *sub_list);
125
132int mqtt_helper_publish(const struct mqtt_publish_param *param);
133
142
143
144#ifdef __cplusplus
145}
146#endif
147
152#endif /* MQTT_HELPER__ */
static const struct event_proxy_config cfg
Definition: event_proxy_def.h:28
void(* mqtt_helper_on_puback_t)(uint16_t message_id, int result)
Definition: mqtt_helper.h:67
int mqtt_helper_deinit(void)
Deinitialize library. Must be called when all MQTT operations are done to release resources and allow...
int mqtt_helper_connect(struct mqtt_helper_conn_params *conn_params)
Connect to an MQTT broker.
int mqtt_helper_disconnect(void)
Disconnect from the MQTT broker.
int mqtt_helper_publish(const struct mqtt_publish_param *param)
Publish an MQTT message.
void(* mqtt_helper_on_pingresp_t)(void)
Definition: mqtt_helper.h:69
int mqtt_helper_init(struct mqtt_helper_cfg *cfg)
Initialize the MQTT helper.
void(* mqtt_helper_on_connack_t)(enum mqtt_conn_return_code return_code, bool session_present)
Definition: mqtt_helper.h:62
mqtt_state
Definition: mqtt_helper.h:23
@ MQTT_STATE_UNINIT
Definition: mqtt_helper.h:24
@ MQTT_STATE_DISCONNECTED
Definition: mqtt_helper.h:25
@ MQTT_STATE_CONNECTING
Definition: mqtt_helper.h:27
@ MQTT_STATE_DISCONNECTING
Definition: mqtt_helper.h:30
@ MQTT_STATE_CONNECTED
Definition: mqtt_helper.h:29
@ MQTT_STATE_TRANSPORT_CONNECTED
Definition: mqtt_helper.h:28
@ MQTT_STATE_COUNT
Definition: mqtt_helper.h:32
@ MQTT_STATE_TRANSPORT_CONNECTING
Definition: mqtt_helper.h:26
void(* mqtt_helper_on_disconnect_t)(int result)
Definition: mqtt_helper.h:64
mqtt_helper_error
Definition: mqtt_helper.h:35
@ MQTT_HELPER_ERROR_MSG_SIZE
Definition: mqtt_helper.h:37
void(* mqtt_helper_on_error_t)(enum mqtt_helper_error error)
Definition: mqtt_helper.h:70
void(* mqtt_helper_on_publish_t)(struct mqtt_helper_buf topic_buf, struct mqtt_helper_buf payload_buf)
Definition: mqtt_helper.h:65
void(* mqtt_helper_on_suback_t)(uint16_t message_id, int result)
Definition: mqtt_helper.h:68
int mqtt_helper_subscribe(struct mqtt_subscription_list *sub_list)
Subscribe to MQTT topics.
bool(* mqtt_helper_on_all_events_t)(struct mqtt_client *const client, const struct mqtt_evt *const event)
Handler invoked for events that are received from the MQTT stack. This callback handler can be used t...
Definition: mqtt_helper.h:60
size_t size
Definition: mqtt_helper.h:45
char * ptr
Definition: mqtt_helper.h:42
Definition: mqtt_helper.h:40
mqtt_helper_on_disconnect_t on_disconnect
Definition: mqtt_helper.h:76
mqtt_helper_on_all_events_t on_all_events
Definition: mqtt_helper.h:74
mqtt_helper_on_publish_t on_publish
Definition: mqtt_helper.h:77
mqtt_helper_on_connack_t on_connack
Definition: mqtt_helper.h:75
mqtt_helper_on_pingresp_t on_pingresp
Definition: mqtt_helper.h:80
mqtt_helper_on_suback_t on_suback
Definition: mqtt_helper.h:79
struct mqtt_helper_cfg::@202 cb
mqtt_helper_on_puback_t on_puback
Definition: mqtt_helper.h:78
mqtt_helper_on_error_t on_error
Definition: mqtt_helper.h:81
Definition: mqtt_helper.h:72
struct mqtt_helper_buf password
Definition: mqtt_helper.h:90
struct mqtt_helper_buf hostname
Definition: mqtt_helper.h:87
struct mqtt_helper_buf device_id
Definition: mqtt_helper.h:88
struct mqtt_helper_buf user_name
Definition: mqtt_helper.h:89
Definition: mqtt_helper.h:85