diff options
| author | Thomas Schmucker <ts@its1.de> | 2024-10-29 22:06:51 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2024-10-29 22:06:51 +0100 |
| commit | 0714998ef54e8c1a46af7ec48698faa3abdf457a (patch) | |
| tree | dabdfa7688b885d784e50f5a92ccea2d3c41d374 /src | |
| parent | dcc35d185796138838e6165dee4ef5d15d7e1d4c (diff) | |
| download | use-mosquitto-0714998ef54e8c1a46af7ec48698faa3abdf457a.tar.gz use-mosquitto-0714998ef54e8c1a46af7ec48698faa3abdf457a.tar.bz2 use-mosquitto-0714998ef54e8c1a46af7ec48698faa3abdf457a.zip | |
Mehrere Topics möglich und bessere Abbruchsteuerung
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 11 |
1 files changed, 7 insertions, 4 deletions
| @@ -76,11 +76,13 @@ connect(const char *clientid, // NOLINT | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | static void | 78 | static void |
| 79 | run(struct mosquitto *client, const char *topic) | 79 | run(struct mosquitto *client, const char *topics[], const volatile bool *quit) |
| 80 | { | 80 | { |
| 81 | mosquitto_subscribe(client, NULL, topic, 0); | 81 | for ( size_t idx = 0; topics[idx] != NULL; ++idx ) { |
| 82 | mosquitto_subscribe(client, NULL, topics[idx], 0); | ||
| 83 | } | ||
| 82 | 84 | ||
| 83 | while ( !terminate ) { | 85 | while ( !*quit ) { |
| 84 | static const int defaultTimeout = -1; // 1000ms | 86 | static const int defaultTimeout = -1; // 1000ms |
| 85 | 87 | ||
| 86 | int err = mosquitto_loop(client, defaultTimeout, 1); | 88 | int err = mosquitto_loop(client, defaultTimeout, 1); |
| @@ -127,7 +129,8 @@ main(void) | |||
| 127 | return EXIT_FAILURE; | 129 | return EXIT_FAILURE; |
| 128 | } | 130 | } |
| 129 | 131 | ||
| 130 | run(client, TOPIC); | 132 | run(client, (const char *[]){ TOPIC, NULL }, &terminate); |
| 133 | |||
| 131 | shutdown(client); | 134 | shutdown(client); |
| 132 | 135 | ||
| 133 | return EXIT_SUCCESS; | 136 | return EXIT_SUCCESS; |
