feat(mosq): Allow user to enable SYS topic

Mosquitto provides several topics under $SYS/# to capture logs and load
statistics. This allows users to enable it.
This commit is contained in:
Euripedes Rocha
2025-03-05 15:03:59 +01:00
parent 37f84ee5a4
commit 905b84fb97
4 changed files with 46 additions and 6 deletions

View File

@ -21,7 +21,6 @@ set(m_srcs
${m_lib_dir}/handle_pubrec.c
${m_lib_dir}/handle_pubrel.c
${m_lib_dir}/handle_ping.c
${m_lib_dir}/time_mosq.c
${m_lib_dir}/utf8_mosq.c
${m_src_dir}/bridge.c
@ -75,6 +74,7 @@ idf_component_register(SRCS ${m_srcs}
port/config.c
port/signals.c
port/broker.c
port/mosq_time.c
port/files.c
port/net__esp_tls.c
port/sysconf.c
@ -82,9 +82,12 @@ idf_component_register(SRCS ${m_srcs}
${m_incl_dir} ${m_lib_dir} ${m_deps_dir}
INCLUDE_DIRS ${m_incl_dir} port/include
REQUIRES esp-tls
PRIV_REQUIRES newlib sock_utils)
PRIV_REQUIRES newlib sock_utils esp_timer)
target_compile_definitions(${COMPONENT_LIB} PRIVATE "WITH_BROKER")
if (CONFIG_MOSQ_ENABLE_SYS)
target_compile_definitions(${COMPONENT_LIB} PRIVATE "WITH_SYS_TREE")
endif()
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
# Some mosquitto source unconditionally define `_GNU_SOURCE` which collides with IDF build system

View File

@ -0,0 +1,15 @@
menu "Mosquitto"
config MOSQ_ENABLE_SYS
bool "Enable $SYS topics"
default n
help
Enable the $SYS topics for the broker
config MOSQ_SYS_UPDATE_INTERVAL
int "Update interval for the SYS topic"
default 10
depends on MOSQ_ENABLE_SYS
help
Time in seconds for the update of the $SYS topics for the broker
endmenu

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*
* SPDX-FileContributor: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2024-2025 Espressif Systems (Shanghai) CO LTD
*/
#include "mosquitto_internal.h"
#include "mosquitto_broker.h"
@ -14,6 +14,7 @@
#include "utlist.h"
#include "lib_load.h"
#include "syslog.h"
#include "sdkconfig.h"
void config__init(struct mosquitto__config *config)
@ -66,7 +67,7 @@ void config__init(struct mosquitto__config *config)
config->log_file = NULL;
config->log_facility = LOG_DAEMON;
config->log_dest = MQTT3_LOG_STDERR | MQTT3_LOG_DLT;
config->log_dest = MQTT3_LOG_STDERR | MQTT3_LOG_TOPIC;
if (db.verbose) {
config->log_type = UINT_MAX;
} else {
@ -91,7 +92,9 @@ void config__init(struct mosquitto__config *config)
config->queue_qos0_messages = false;
config->retain_available = true;
config->set_tcp_nodelay = false;
config->sys_interval = 10;
#if defined(WITH_SYS_TREE)
config->sys_interval = CONFIG_MOSQ_SYS_UPDATE_INTERVAL;
#endif
config->upgrade_outgoing_qos = false;
config->daemon = false;
@ -236,7 +239,7 @@ char *misc__trimblanks(char *str)
// Dummy definition of fork() to work around IDF warning: " warning: _fork is not implemented and will always fail"
// fork() is used in mosquitto.c to deamonize the broker, which we do not call.
pid_t fork (void)
pid_t fork(void)
{
abort();
return 0;

View File

@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <time.h>
#include "time_mosq.h"
#include "esp_timer.h"
void mosquitto_time_init(void)
{
}
time_t mosquitto_time(void)
{
return esp_timer_get_time() / 1000000; // Convert microseconds to seconds
}