Skip to content

Commit

Permalink
Add workaround for long keys= in mqtt-publisher
Browse files Browse the repository at this point in the history
This fixes #3084
  • Loading branch information
ondras12345 authored and andypugh committed Sep 1, 2024
1 parent adfc62f commit 317595e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
46 changes: 29 additions & 17 deletions docs/src/man/man1/mqtt-publisher.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ debian this is available from the `python3-paho-mqtt` package.

The name of HAL pins, signals and other values to publish using
MQTT. The names are also used as the JSON keys in the MQTT
message published with the broker.
message published with the broker. If multiple "keys=" options
are specified, the lists are merged.

*--dryrun*::

Expand Down Expand Up @@ -94,22 +95,33 @@ The loop reading HAL values and publishing MQTT messages.
Any set of HAL pins and signals can be published. This setup might be
a useful starting point:

loadusr -W mqtt-publisher [MQTT]DRYRUN --mqtt-broker=[MQTT]BROKER
--mqtt-user=[MQTT]USERNAME --mqtt-password=[MQTT]PASSWORD
keys=halui.axis.a.pos-feedback,halui.axis.b.pos-feedback,
halui.axis.c.pos-feedback,halui.axis.u.pos-feedback,
halui.axis.v.pos-feedback,halui.axis.w.pos-feedback,
halui.axis.x.pos-feedback,halui.axis.y.pos-feedback,
halui.axis.z.pos-feedback,halui.estop.is-activated,
halui.joint.0.is-homed,halui.joint.1.is-homed,halui.joint.2.is-homed,
halui.joint.3.is-homed,halui.joint.4.is-homed,halui.joint.5.is-homed,
halui.joint.6.is-homed,halui.joint.7.is-homed,halui.joint.8.is-homed,
halui.machine.is-on,halui.max-velocity.value,halui.mode.is-auto,
halui.mode.is-manual,halui.mode.is-mdi,halui.mode.is-teleop,
halui.program.is-running'

Note, the list of keys can not include space after comma. The lines
are only broken here to avoid too long lines in the documentation.
----
loadusr -W mqtt-publisher \
[MQTT]DRYRUN \
--mqtt-broker=[MQTT]BROKER
--mqtt-user=[MQTT]USERNAME \
--mqtt-password=[MQTT]PASSWORD \
keys=halui.axis.a.pos-feedback,halui.axis.b.pos-feedback,\
halui.axis.c.pos-feedback,halui.axis.u.pos-feedback,\
halui.axis.v.pos-feedback,halui.axis.w.pos-feedback,\
halui.axis.x.pos-feedback,halui.axis.y.pos-feedback,\
halui.axis.z.pos-feedback \
keys=halui.estop.is-activated, halui.joint.0.is-homed,\
halui.joint.1.is-homed,halui.joint.2.is-homed,halui.joint.3.is-homed,\
halui.joint.4.is-homed,halui.joint.5.is-homed,halui.joint.6.is-homed,\
halui.joint.7.is-homed,halui.joint.8.is-homed \
keys=halui.machine.is-on,halui.max-velocity.value,halui.mode.is-auto,
halui.mode.is-manual,halui.mode.is-mdi,halui.mode.is-teleop,
halui.program.is-running
----

Note: It is recommended to use the line continuation character "\" as
shown here to improve readability. But note that spaces must be left in
to delimit options, and must not be included (including at the beginning
of a line) inside a single option.

HAL limits a single option/token (for example "keys=") to 255 characters.
To work around this issue use multiple "keys=" entries as shown.

== SEE ALSO

Expand Down
4 changes: 2 additions & 2 deletions src/hal/user_comps/mqtt-publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def usage():
@staticmethod
def main():
from optparse import Option, OptionParser
keys={}
keys=[]
options = [
Option( '--dryrun', dest='dryrun', action='store_true',
help='Dryrun, only collect HAL pin values, do not send them to MQTT.'),
Expand Down Expand Up @@ -147,7 +147,7 @@ def main():

for extra in args:
if 0 == extra.find('keys='):
keys = extra.split('=')[1].split(',')
keys.extend(extra.split('=')[1].split(','))

h = LinuxCNC2MQTT(opts.mqttbroker, opts.mqttport, opts.mqttprefix,
opts.mqttuser, opts.mqttpassword, dryrun=opts.dryrun)
Expand Down

0 comments on commit 317595e

Please sign in to comment.