diff options
Diffstat (limited to 'src/mqtt.c')
| -rw-r--r-- | src/mqtt.c | 14 |
1 files changed, 8 insertions, 6 deletions
| @@ -14,7 +14,6 @@ mqtt_connect(const char *clientid, // NOLINT | |||
| 14 | const char *password, // NOLINT | 14 | const char *password, // NOLINT |
| 15 | const char *hostname, // NOLINT | 15 | const char *hostname, // NOLINT |
| 16 | int port, | 16 | int port, |
| 17 | void callback(struct mosquitto *, void *, const struct mosquitto_message *), | ||
| 18 | void *userdata) | 17 | void *userdata) |
| 19 | { | 18 | { |
| 20 | struct mosquitto *client = mosquitto_new(clientid, true, userdata); | 19 | struct mosquitto *client = mosquitto_new(clientid, true, userdata); |
| @@ -30,10 +29,6 @@ mqtt_connect(const char *clientid, // NOLINT | |||
| 30 | return NULL; | 29 | return NULL; |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | if ( callback ) { | ||
| 34 | mosquitto_message_callback_set(client, callback); | ||
| 35 | } | ||
| 36 | |||
| 37 | err = mosquitto_connect(client, hostname, port, KEEPALIVE); | 32 | err = mosquitto_connect(client, hostname, port, KEEPALIVE); |
| 38 | if ( err != MOSQ_ERR_SUCCESS ) { | 33 | if ( err != MOSQ_ERR_SUCCESS ) { |
| 39 | (void) fprintf(stderr, "error: %s\n", mosquitto_strerror(err)); | 34 | (void) fprintf(stderr, "error: %s\n", mosquitto_strerror(err)); |
| @@ -45,8 +40,15 @@ mqtt_connect(const char *clientid, // NOLINT | |||
| 45 | } | 40 | } |
| 46 | 41 | ||
| 47 | void | 42 | void |
| 48 | mqtt_run(struct mosquitto *client, const char *topics[], const volatile bool *quit) | 43 | mqtt_run(struct mosquitto *client, |
| 44 | const char *topics[], | ||
| 45 | void callback(struct mosquitto *, void *, const struct mosquitto_message *), | ||
| 46 | const volatile bool *quit) | ||
| 49 | { | 47 | { |
| 48 | if ( callback ) { | ||
| 49 | mosquitto_message_callback_set(client, callback); | ||
| 50 | } | ||
| 51 | |||
| 50 | int *mid = NULL; | 52 | int *mid = NULL; |
| 51 | 53 | ||
| 52 | for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { | 54 | for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { |
