Add mqtt base topic option (closes #2768)
This commit is contained in:
parent
a863963a70
commit
86a39f2dfb
4 changed files with 13 additions and 5 deletions
|
@ -430,11 +430,12 @@ E.g. -X "n=doorbell,m=OOK_PWM,s=400,l=800,r=7000,g=1000,match={24}0xa9878c,repea
|
||||||
Add MQTT options with e.g. -F "mqtt://host:1883,opt=arg"
|
Add MQTT options with e.g. -F "mqtt://host:1883,opt=arg"
|
||||||
MQTT options are: user=foo, pass=bar, retain[=0|1], <format>[=topic]
|
MQTT options are: user=foo, pass=bar, retain[=0|1], <format>[=topic]
|
||||||
Default user and password are read from MQTT_USER and MQTT_PASSWORD env vars.
|
Default user and password are read from MQTT_USER and MQTT_PASSWORD env vars.
|
||||||
|
A base topic can be set with base=<topic>, default is "rtl_433/HOSTNAME".
|
||||||
Supported MQTT formats: (default is all)
|
Supported MQTT formats: (default is all)
|
||||||
events: posts JSON event data
|
events: posts JSON event data
|
||||||
states: posts JSON state data
|
states: posts JSON state data
|
||||||
devices: posts device and sensor info in nested topics
|
devices: posts device and sensor info in nested topics
|
||||||
The topic string will expand keys like [/model]
|
Any topic string overrides the base topic and will expand keys like [/model]
|
||||||
E.g. -F "mqtt://localhost:1883,user=USERNAME,pass=PASSWORD,retain=0,devices=rtl_433[/id]"
|
E.g. -F "mqtt://localhost:1883,user=USERNAME,pass=PASSWORD,retain=0,devices=rtl_433[/id]"
|
||||||
With MQTT each rtl_433 instance needs a distinct driver selection. The MQTT Client-ID is computed from the driver string.
|
With MQTT each rtl_433 instance needs a distinct driver selection. The MQTT Client-ID is computed from the driver string.
|
||||||
If you use multiple RTL-SDR, perhaps set a serial and select by that (helps not to get the wrong antenna).
|
If you use multiple RTL-SDR, perhaps set a serial and select by that (helps not to get the wrong antenna).
|
||||||
|
|
|
@ -347,6 +347,9 @@ MQTT options are: user=foo, pass=bar, retain[=0|1], <format>[=topic]
|
||||||
Default user and password are read from MQTT_USER and MQTT_PASSWORD env vars.
|
Default user and password are read from MQTT_USER and MQTT_PASSWORD env vars.
|
||||||
.RE
|
.RE
|
||||||
.RS
|
.RS
|
||||||
|
A base topic can be set with base=<topic>, default is "rtl_433/HOSTNAME".
|
||||||
|
.RE
|
||||||
|
.RS
|
||||||
Supported MQTT formats: (default is all)
|
Supported MQTT formats: (default is all)
|
||||||
.RE
|
.RE
|
||||||
.RS
|
.RS
|
||||||
|
@ -359,7 +362,7 @@ Supported MQTT formats: (default is all)
|
||||||
devices: posts device and sensor info in nested topics
|
devices: posts device and sensor info in nested topics
|
||||||
.RE
|
.RE
|
||||||
.RS
|
.RS
|
||||||
The topic string will expand keys like [/model]
|
Any topic string overrides the base topic and will expand keys like [/model]
|
||||||
.RE
|
.RE
|
||||||
.RS
|
.RS
|
||||||
E.g. \-F "mqtt://localhost:1883,user=USERNAME,pass=PASSWORD,retain=0,devices=rtl_433[/id]"
|
E.g. \-F "mqtt://localhost:1883,user=USERNAME,pass=PASSWORD,retain=0,devices=rtl_433[/id]"
|
||||||
|
|
|
@ -505,8 +505,9 @@ struct data_output *data_output_mqtt_create(struct mg_mgr *mgr, char *param, cha
|
||||||
snprintf(client_id, sizeof(client_id), "rtl_433-%04x%04x%04x", host_crc, devq_crc, parm_crc);
|
snprintf(client_id, sizeof(client_id), "rtl_433-%04x%04x%04x", host_crc, devq_crc, parm_crc);
|
||||||
|
|
||||||
// default base topic
|
// default base topic
|
||||||
char base_topic[8 + sizeof(mqtt->hostname)];
|
char default_base_topic[8 + sizeof(mqtt->hostname)];
|
||||||
snprintf(base_topic, sizeof(base_topic), "rtl_433/%s", mqtt->hostname);
|
snprintf(default_base_topic, sizeof(default_base_topic), "rtl_433/%s", mqtt->hostname);
|
||||||
|
char const *base_topic = default_base_topic;
|
||||||
|
|
||||||
// default topics
|
// default topics
|
||||||
char const *path_devices = "devices[/type][/model][/subtype][/channel][/id]";
|
char const *path_devices = "devices[/type][/model][/subtype][/channel][/id]";
|
||||||
|
@ -545,6 +546,8 @@ struct data_output *data_output_mqtt_create(struct mg_mgr *mgr, char *param, cha
|
||||||
retain = atobv(val, 1);
|
retain = atobv(val, 1);
|
||||||
else if (!strcasecmp(key, "q") || !strcasecmp(key, "qos"))
|
else if (!strcasecmp(key, "q") || !strcasecmp(key, "qos"))
|
||||||
qos = atoiv(val, 1);
|
qos = atoiv(val, 1);
|
||||||
|
else if (!strcasecmp(key, "b") || !strcasecmp(key, "base"))
|
||||||
|
base_topic = val;
|
||||||
// Simple key-topic mapping
|
// Simple key-topic mapping
|
||||||
else if (!strcasecmp(key, "d") || !strcasecmp(key, "devices"))
|
else if (!strcasecmp(key, "d") || !strcasecmp(key, "devices"))
|
||||||
mqtt->devices = mqtt_topic_default(val, base_topic, path_devices);
|
mqtt->devices = mqtt_topic_default(val, base_topic, path_devices);
|
||||||
|
|
|
@ -282,11 +282,12 @@ static void help_output(void)
|
||||||
"\tAdd MQTT options with e.g. -F \"mqtt://host:1883,opt=arg\"\n"
|
"\tAdd MQTT options with e.g. -F \"mqtt://host:1883,opt=arg\"\n"
|
||||||
"\tMQTT options are: user=foo, pass=bar, retain[=0|1], <format>[=topic]\n"
|
"\tMQTT options are: user=foo, pass=bar, retain[=0|1], <format>[=topic]\n"
|
||||||
"\tDefault user and password are read from MQTT_USER and MQTT_PASSWORD env vars.\n"
|
"\tDefault user and password are read from MQTT_USER and MQTT_PASSWORD env vars.\n"
|
||||||
|
"\tA base topic can be set with base=<topic>, default is \"rtl_433/HOSTNAME\".\n"
|
||||||
"\tSupported MQTT formats: (default is all)\n"
|
"\tSupported MQTT formats: (default is all)\n"
|
||||||
"\t events: posts JSON event data\n"
|
"\t events: posts JSON event data\n"
|
||||||
"\t states: posts JSON state data\n"
|
"\t states: posts JSON state data\n"
|
||||||
"\t devices: posts device and sensor info in nested topics\n"
|
"\t devices: posts device and sensor info in nested topics\n"
|
||||||
"\tThe topic string will expand keys like [/model]\n"
|
"\tAny topic string overrides the base topic and will expand keys like [/model]\n"
|
||||||
"\tE.g. -F \"mqtt://localhost:1883,user=USERNAME,pass=PASSWORD,retain=0,devices=rtl_433[/id]\"\n"
|
"\tE.g. -F \"mqtt://localhost:1883,user=USERNAME,pass=PASSWORD,retain=0,devices=rtl_433[/id]\"\n"
|
||||||
"\tWith MQTT each rtl_433 instance needs a distinct driver selection. The MQTT Client-ID is computed from the driver string.\n"
|
"\tWith MQTT each rtl_433 instance needs a distinct driver selection. The MQTT Client-ID is computed from the driver string.\n"
|
||||||
"\tIf you use multiple RTL-SDR, perhaps set a serial and select by that (helps not to get the wrong antenna).\n"
|
"\tIf you use multiple RTL-SDR, perhaps set a serial and select by that (helps not to get the wrong antenna).\n"
|
||||||
|
|
Loading…
Add table
Reference in a new issue