Use mg_str, not pointers, in mg_mqtt_{sub,pub}

This commit is contained in:
Sergey Lyubka committed 2022-01-19 09:57:27 +00:00
1 parent fe813ee247
commit 226917e1cd
9 files changed
+45 -48

No files matched your search

+2 -2
View File
@@ -54,7 +54,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
struct mg_str topic = mg_str(s_rx_topic);
LOG(LL_INFO, ("Connected to %s", s_url));
LOG(LL_INFO, ("Subscribing to %s", s_rx_topic));
mg_mqtt_sub(c, &topic, s_qos);
mg_mqtt_sub(c, topic, s_qos);
c->label[0] = 'X'; // Set a label that we're logged in
} else if (ev == MG_EV_MQTT_MSG) {
// When we receive MQTT message, print it
@@ -67,7 +67,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (now_second != prev_second) {
struct mg_str topic = mg_str(s_tx_topic), data = mg_str("{\"a\":123}");
LOG(LL_INFO, ("Publishing to %s", s_tx_topic));
mg_mqtt_pub(c, &topic, &data, s_qos, false);
mg_mqtt_pub(c, topic, data, s_qos, false);
prev_second = now_second;
}
}
+2 -2
View File
@@ -43,10 +43,10 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
struct mg_str subt = mg_str(s_sub_topic);
struct mg_str pubt = mg_str(s_pub_topic), data = mg_str("hello");
LOG(LL_INFO, ("CONNECTED to %s", s_url));
mg_mqtt_sub(c, &subt, s_qos);
mg_mqtt_sub(c, subt, s_qos);
LOG(LL_INFO, ("SUBSCRIBED to %.*s", (int) subt.len, subt.ptr));
mg_mqtt_pub(c, &pubt, &data, s_qos, false);
mg_mqtt_pub(c, pubt, data, s_qos, false);
LOG(LL_INFO, ("PUBSLISHED %.*s -> %.*s", (int) data.len, data.ptr,
(int) pubt.len, pubt.ptr));
} else if (ev == MG_EV_MQTT_MSG) {
+2 -2
View File
@@ -46,10 +46,10 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
struct mg_str topic = mg_str(s_topic), data = mg_str("hello");
size_t len = c->send.len;
LOG(LL_INFO, ("CONNECTED to %s", s_url));
mg_mqtt_sub(c, &topic, 1);
mg_mqtt_sub(c, topic, 1);
mg_ws_wrap(c, len, WEBSOCKET_OP_BINARY);
LOG(LL_INFO, ("SUBSCRIBED to %.*s", (int) topic.len, topic.ptr));
mg_mqtt_pub(c, &topic, &data, 1, false);
mg_mqtt_pub(c, topic, data, 1, false);
LOG(LL_INFO, ("PUBSLISHED %.*s -> %.*s", (int) data.len, data.ptr,
(int) topic.len, topic.ptr));
len = mg_ws_wrap(c, c->send.len - len, WEBSOCKET_OP_BINARY);