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 
85 #ifndef NET_EMCUTE_H
86 #define NET_EMCUTE_H
87 
88 #include <stdint.h>
89 #include <stddef.h>
90 #include <stdbool.h>
91 
92 #include "net/sock/udp.h"
93 
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98 #ifndef EMCUTE_DEFAULT_PORT
99 
102 #define EMCUTE_DEFAULT_PORT (1883U)
103 #endif
104 
105 #ifndef EMCUTE_BUFSIZE
106 
114 #define EMCUTE_BUFSIZE (512U)
115 #endif
116 
117 #ifndef EMCUTE_TOPIC_MAXLEN
118 
124 #define EMCUTE_TOPIC_MAXLEN (196U)
125 #endif
126 
127 #ifndef EMCUTE_KEEPALIVE
128 
136 #define EMCUTE_KEEPALIVE (360) /* -> 6 min*/
137 #endif
138 
139 #ifndef EMCUTE_T_RETRY
140 
145 #define EMCUTE_T_RETRY (15U) /* -> 15 sec */
146 #endif
147 
148 #ifndef EMCUTE_N_RETRY
149 
154 #define EMCUTE_N_RETRY (3U)
155 #endif
156 
167 enum {
168  EMCUTE_DUP = 0x80,
170  EMCUTE_QOS_2 = 0x40,
171  EMCUTE_QOS_1 = 0x20,
172  EMCUTE_QOS_0 = 0x00,
173  EMCUTE_RETAIN = 0x10,
174  EMCUTE_WILL = 0x08,
175  EMCUTE_CS = 0x04,
180 };
181 
185 enum {
186  EMCUTE_OK = 0,
187  EMCUTE_NOGW = -1,
192 };
193 
197 typedef struct {
198  const char *name;
199  uint16_t id;
201 
209 typedef void(*emcute_cb_t)(const emcute_topic_t *topic, void *data, size_t len);
210 
214 typedef struct emcute_sub {
215  struct emcute_sub *next;
218  void *arg;
219 } emcute_sub_t;
220 
242 int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic,
243  const void *will_msg, size_t will_msg_len, unsigned flags);
244 
252 int emcute_discon(void);
253 
265 int emcute_reg(emcute_topic_t *topic);
266 
283 int emcute_pub(emcute_topic_t *topic, const void *buf, size_t len,
284  unsigned flags);
285 
303 int emcute_sub(emcute_sub_t *sub, unsigned flags);
304 
314 int emcute_unsub(emcute_sub_t *sub);
315 
329 int emcute_willupd_topic(const char *topic, unsigned flags);
330 
344 int emcute_willupd_msg(const void *data, size_t len);
345 
355 void emcute_run(uint16_t port, const char *id);
356 
367 const char *emcute_type_str(uint8_t type);
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 
373 #endif /* NET_EMCUTE_H */
374 
const char * name
topic string (currently ACSII only)
Definition: emcute.h:198
struct emcute_sub * next
next subscription (saved in a list)
Definition: emcute.h:215
error: operation was rejected by broker
Definition: emcute.h:188
error: feature not supported
Definition: emcute.h:191
error: not connected to a gateway
Definition: emcute.h:187
UDP sock definitions.
error: ran out of buffer space
Definition: emcute.h:189
emcute_topic_t topic
topic we subscribe to
Definition: emcute.h:216
int emcute_sub(emcute_sub_t *sub, unsigned flags)
Subscribe to the given topic.
QoS level 2.
Definition: emcute.h:170
int emcute_willupd_topic(const char *topic, unsigned flags)
Update the last will topic.
emcute_cb_t cb
function called when receiving messages
Definition: emcute.h:217
retain flag
Definition: emcute.h:173
Data-structure for keeping track of topics we register to.
Definition: emcute.h:214
topic ID: normal
Definition: emcute.h:179
int emcute_willupd_msg(const void *data, size_t len)
Update the last will message.
int emcute_pub(emcute_topic_t *topic, const void *buf, size_t len, unsigned flags)
Publish data on the given topic.
MQTT-SN topic.
Definition: emcute.h:197
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 &#39;occupy&#39; the calling thread.
topic ID type mask
Definition: emcute.h:176
uint16_t id
topic id, as assigned by the gateway
Definition: emcute.h:199
Common IP-based transport layer end point.
Definition: sock.h:195
topic ID: short
Definition: emcute.h:177
everything went as expect
Definition: emcute.h:186
QoS level 0.
Definition: emcute.h:172
int emcute_reg(emcute_topic_t *topic)
Get a topic ID for the given topic name from the gateway.
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:209
QoS level mask.
Definition: emcute.h:169
clean session flag
Definition: emcute.h:175
QoS level 1.
Definition: emcute.h:171
will flag, used during CONNECT
Definition: emcute.h:174
int emcute_discon(void)
Disconnect from the gateway we are currently connected to.
duplicate flag
Definition: emcute.h:168
error: timeout
Definition: emcute.h:190
const char * emcute_type_str(uint8_t type)
Return the string representation of the given type value.
void * arg
optional custom argument
Definition: emcute.h:218
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_unsub(emcute_sub_t *sub)
Unsubscripbe the given topic.
topic ID: pre-defined
Definition: emcute.h:178