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
86#ifndef NET_EMCUTE_H
87#define NET_EMCUTE_H
88
89#include <stdint.h>
90#include <stddef.h>
91#include <stdbool.h>
92
93#include "net/sock/udp.h"
94
95#ifdef __cplusplus
96extern "C" {
97#endif
98
112#ifndef CONFIG_EMCUTE_DEFAULT_PORT
113#define CONFIG_EMCUTE_DEFAULT_PORT (1883U)
114#endif
115
124#ifndef CONFIG_EMCUTE_BUFSIZE
125#define CONFIG_EMCUTE_BUFSIZE (512U)
126#endif
127
133#ifndef CONFIG_EMCUTE_TOPIC_MAXLEN
134#define CONFIG_EMCUTE_TOPIC_MAXLEN (196U)
135#endif
136
144#ifndef CONFIG_EMCUTE_KEEPALIVE
145#define CONFIG_EMCUTE_KEEPALIVE (360) /* -> 6 min*/
146#endif
147
158#ifndef CONFIG_EMCUTE_T_RETRY
159#define CONFIG_EMCUTE_T_RETRY (15U) /* -> 15 sec */
160#endif
161
171#ifndef CONFIG_EMCUTE_N_RETRY
172#define CONFIG_EMCUTE_N_RETRY (3U)
173#endif
186enum {
187 EMCUTE_DUP = 0x80,
193 EMCUTE_WILL = 0x08,
194 EMCUTE_CS = 0x04,
198 EMCUTE_TIT_NORMAL = 0x00
200
204enum {
210 EMCUTE_NOTSUP = -5
212
216typedef struct {
217 const char *name;
218 uint16_t id;
220
228typedef void(*emcute_cb_t)(const emcute_topic_t *topic, void *data, size_t len);
229
239
261int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic,
262 const void *will_msg, size_t will_msg_len, unsigned flags);
263
272
285
302int emcute_pub(emcute_topic_t *topic, const void *buf, size_t len,
303 unsigned flags);
304
322int emcute_sub(emcute_sub_t *sub, unsigned flags);
323
334
348int emcute_willupd_topic(const char *topic, unsigned flags);
349
363int emcute_willupd_msg(const void *data, size_t len);
364
374void emcute_run(uint16_t port, const char *id);
375
386const char *emcute_type_str(uint8_t type);
387
388#ifdef __cplusplus
389}
390#endif
391
392#endif /* NET_EMCUTE_H */
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:228
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.
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:194
@ EMCUTE_RETAIN
retain flag
Definition emcute.h:192
@ EMCUTE_QOS_2
QoS level 2.
Definition emcute.h:189
@ EMCUTE_QOS_1
QoS level 1.
Definition emcute.h:190
@ EMCUTE_DUP
duplicate flag
Definition emcute.h:187
@ EMCUTE_QOS_MASK
QoS level mask.
Definition emcute.h:188
@ EMCUTE_QOS_0
QoS level 0.
Definition emcute.h:191
@ EMCUTE_TIT_NORMAL
topic ID: normal
Definition emcute.h:198
@ EMCUTE_TIT_SHORT
topic ID: short
Definition emcute.h:196
@ EMCUTE_TIT_MASK
topic ID type mask
Definition emcute.h:195
@ EMCUTE_TIT_PREDEF
topic ID: pre-defined
Definition emcute.h:197
@ EMCUTE_WILL
will flag, used during CONNECT
Definition emcute.h:193
@ EMCUTE_NOGW
error: not connected to a gateway
Definition emcute.h:206
@ EMCUTE_NOTSUP
error: feature not supported
Definition emcute.h:210
@ EMCUTE_OVERFLOW
error: ran out of buffer space
Definition emcute.h:208
@ EMCUTE_OK
everything went as expect
Definition emcute.h:205
@ EMCUTE_TIMEOUT
error: timeout
Definition emcute.h:209
@ EMCUTE_REJECT
error: operation was rejected by broker
Definition emcute.h:207
UDP sock definitions.
Common IP-based transport layer end point.
Definition sock.h:215
Data-structure for keeping track of topics we register to.
Definition emcute.h:233
emcute_topic_t topic
topic we subscribe to
Definition emcute.h:235
struct emcute_sub * next
next subscription (saved in a list)
Definition emcute.h:234
emcute_cb_t cb
function called when receiving messages
Definition emcute.h:236
void * arg
optional custom argument
Definition emcute.h:237
MQTT-SN topic.
Definition emcute.h:216
const char * name
topic string (currently ASCII only)
Definition emcute.h:217
uint16_t id
topic id, as assigned by the gateway
Definition emcute.h:218