diff --git a/mongoose.c b/mongoose.c index 2d5f50d8..b96f1f45 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2019,6 +2019,18 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, (void) fn_data; } +void mg_mqtt_ping(struct mg_connection *nc) { + mg_mqtt_send_header(nc, MQTT_CMD_PINGREQ, 0, 0); +} + +void mg_mqtt_pong(struct mg_connection *nc) { + mg_mqtt_send_header(nc, MQTT_CMD_PINGRESP, 0, 0); +} + +void mg_mqtt_disconnect(struct mg_connection *nc) { + mg_mqtt_send_header(nc, MQTT_CMD_DISCONNECT, 0, 0); +} + struct mg_connection *mg_mqtt_connect(struct mg_mgr *mgr, const char *url, struct mg_mqtt_opts *opts, mg_event_handler_t fn, void *fn_data) { diff --git a/mongoose.h b/mongoose.h index fab27a4f..7b24ec85 100644 --- a/mongoose.h +++ b/mongoose.h @@ -829,6 +829,9 @@ void mg_mqtt_send_header(struct mg_connection *, uint8_t cmd, uint8_t flags, uint32_t len); int mg_mqtt_next_sub(struct mg_mqtt_message *msg, struct mg_str *topic, uint8_t *qos, int pos); +void mg_mqtt_ping(struct mg_connection *); +void mg_mqtt_pong(struct mg_connection *); +void mg_mqtt_disconnect(struct mg_connection *); diff --git a/src/mqtt.c b/src/mqtt.c index 25dd9960..a857c197 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -232,6 +232,18 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, (void) fn_data; } +void mg_mqtt_ping(struct mg_connection *nc) { + mg_mqtt_send_header(nc, MQTT_CMD_PINGREQ, 0, 0); +} + +void mg_mqtt_pong(struct mg_connection *nc) { + mg_mqtt_send_header(nc, MQTT_CMD_PINGRESP, 0, 0); +} + +void mg_mqtt_disconnect(struct mg_connection *nc) { + mg_mqtt_send_header(nc, MQTT_CMD_DISCONNECT, 0, 0); +} + struct mg_connection *mg_mqtt_connect(struct mg_mgr *mgr, const char *url, struct mg_mqtt_opts *opts, mg_event_handler_t fn, void *fn_data) { diff --git a/src/mqtt.h b/src/mqtt.h index 77b09cc8..00ec6213 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -55,3 +55,6 @@ void mg_mqtt_send_header(struct mg_connection *, uint8_t cmd, uint8_t flags, uint32_t len); int mg_mqtt_next_sub(struct mg_mqtt_message *msg, struct mg_str *topic, uint8_t *qos, int pos); +void mg_mqtt_ping(struct mg_connection *); +void mg_mqtt_pong(struct mg_connection *); +void mg_mqtt_disconnect(struct mg_connection *);