Loading...
Searching...
No Matches
emcute.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
87
88#include <stdint.h>
89#include <stddef.h>
90#include <stdbool.h>
91
92#include "net/sock/udp.h"
93
94#ifdef __cplusplus
95extern "C" {
96#endif
97
111#ifndef CONFIG_EMCUTE_DEFAULT_PORT
112#define CONFIG_EMCUTE_DEFAULT_PORT (1883U)
113#endif
114
123#ifndef CONFIG_EMCUTE_BUFSIZE
124#define CONFIG_EMCUTE_BUFSIZE (512U)
125#endif
126
132#ifndef CONFIG_EMCUTE_TOPIC_MAXLEN
133#define CONFIG_EMCUTE_TOPIC_MAXLEN (196U)
134#endif
135
143#ifndef CONFIG_EMCUTE_KEEPALIVE
144#define CONFIG_EMCUTE_KEEPALIVE (360) /* -> 6 min*/
145#endif
146
157#ifndef CONFIG_EMCUTE_T_RETRY
158#define CONFIG_EMCUTE_T_RETRY (15U) /* -> 15 sec */
159#endif
160
170#ifndef CONFIG_EMCUTE_N_RETRY
171#define CONFIG_EMCUTE_N_RETRY (3U)
172#endif
174
185enum {
186 EMCUTE_DUP = 0x80,
192 EMCUTE_WILL = 0x08,
193 EMCUTE_CS = 0x04,
198};
199
203enum {
210};
211
215typedef struct {
216 const char *name;
217 uint16_t id;
219
227typedef void(*emcute_cb_t)(const emcute_topic_t *topic, void *data, size_t len);
228
238
260int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic,
261 const void *will_msg, size_t will_msg_len, unsigned flags);
262
271
284
301int emcute_pub(emcute_topic_t *topic, const void *buf, size_t len,
302 unsigned flags);
303
321int emcute_sub(emcute_sub_t *sub, unsigned flags);
322
333
347int emcute_willupd_topic(const char *topic, unsigned flags);
348
362int emcute_willupd_msg(const void *data, size_t len);
363
373void emcute_run(uint16_t port, const char *id);
374
385const char *emcute_type_str(uint8_t type);
386
387#ifdef __cplusplus
388}
389#endif
390
int emcute_willupd_topic(const char *topic, unsigned flags)
Update the last will topic.
int emcute_discon(void)
Disconnect from the gateway we are currently connected to.
int emcute_willupd_msg(const void *data, size_t len)
Update the last will message.
int emcute_unsub(emcute_sub_t *sub)
Unsubscripbe the given topic.
int emcute_reg(emcute_topic_t *topic)
Get a topic ID for the given topic name from the gateway.
const char * emcute_type_str(uint8_t type)
Return the string representation of the given type value.
void(* emcute_cb_t)(const emcute_topic_t *topic, void *data, size_t len)
Signature for callbacks fired when publish messages are received.
Definition emcute.h:227
int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic, const void *will_msg, size_t will_msg_len, unsigned flags)
Connect to a given MQTT-SN gateway (CONNECT)
int emcute_pub(emcute_topic_t *topic, const void *buf, size_t len, unsigned flags)
Publish data on the given topic.
int emcute_sub(emcute_sub_t *sub, unsigned flags)
Subscribe to the given topic.
struct emcute_sub emcute_sub_t
Data-structure for keeping track of topics we register to.
void emcute_run(uint16_t port, const char *id)
Run emCute, will 'occupy' the calling thread.
@ EMCUTE_CS
clean session flag
Definition emcute.h:193
@ EMCUTE_RETAIN
retain flag
Definition emcute.h:191
@ EMCUTE_QOS_2
QoS level 2.
Definition emcute.h:188
@ EMCUTE_QOS_1
QoS level 1.
Definition emcute.h:189
@ EMCUTE_DUP
duplicate flag
Definition emcute.h:186
@ EMCUTE_QOS_MASK
QoS level mask.
Definition emcute.h:187
@ EMCUTE_QOS_0
QoS level 0.
Definition emcute.h:190
@ EMCUTE_TIT_NORMAL
topic ID: normal
Definition emcute.h:197
@ EMCUTE_TIT_SHORT
topic ID: short
Definition emcute.h:195
@ EMCUTE_TIT_MASK
topic ID type mask
Definition emcute.h:194
@ EMCUTE_TIT_PREDEF
topic ID: pre-defined
Definition emcute.h:196
@ EMCUTE_WILL
will flag, used during CONNECT
Definition emcute.h:192
@ EMCUTE_NOGW
error: not connected to a gateway
Definition emcute.h:205
@ EMCUTE_NOTSUP
error: feature not supported
Definition emcute.h:209
@ EMCUTE_OVERFLOW
error: ran out of buffer space
Definition emcute.h:207
@ EMCUTE_OK
everything went as expect
Definition emcute.h:204
@ EMCUTE_TIMEOUT
error: timeout
Definition emcute.h:208
@ EMCUTE_REJECT
error: operation was rejected by broker
Definition emcute.h:206
struct _sock_tl_ep sock_udp_ep_t
An end point for a UDP sock object.
Definition udp.h:293
UDP sock definitions.
Data-structure for keeping track of topics we register to.
Definition emcute.h:232
emcute_topic_t topic
topic we subscribe to
Definition emcute.h:234
struct emcute_sub * next
next subscription (saved in a list)
Definition emcute.h:233
emcute_cb_t cb
function called when receiving messages
Definition emcute.h:235
void * arg
optional custom argument
Definition emcute.h:236
MQTT-SN topic.
Definition emcute.h:215
const char * name
topic string (currently ASCII only)
Definition emcute.h:216
uint16_t id
topic id, as assigned by the gateway
Definition emcute.h:217