mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-27 20:59:00 +08:00
more Mongoose-style
This commit is contained in:
parent
7d2fca9574
commit
4ceb50d485
@ -204,15 +204,11 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|||||||
// Timer function - recreate client connection if it is closed
|
// Timer function - recreate client connection if it is closed
|
||||||
static void timer_fn(void *arg) {
|
static void timer_fn(void *arg) {
|
||||||
struct mg_mgr *mgr = (struct mg_mgr *) arg;
|
struct mg_mgr *mgr = (struct mg_mgr *) arg;
|
||||||
char status_topic[50];
|
if (s_conn == NULL) {
|
||||||
memset(status_topic, 0, sizeof(status_topic));
|
char *status_topic = mg_mprintf("%s/%s/status", g_root_topic, g_device_id);
|
||||||
mg_snprintf(status_topic, sizeof(status_topic), "%s/%s/status", g_root_topic,
|
char *msg = mg_mprintf("{%m:%m,%m:{%m:%m}}", MG_ESC("method"),
|
||||||
g_device_id);
|
MG_ESC("status.notify"), MG_ESC("params"),
|
||||||
char msg[200];
|
MG_ESC("status"), MG_ESC("offline"));
|
||||||
memset(msg, 0, sizeof(msg));
|
|
||||||
mg_snprintf(msg, sizeof(msg), "{%m:%m,%m:{%m:%m}}", MG_ESC("method"),
|
|
||||||
MG_ESC("status.notify"), MG_ESC("params"), MG_ESC("status"),
|
|
||||||
MG_ESC("offline"));
|
|
||||||
|
|
||||||
struct mg_mqtt_opts opts = {.clean = true,
|
struct mg_mqtt_opts opts = {.clean = true,
|
||||||
.qos = s_qos,
|
.qos = s_qos,
|
||||||
@ -221,7 +217,10 @@ static void timer_fn(void *arg) {
|
|||||||
.keepalive = KEEP_ALIVE_INTERVAL,
|
.keepalive = KEEP_ALIVE_INTERVAL,
|
||||||
.retain = true,
|
.retain = true,
|
||||||
.message = mg_str(msg)};
|
.message = mg_str(msg)};
|
||||||
if (s_conn == NULL) s_conn = mg_mqtt_connect(mgr, g_url, &opts, fn, NULL);
|
s_conn = mg_mqtt_connect(mgr, g_url, &opts, fn, NULL);
|
||||||
|
free(msg);
|
||||||
|
free(status_topic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timer_keepalive(void *arg) {
|
static void timer_keepalive(void *arg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user