Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 04cc0a2

Browse files
committed
feat(config): Add CLI for MQTT configures
MQTT host and MQTT subscribe topic root can be assigned with CLI command `--mqtt_host` and `--mqtt_topic_root` respectively close #294
1 parent aee0c73 commit 04cc0a2

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

accelerator/cli_info.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ typedef enum ta_cli_arg_value_e {
3030
IRI_HOST_CLI,
3131
IRI_PORT_CLI,
3232

33+
/** MQTT */
34+
MQTT_HOST_CLI,
35+
MQTT_ROOT_CLI,
36+
3337
/** REDIS */
3438
REDIS_HOST_CLI,
3539
REDIS_PORT_CLI,
@@ -63,6 +67,8 @@ static struct ta_cli_argument_s {
6367
{"ta_thread", optional_argument, NULL, TA_THREAD_COUNT_CLI, "TA executing thread"},
6468
{"iri_host", required_argument, NULL, IRI_HOST_CLI, "IRI listening host"},
6569
{"iri_port", required_argument, NULL, IRI_PORT_CLI, "IRI listening port"},
70+
{"mqtt_host", required_argument, NULL, MQTT_HOST_CLI, "MQTT listening host"},
71+
{"mqtt_root", required_argument, NULL, MQTT_ROOT_CLI, "MQTT listening topic root"},
6672
{"redis_host", required_argument, NULL, REDIS_HOST_CLI, "Redis server listening host"},
6773
{"redis_port", required_argument, NULL, REDIS_PORT_CLI, "Redis server listening port"},
6874
{"db_host", required_argument, NULL, DB_HOST_CLI, "DB server listening host"},

accelerator/config.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ static status_t cli_core_set(ta_core_t* const core, int key, char* const value)
6868
iota_service->http.port = atoi(value);
6969
break;
7070

71+
#ifdef MQTT_ENABLE
72+
// MQTT configuration
73+
case MQTT_HOST_CLI:
74+
ta_conf->mqtt_host = value;
75+
break;
76+
case MQTT_ROOT_CLI:
77+
ta_conf->mqtt_topic_root = value;
78+
break;
79+
#endif
80+
7181
// Cache configuration
7282
case REDIS_HOST_CLI:
7383
cache->host = value;

accelerator/mqtt_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ int main(int argc, char *argv[]) {
2727
return EXIT_FAILURE;
2828
}
2929

30+
// Initialize configurations with configuration file
31+
if (ta_core_file_init(&ta_core, argc, argv) != SC_OK) {
32+
return EXIT_FAILURE;
33+
}
34+
3035
// Initialize configurations with CLI value
3136
if (ta_core_cli_init(&ta_core, argc, argv) != SC_OK) {
3237
return EXIT_FAILURE;

docs/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ MQTT connectivity is an optional feature allowing IoT endpoint devices to collab
5252
make MQTT && bazel run --define mqtt=enable //accelerator
5353
```
5454

55-
Note you may need to set up the `MQTT_HOST` and `TOPIC_ROOT` in `config.h` to connect to a MQTT broker.
55+
Note you may need to set up the `MQTT_HOST` and `TOPIC_ROOT` in `config.h` to connect to a MQTT broker, or you can use CLI option `--mqtt_host`, and `--mqtt_root` to set MQTT broker address and MQTT topic root, respectively.
5656
For more information for MQTT connectivity of `tangle-accelerator`, you could read `connectivity/mqtt/usage.md`.
5757

5858
## Enable external database for transaction reattachment

0 commit comments

Comments
 (0)