diff --git a/lib/nodes/mqtt.c b/lib/nodes/mqtt.c index 8125b1e1f..de46736a8 100644 --- a/lib/nodes/mqtt.c +++ b/lib/nodes/mqtt.c @@ -63,7 +63,7 @@ static void mqtt_connect_cb(struct mosquitto *mosq, void *userdata, int result) if (m->subscribe) { ret = mosquitto_subscribe(m->client, NULL, m->subscribe, m->qos); if (ret) - warning("MQTT: failed to subscribe to topic '%s' for node %s", m->subscribe, node_name(n)); + warning("MQTT: failed to subscribe to topic '%s' for node %s: %s", m->subscribe, node_name(n), mosquitto_strerror(ret)); } else warning("MQTT: no subscribe for node %s as no subscribe topic is given", node_name(n)); @@ -207,11 +207,11 @@ int mqtt_parse(struct node *n, json_t *cfg) // Some checks ret = mosquitto_sub_topic_check(m->subscribe); if (ret != MOSQ_ERR_SUCCESS) - error("Invalid subscribe topic: '%s' for node %s", m->subscribe, node_name(n)); + error("Invalid subscribe topic: '%s' for node %s: %s", m->subscribe, node_name(n), mosquitto_strerror(ret)); ret = mosquitto_pub_topic_check(m->publish); if (ret != MOSQ_ERR_SUCCESS) - error("Invalid publish topic: '%s' for node %s", m->publish, node_name(n)); + error("Invalid publish topic: '%s' for node %s: %s", m->publish, node_name(n), mosquitto_strerror(ret)); return 0; } @@ -283,17 +283,17 @@ int mqtt_start(struct node *n) if (m->username && m->password) { ret = mosquitto_username_pw_set(m->client, m->username, m->password); if (ret) - return ret; + goto mosquitto_error; } if (m->ssl.enabled) { ret = mosquitto_tls_set(m->client, m->ssl.cafile, m->ssl.capath, m->ssl.certfile, m->ssl.keyfile, NULL); if (ret) - return ret; + goto mosquitto_error; ret = mosquitto_tls_insecure_set(m->client, m->ssl.insecure); if (ret) - return ret; + goto mosquitto_error; } mosquitto_log_callback_set(m->client, mqtt_log_cb); @@ -320,13 +320,18 @@ int mqtt_start(struct node *n) ret = mosquitto_connect(m->client, m->host, m->port, m->keepalive); if (ret) - return ret; + goto mosquitto_error; ret = mosquitto_loop_start(m->client); if (ret) - return ret; + goto mosquitto_error; return 0; + +mosquitto_error: + warning("MQTT: %s", mosquitto_strerror(ret)); + + return ret; } int mqtt_stop(struct node *n) @@ -336,17 +341,22 @@ int mqtt_stop(struct node *n) ret = mosquitto_disconnect(m->client); if (ret) - return ret; + goto mosquitto_error; ret = mosquitto_loop_stop(m->client, 0); if (ret) - return ret; + goto mosquitto_error; ret = io_destroy(&m->io); if (ret) return ret; return 0; + +mosquitto_error: + warning("MQTT: %s", mosquitto_strerror(ret)); + + return ret; } int mqtt_type_start(struct super_node *sn) @@ -355,9 +365,14 @@ int mqtt_type_start(struct super_node *sn) ret = mosquitto_lib_init(); if (ret) - return ret; + goto mosquitto_error; return 0; + +mosquitto_error: + warning("MQTT: %s", mosquitto_strerror(ret)); + + return ret; } int mqtt_type_stop() @@ -366,9 +381,14 @@ int mqtt_type_stop() ret = mosquitto_lib_cleanup(); if (ret) - return ret; + goto mosquitto_error; return 0; + +mosquitto_error: + warning("MQTT: %s", mosquitto_strerror(ret)); + + return ret; } int mqtt_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release)