mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-27 20:48:29 +00:00
Add mg_mqtt_pubex
This commit is contained in:
1 parent
886a29d659
commit
a15d518571
6 files changed
+58
-21
No files matched your search
+9
-4
@@ -1,8 +1,8 @@
|
||||
#include "mqtt.h"
|
||||
#include "arch.h"
|
||||
#include "base64.h"
|
||||
#include "event.h"
|
||||
#include "log.h"
|
||||
#include "mqtt.h"
|
||||
#include "private.h"
|
||||
#include "url.h"
|
||||
#include "util.h"
|
||||
@@ -81,9 +81,9 @@ static void mqtt_login(struct mg_connection *c, const char *url,
|
||||
}
|
||||
}
|
||||
|
||||
void mg_mqtt_pub(struct mg_connection *c, struct mg_str *topic,
|
||||
struct mg_str *data) {
|
||||
uint8_t flags = MQTT_QOS(1);
|
||||
void mg_mqtt_pubex(struct mg_connection *c, struct mg_str *topic,
|
||||
struct mg_str *data, int qos, bool retain) {
|
||||
uint8_t flags = (uint8_t)((qos & 3) << 1) | (retain ? 1 : 0);
|
||||
uint32_t total_len = 2 + (uint32_t) topic->len + (uint32_t) data->len;
|
||||
LOG(LL_DEBUG, ("%lu [%.*s] -> [%.*s]", c->id, (int) topic->len,
|
||||
(char *) topic->ptr, (int) data->len, (char *) data->ptr));
|
||||
@@ -99,6 +99,11 @@ void mg_mqtt_pub(struct mg_connection *c, struct mg_str *topic,
|
||||
mg_send(c, data->ptr, data->len);
|
||||
}
|
||||
|
||||
void mg_mqtt_pub(struct mg_connection *c, struct mg_str *topic,
|
||||
struct mg_str *data) {
|
||||
mg_mqtt_pubex(c, topic, data, 1, false);
|
||||
}
|
||||
|
||||
void mg_mqtt_sub(struct mg_connection *c, struct mg_str *topic) {
|
||||
static uint16_t s_id;
|
||||
uint8_t qos = 1;
|
||||
|
||||
Reference in new issue
Block a user