oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
net_mqtt.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
9#ifndef OVE_NET_MQTT_H
10#define OVE_NET_MQTT_H
11
25#include "ove/types.h"
26#include "ove/net.h"
27#include "ove_config.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
34#ifdef __ZIG_CIMPORT__
35typedef uint8_t ove_mqtt_qos_t;
36#define OVE_MQTT_QOS0 ((ove_mqtt_qos_t)0)
37#define OVE_MQTT_QOS1 ((ove_mqtt_qos_t)1)
38#else
39typedef enum {
40 OVE_MQTT_QOS0 = 0,
41 OVE_MQTT_QOS1 = 1,
43#endif
44
54typedef void (*ove_mqtt_msg_cb)(const char *topic, size_t topic_len, const void *payload,
55 size_t payload_len, void *user_data);
56
64typedef struct {
65 const char *host;
66 uint16_t port;
67 const char *client_id;
68 const char *username;
69 const char *password;
70 uint16_t keep_alive_s;
71 int use_tls;
72 const unsigned char
77 void *user_data;
79
80#include "ove/storage.h"
81
82#ifdef CONFIG_OVE_NET_MQTT
83
91int ove_mqtt_client_init(ove_mqtt_client_t *client, ove_mqtt_client_storage_t *storage);
92
99
108
115
126int ove_mqtt_publish(ove_mqtt_client_t client, const char *topic, const void *payload,
127 size_t payload_len, ove_mqtt_qos_t qos);
128
137int ove_mqtt_subscribe(ove_mqtt_client_t client, const char *topic, ove_mqtt_qos_t qos);
138
146int ove_mqtt_unsubscribe(ove_mqtt_client_t client, const char *topic);
147
157int ove_mqtt_loop(ove_mqtt_client_t client, uint64_t timeout_ns);
158
159#ifdef OVE_HEAP_NET_MQTT
167
174#endif /* OVE_HEAP_NET_MQTT */
175
176#else /* !CONFIG_OVE_NET_MQTT */
177
179#ifndef CONFIG_OVE_NET_MQTT
180typedef struct {
181 uint8_t _unused;
182} ove_mqtt_client_storage_t;
183#endif
184
185static inline int ove_mqtt_client_init(ove_mqtt_client_t *client,
186 ove_mqtt_client_storage_t *storage)
187{
188 (void)client;
189 (void)storage;
191}
192static inline void ove_mqtt_client_deinit(ove_mqtt_client_t client)
193{
194 (void)client;
195}
196static inline int ove_mqtt_connect(ove_mqtt_client_t client, const ove_mqtt_config_t *cfg)
197{
198 (void)client;
199 (void)cfg;
201}
202static inline void ove_mqtt_disconnect(ove_mqtt_client_t client)
203{
204 (void)client;
205}
206static inline int ove_mqtt_publish(ove_mqtt_client_t client, const char *topic, const void *payload,
207 size_t payload_len, ove_mqtt_qos_t qos)
208{
209 (void)client;
210 (void)topic;
211 (void)payload;
212 (void)payload_len;
213 (void)qos;
215}
216static inline int ove_mqtt_subscribe(ove_mqtt_client_t client, const char *topic,
217 ove_mqtt_qos_t qos)
218{
219 (void)client;
220 (void)topic;
221 (void)qos;
223}
224static inline int ove_mqtt_unsubscribe(ove_mqtt_client_t client, const char *topic)
225{
226 (void)client;
227 (void)topic;
229}
230static inline int ove_mqtt_loop(ove_mqtt_client_t client, uint64_t timeout_ns)
231{
232 (void)client;
233 (void)timeout_ns;
235}
238#endif /* CONFIG_OVE_NET_MQTT */
239
240#ifdef __cplusplus
241}
242#endif
243
246#endif /* OVE_NET_MQTT_H */
void ove_mqtt_client_deinit(ove_mqtt_client_t client)
De-initialise an MQTT client.
#define OVE_MQTT_QOS1
Definition net_mqtt.h:37
int ove_mqtt_connect(ove_mqtt_client_t client, const ove_mqtt_config_t *cfg)
Connect to an 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.
void ove_mqtt_disconnect(ove_mqtt_client_t client)
Disconnect from the MQTT broker.
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.
Definition net_mqtt.h:54
void ove_mqtt_client_destroy(ove_mqtt_client_t client)
Destroy a heap-allocated MQTT client.
int ove_mqtt_client_init(ove_mqtt_client_t *client, ove_mqtt_client_storage_t *storage)
Initialise an MQTT client from caller-supplied storage.
#define OVE_MQTT_QOS0
Definition net_mqtt.h:36
uint8_t ove_mqtt_qos_t
MQTT QoS level.
Definition net_mqtt.h:35
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.
int ove_mqtt_unsubscribe(ove_mqtt_client_t client, const char *topic)
Unsubscribe from a topic.
int ove_mqtt_subscribe(ove_mqtt_client_t client, const char *topic, ove_mqtt_qos_t qos)
Subscribe to a topic.
struct ove_mqtt_client * ove_mqtt_client_t
Opaque handle for an MQTT client.
Definition types.h:259
@ OVE_ERR_NOT_SUPPORTED
Definition types.h:98
MQTT connection configuration.
Definition net_mqtt.h:64
size_t tls_ca_cert_len
Definition net_mqtt.h:74
int use_tls
Definition net_mqtt.h:71
const char * username
Definition net_mqtt.h:68
const char * password
Definition net_mqtt.h:69
const unsigned char * tls_ca_cert
Definition net_mqtt.h:73
int tls_allow_insecure
Definition net_mqtt.h:75
uint16_t keep_alive_s
Definition net_mqtt.h:70
void * user_data
Definition net_mqtt.h:77
const char * host
Definition net_mqtt.h:65
uint16_t port
Definition net_mqtt.h:66
ove_mqtt_msg_cb on_message
Definition net_mqtt.h:76
const char * client_id
Definition net_mqtt.h:67