Skip to content

shell: mqtt: use topic levels #92677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jeppenodgaard
Copy link
Collaborator

Change topic from <device_id>_rx (and tx) to <device_id>/sh/rx.

This allows use of wildcards. E.g. subscribe to all devices "+/sh/tx".

Level "sh" is added to the topic to make it less generic and prevent potential clashes with other topics.

@github-actions github-actions bot added the area: Shell Shell subsystem label Jul 4, 2025
@github-actions github-actions bot requested review from carlescufi and jakub-uC July 4, 2025 08:34
@jeppenodgaard jeppenodgaard force-pushed the shell-mqtt-improve-topic branch from e6a8228 to 248510b Compare July 4, 2025 09:09
jakub-uC
jakub-uC previously approved these changes Jul 8, 2025
Copy link
Collaborator

@kartben kartben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind the change but this will be breaking users so needs to be mentioned in the migration guide.

Bonus points if:

  • you consider adding some documentation for the MQTT backend in https://docs.zephyrproject.org/latest/services/shell/index.html#backends (of course this would be a different PR, not asking you to do it here)
  • you consider making the topics being used something that can be configured via Kconfig, since things are pretty inflexible at the moment, as your PR basically highlights. I would argue this could/should be done in this very PR since it would effectively make this change non-breaking for folks if you keep the same default value as before.

Thanks!

@jeppenodgaard
Copy link
Collaborator Author

I don't mind the change but this will be breaking users so needs to be mentioned in the migration guide.

Bonus points if:

* you consider adding some documentation for the MQTT backend in https://docs.zephyrproject.org/latest/services/shell/index.html#backends (of course this would be a different PR, not asking you to do it here)

* you consider making the topics being used something that can be configured via Kconfig, since things are pretty inflexible at the moment, as your PR basically highlights. I would argue this could/should be done in this very PR since it would effectively make this change non-breaking for folks if you keep the same default value as before.

Thanks!

Since 4.2 hard freeze is tomorrow and there no 4.3 release files I created #92961

@jeppenodgaard
Copy link
Collaborator Author

Thank you for your review and insightful feedback @kartben .

you consider making the topics being used something that can be configured via Kconfig, since things are pretty inflexible at the moment, as your PR basically highlights. I would argue this could/should be done in this very PR since it would effectively make this change non-breaking for folks if you keep the same default value as before.

I think it is difficult to make something that is backward compatible and still follow MQTT best practice.

I would like to have SHELL_MQTT_TOPIC_IDENTIFIER which is default sh, SHELL_MQTT_TOPIC_TX_IDENTIFIER which is default tx and SHELL_MQTT_TOPIC_RX_IDENTIFIER which is default rx. This approach does not allow using _ between device identifier and the rest of the topic.

The backward compatible solution would be to make only two Kconfig which would have shared MQTT levels:

  • SHELL_MQTT_TOPIC_RX_IDENTIFIER with default /sh/rx
  • SHELL_MQTT_TOPIC_TX_IDENTIFIER with default /sh/tx

Which is less granular.

Semi-related: I think there is a need for a common MQTT topic device identifier in Kconfig somewhere, so everything that uses MQTT has the same identifier.

@jeppenodgaard jeppenodgaard force-pushed the shell-mqtt-improve-topic branch from 248510b to b7c4db2 Compare July 11, 2025 09:56
@github-actions github-actions bot added the Release Notes To be mentioned in the release notes label Jul 11, 2025
Change topic from <device_id>_rx (and tx) to <device_id>/sh/rx.

This allows use of wildcards. E.g. subscribe to all devices "+/sh/tx".

Level "sh" is added to the topic to make it less generic and prevent
potential clashes with other topics.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
@jeppenodgaard jeppenodgaard force-pushed the shell-mqtt-improve-topic branch from b7c4db2 to a7d2f80 Compare July 11, 2025 09:58
Copy link

Please retry analysis of this Pull-Request directly on SonarQube Cloud

@dkalowsk dkalowsk added this to the v4.3.0 milestone Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Shell Shell subsystem Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants