diff options
| author | Thomas Schmucker <ts@its1.de> | 2024-11-03 22:07:54 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2024-11-03 22:07:54 +0100 |
| commit | 6d804810804e09c30b348ce7287ac175e41d7881 (patch) | |
| tree | e9cb4164bac336ab3af90dc01650e9d0972a2cc5 /src/mqtt.c | |
| parent | f15530cbfa7b2e344844a36e1a199301a81b6383 (diff) | |
| download | use-mosquitto-6d804810804e09c30b348ce7287ac175e41d7881.tar.gz use-mosquitto-6d804810804e09c30b348ce7287ac175e41d7881.tar.bz2 use-mosquitto-6d804810804e09c30b348ce7287ac175e41d7881.zip | |
publisher hinzugefügt
Diffstat (limited to 'src/mqtt.c')
| -rw-r--r-- | src/mqtt.c | 12 |
1 files changed, 10 insertions, 2 deletions
| @@ -30,7 +30,9 @@ mqtt_connect(const char *clientid, // NOLINT | |||
| 30 | return NULL; | 30 | return NULL; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | mosquitto_message_callback_set(client, callback); | 33 | if ( callback ) { |
| 34 | mosquitto_message_callback_set(client, callback); | ||
| 35 | } | ||
| 34 | 36 | ||
| 35 | err = mosquitto_connect(client, hostname, port, KEEPALIVE); | 37 | err = mosquitto_connect(client, hostname, port, KEEPALIVE); |
| 36 | if ( err != MOSQ_ERR_SUCCESS ) { | 38 | if ( err != MOSQ_ERR_SUCCESS ) { |
| @@ -45,8 +47,10 @@ mqtt_connect(const char *clientid, // NOLINT | |||
| 45 | void | 47 | void |
| 46 | mqtt_run(struct mosquitto *client, const char *topics[], const volatile bool *quit) | 48 | mqtt_run(struct mosquitto *client, const char *topics[], const volatile bool *quit) |
| 47 | { | 49 | { |
| 50 | int *mid = NULL; | ||
| 51 | |||
| 48 | for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { | 52 | for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { |
| 49 | mosquitto_subscribe(client, NULL, topics[idx], 0); | 53 | mosquitto_subscribe(client, mid, topics[idx], 0); |
| 50 | } | 54 | } |
| 51 | 55 | ||
| 52 | while ( !*quit ) { | 56 | while ( !*quit ) { |
| @@ -59,6 +63,10 @@ mqtt_run(struct mosquitto *client, const char *topics[], const volatile bool *qu | |||
| 59 | mosquitto_reconnect(client); | 63 | mosquitto_reconnect(client); |
| 60 | } | 64 | } |
| 61 | } | 65 | } |
| 66 | |||
| 67 | for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { | ||
| 68 | mosquitto_unsubscribe(client, mid, topics[idx]); | ||
| 69 | } | ||
| 62 | } | 70 | } |
| 63 | 71 | ||
| 64 | void | 72 | void |
