From 7735ded57fbb5834efc2f6185fb668ec70923e7f Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sat, 11 Jul 2026 13:59:01 +0200 Subject: zwei Topics, überflüssige Variable entfernt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.h.in | 4 ++++ src/mqtt.c | 6 ++---- src/publish.c | 15 +++++++-------- src/subscribe.c | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/config.h.in b/config.h.in index aca08e7..1e4e454 100644 --- a/config.h.in +++ b/config.h.in @@ -24,6 +24,10 @@ # define TOPIC "topic" #endif +#ifndef TOPIC2 +# define TOPIC2 "topic2" +#endif + #ifndef KEEPALIVE # define KEEPALIVE 10 #endif diff --git a/src/mqtt.c b/src/mqtt.c index 5a8bfc0..be4b9d2 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -49,10 +49,8 @@ mqtt_handle_messages(struct mosquitto *client, mosquitto_message_callback_set(client, callback); } - int *mid = NULL; - for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { - mosquitto_subscribe(client, mid, topics[idx], 0); + mosquitto_subscribe(client, NULL, topics[idx], 0); } while ( !*quit ) { @@ -67,7 +65,7 @@ mqtt_handle_messages(struct mosquitto *client, } for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { - mosquitto_unsubscribe(client, mid, topics[idx]); + mosquitto_unsubscribe(client, NULL, topics[idx]); } } diff --git a/src/publish.c b/src/publish.c index 28a9c3a..542e5e9 100644 --- a/src/publish.c +++ b/src/publish.c @@ -18,12 +18,6 @@ # define MAX_COMMAND_LENGTH 100 #endif -static bool -streq(const char *lhs, const char *rhs) -{ - return strcmp(lhs, rhs) == 0; -} - static void application_cleanup(void) { @@ -37,6 +31,12 @@ application_init(void) (void) atexit(application_cleanup); } +static bool +streq(const char *lhs, const char *rhs) +{ + return strcmp(lhs, rhs) == 0; +} + static void application_run(struct mosquitto *client) { @@ -61,12 +61,11 @@ application_run(struct mosquitto *client) } else if ( streq(command, "send") ) { static const char payload[] = "ich bin ein payload"; - static const char topic[] = "testtopic"; int err = mosquitto_publish( client, NULL, - topic, + TOPIC, sizeof payload, payload, 0, diff --git a/src/subscribe.c b/src/subscribe.c index 3d8611e..d612b02 100644 --- a/src/subscribe.c +++ b/src/subscribe.c @@ -72,7 +72,7 @@ main(void) } mqtt_handle_messages(client, - (const char *[]){ TOPIC, "testtopic", NULL }, + (const char *[]){ TOPIC, TOPIC2, NULL }, callback, &terminate); -- cgit v1.3