diff --git a/doc/releases/migration-guide-4.3.rst b/doc/releases/migration-guide-4.3.rst index b6fb69c1f08f4..936448733dbc4 100644 --- a/doc/releases/migration-guide-4.3.rst +++ b/doc/releases/migration-guide-4.3.rst @@ -146,6 +146,16 @@ Logging used. The new script supports the same functionality (and more), but requires different command line arguments when invoked. +Shell +===== + +* The MQTT topics related to :kconfig:option:`SHELL_BACKEND_MQTT` have been renamed. Renamed + ``_rx`` to ``/sh/rx`` and ``_tx`` to ``/sh/rx``. The + part after the ```` is now configurable via :kconfig:option:`SHELL_MQTT_TOPIC_RX_ID` + and :kconfig:option:`SHELL_MQTT_TOPIC_TX_ID`. This allows keeping the previous topics for backward + compatibility. + (:github:`92677`). + .. zephyr-keep-sorted-stop Modules diff --git a/include/zephyr/shell/shell_mqtt.h b/include/zephyr/shell/shell_mqtt.h index 92ce6987efefc..4a96f9f0eac5d 100644 --- a/include/zephyr/shell/shell_mqtt.h +++ b/include/zephyr/shell/shell_mqtt.h @@ -25,7 +25,8 @@ extern "C" { #define SH_MQTT_BUFFER_SIZE 64 #define DEVICE_ID_BIN_MAX_SIZE 3 #define DEVICE_ID_HEX_MAX_SIZE ((DEVICE_ID_BIN_MAX_SIZE * 2) + 1) -#define SH_MQTT_TOPIC_MAX_SIZE DEVICE_ID_HEX_MAX_SIZE + 3 +#define SH_MQTT_TOPIC_RX_MAX_SIZE DEVICE_ID_HEX_MAX_SIZE + sizeof(CONFIG_SHELL_MQTT_TOPIC_RX_ID) +#define SH_MQTT_TOPIC_TX_MAX_SIZE DEVICE_ID_HEX_MAX_SIZE + sizeof(CONFIG_SHELL_MQTT_TOPIC_TX_ID) extern const struct shell_transport_api shell_mqtt_transport_api; @@ -40,8 +41,8 @@ struct shell_mqtt_tx_buf { /** MQTT-based shell transport. */ struct shell_mqtt { char device_id[DEVICE_ID_HEX_MAX_SIZE]; - char sub_topic[SH_MQTT_TOPIC_MAX_SIZE]; - char pub_topic[SH_MQTT_TOPIC_MAX_SIZE]; + char sub_topic[SH_MQTT_TOPIC_RX_MAX_SIZE]; + char pub_topic[SH_MQTT_TOPIC_TX_MAX_SIZE]; /** Handler function registered by shell. */ shell_transport_handler_t shell_handler; diff --git a/subsys/shell/backends/Kconfig.backends b/subsys/shell/backends/Kconfig.backends index c68ec201197c2..ebeb4792bf19d 100644 --- a/subsys/shell/backends/Kconfig.backends +++ b/subsys/shell/backends/Kconfig.backends @@ -288,8 +288,7 @@ config SHELL_BACKEND_MQTT select DNS_RESOLVER select HWINFO select MQTT_LIB - select NET_MGMT - select NET_MGMT_EVENT + select NET_CONNECTION_MANAGER help Enable MQTT backend. @@ -348,6 +347,18 @@ config SHELL_MQTT_LISTEN_TIMEOUT_MS help Time to listen for incoming packets in milliseconds. +config SHELL_MQTT_TOPIC_RX_ID + string "MQTT topic receive identifier" + default "/sh/rx" + help + String used as receive identifier in the MQTT topic. + +config SHELL_MQTT_TOPIC_TX_ID + string "MQTT topic transmit identifier" + default "/sh/tx" + help + String used as transmit identifier in the MQTT topic. + module = SHELL_BACKEND_MQTT default-timeout = 100 source "subsys/shell/Kconfig.template.shell_log_queue_timeout" diff --git a/subsys/shell/backends/shell_mqtt.c b/subsys/shell/backends/shell_mqtt.c index dcc7f83812e2f..7588fa25a012a 100644 --- a/subsys/shell/backends/shell_mqtt.c +++ b/subsys/shell/backends/shell_mqtt.c @@ -657,8 +657,10 @@ static int init(const struct shell_transport *transport, const void *config, LOG_DBG("Client ID is %s", sh->device_id); - (void)snprintf(sh->pub_topic, SH_MQTT_TOPIC_MAX_SIZE, "%s_tx", sh->device_id); - (void)snprintf(sh->sub_topic, SH_MQTT_TOPIC_MAX_SIZE, "%s_rx", sh->device_id); + (void)snprintf(sh->pub_topic, SH_MQTT_TOPIC_TX_MAX_SIZE, "%s" CONFIG_SHELL_MQTT_TOPIC_TX_ID, + sh->device_id); + (void)snprintf(sh->sub_topic, SH_MQTT_TOPIC_RX_MAX_SIZE, "%s" CONFIG_SHELL_MQTT_TOPIC_RX_ID, + sh->device_id); ring_buf_init(&sh->rx_rb, RX_RB_SIZE, sh->rx_rb_buf);