summaryrefslogtreecommitdiff
path: root/src/mqtt.c
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2024-11-03 22:07:54 +0100
committerThomas Schmucker <ts@its1.de>2024-11-03 22:07:54 +0100
commit6d804810804e09c30b348ce7287ac175e41d7881 (patch)
treee9cb4164bac336ab3af90dc01650e9d0972a2cc5 /src/mqtt.c
parentf15530cbfa7b2e344844a36e1a199301a81b6383 (diff)
downloaduse-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.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/mqtt.c b/src/mqtt.c
index ce89b0b..32e2ea9 100644
--- a/src/mqtt.c
+++ b/src/mqtt.c
@@ -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
45void 47void
46mqtt_run(struct mosquitto *client, const char *topics[], const volatile bool *quit) 48mqtt_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
64void 72void