summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ed93534)
raw | patch | inline | side by side (parent: ed93534)
author | Florian Forster <octo@collectd.org> | |
Thu, 20 Nov 2014 16:42:42 +0000 (17:42 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 6 Jul 2015 12:07:10 +0000 (14:07 +0200) |
This compiles with libmosquitto 0.15.0. It appears newer versions of the
library have some interface changes, so we should add a version check.
Luckily, libmosquitto provides everything we need.
library have some interface changes, so we should add a version check.
Luckily, libmosquitto provides everything we need.
src/mqtt.c | patch | blob | history |
diff --git a/src/mqtt.c b/src/mqtt.c
index 3bed0a5e32e537b9898c4bb7cb3b63085f529ce7..7adc7f7196cd46589fa0e8e0070db844e62701e3 100644 (file)
--- a/src/mqtt.c
+++ b/src/mqtt.c
pthread_mutex_t lock;
};
+static char const *mosquitto_strerror (int code)
+{
+ switch (code)
+ {
+ case MOSQ_ERR_SUCCESS: return "MOSQ_ERR_SUCCESS";
+ case MOSQ_ERR_NOMEM: return "MOSQ_ERR_NOMEM";
+ case MOSQ_ERR_PROTOCOL: return "MOSQ_ERR_PROTOCOL";
+ case MOSQ_ERR_INVAL: return "MOSQ_ERR_INVAL";
+ case MOSQ_ERR_NO_CONN: return "MOSQ_ERR_NO_CONN";
+ case MOSQ_ERR_CONN_REFUSED: return "MOSQ_ERR_CONN_REFUSED";
+ case MOSQ_ERR_NOT_FOUND: return "MOSQ_ERR_NOT_FOUND";
+ case MOSQ_ERR_CONN_LOST: return "MOSQ_ERR_CONN_LOST";
+ case MOSQ_ERR_SSL: return "MOSQ_ERR_SSL";
+ case MOSQ_ERR_PAYLOAD_SIZE: return "MOSQ_ERR_PAYLOAD_SIZE";
+ case MOSQ_ERR_NOT_SUPPORTED: return "MOSQ_ERR_NOT_SUPPORTED";
+ case MOSQ_ERR_AUTH: return "MOSQ_ERR_AUTH";
+ case MOSQ_ERR_ACL_DENIED: return "MOSQ_ERR_ACL_DENIED";
+ case MOSQ_ERR_UNKNOWN: return "MOSQ_ERR_UNKNOWN";
+ case MOSQ_ERR_ERRNO: return "MOSQ_ERR_ERRNO";
+ }
+
+ return "UNKNOWN ERROR CODE";
+}
+
/*
* Functions
*/
} /* mqtt_reconnect_broker */
static int mqtt_publish_message (struct mqtt_client_conf *conf, char *topic,
- char *payload, size_t payload_len)
+ void const *payload, size_t payload_len)
{
char errbuf[1024];
int status;
memset (&user_data, 0, sizeof (user_data));
user_data.data = conf;
- if ((conf->mosq = mosquitto_new (conf->client_id, true, NULL)) == NULL) {
- ERROR ("mqtt_config: mosquitto_new failed");
+ conf->mosq = mosquitto_new (conf->client_id, /* user data = */ conf);
+ if (conf->mosq == NULL)
+ {
+ ERROR ("mqtt plugin: mosquitto_new failed");
+ free (conf);
return (-1);
}
- status = mosquitto_connect (conf->mosq, conf->host, conf->port, 10);
-
+ status = mosquitto_connect (conf->mosq, conf->host, conf->port,
+ /* keepalive = */ 10, /* clean session = */ 1);
if (status != MOSQ_ERR_SUCCESS) {
ERROR ("mqtt_config: mosquitto_connect failed: %s",
(status == MOSQ_ERR_ERRNO ?