Skip to content
Snippets Groups Projects
Commit fddec635 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add -B and -H options to auto-prefix the topic with BBS or host topic prefix

This allows command-lines to be more cross-platform/host

As requested by Nelgin
parent 82ac8f48
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
"use strict"; "use strict";
var mqtt = new MQTT; var mqtt = new MQTT;
var topic; var topic = '';
var msg; var msg;
var retain = false; var retain = false;
const bbs_prefix = "sbbs/" + system.qwk_id + "/";
const host_prefix = bbs_prefix + "host/" + system.local_host_name + "/";
function usage() function usage()
{ {
...@@ -16,6 +18,8 @@ function usage() ...@@ -16,6 +18,8 @@ function usage()
print(" -q QoS value to use, default: " + mqtt.publish_qos); print(" -q QoS value to use, default: " + mqtt.publish_qos);
print(" -r Retain message"); print(" -r Retain message");
print(" -t Topic to publish message to (required)"); print(" -t Topic to publish message to (required)");
print(" -B Prefix the topic with " + bbs_prefix);
print(" -H Prefix the topic with " + host_prefix);
print(" -m Message text to publish"); print(" -m Message text to publish");
print(" -n send a null (zero length) message"); print(" -n send a null (zero length) message");
exit(0); exit(0);
...@@ -26,6 +30,12 @@ for(var i = 0; i < argc; ++i) { ...@@ -26,6 +30,12 @@ for(var i = 0; i < argc; ++i) {
while(arg[0] === '-') while(arg[0] === '-')
arg = arg.substring(1); arg = arg.substring(1);
switch(arg) { switch(arg) {
case 'B':
topic = bbs_prefix;
break;
case 'H':
topic = host_prefix;
break;
case 'h': case 'h':
mqtt.broker_addr = argv[++i]; mqtt.broker_addr = argv[++i];
break; break;
...@@ -45,7 +55,7 @@ for(var i = 0; i < argc; ++i) { ...@@ -45,7 +55,7 @@ for(var i = 0; i < argc; ++i) {
retain = true; retain = true;
break; break;
case 't': case 't':
topic = argv[++i]; topic += argv[++i];
break; break;
case 'v': case 'v':
verbose = true; verbose = true;
...@@ -64,11 +74,8 @@ if(!mqtt.connect()) { ...@@ -64,11 +74,8 @@ if(!mqtt.connect()) {
alert(format("Error (%s) connecting to %s:%u", mqtt.error_str, mqtt.broker_addr, mqtt.broker_port)); alert(format("Error (%s) connecting to %s:%u", mqtt.error_str, mqtt.broker_addr, mqtt.broker_port));
exit(1); exit(1);
} }
//prompt("hit enter");
if(!mqtt.publish(retain, topic, msg)) { if(!mqtt.publish(retain, topic, msg)) {
alert(format("Error (%s) publishing to %s", mqtt.error_str, topic)); alert(format("Error (%s) publishing to %s", mqtt.error_str, topic));
exit(1); exit(1);
} }
//prompt("hit enter");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment