This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 90880743c91408f641e0aeb1f8b6ca58e8883c47
Author: Szymon Janc <[email protected]>
AuthorDate: Wed Oct 14 23:55:36 2026 +0200

    net/mqtt/coremqtt: Add coreMQTT package
    
    Adds package for FreeRTOS coreMQTT, MQTT v5.0 client library, from
    external repository (v5.0.2). coreMQTT is actively maintained, MIT
    licensed, does not allocate memory, does not use threads and is
    independent of network stack, which is provided by user with simple
    send/receive transport interface.
    
    Mynewt glue provides:
     - core_mqtt_config.h with library configuration from syscfg
     - coreMQTT logs routed to modlog (COREMQTT_LOG_MOD, COREMQTT_LOG_LVL)
     - coremqtt_time_ms() that can be used as coreMQTT time function
    
    Assisted-by: Claude:claude-opus-5-5
---
 net/mqtt/coremqtt/include/core_mqtt_config.h  | 70 +++++++++++++++++++++++++++
 net/mqtt/coremqtt/include/coremqtt/coremqtt.h | 54 +++++++++++++++++++++
 net/mqtt/coremqtt/pkg.yml                     | 51 +++++++++++++++++++
 net/mqtt/coremqtt/src/coremqtt.c              | 56 +++++++++++++++++++++
 net/mqtt/coremqtt/syscfg.yml                  | 70 +++++++++++++++++++++++++++
 5 files changed, 301 insertions(+)

diff --git a/net/mqtt/coremqtt/include/core_mqtt_config.h 
b/net/mqtt/coremqtt/include/core_mqtt_config.h
new file mode 100644
index 000000000..f040abf34
--- /dev/null
+++ b/net/mqtt/coremqtt/include/core_mqtt_config.h
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * coreMQTT configuration for Mynewt. This file is included by coreMQTT
+ * through core_mqtt_config_defaults.h; settings come from syscfg.
+ */
+
+#ifndef H_CORE_MQTT_CONFIG_
+#define H_CORE_MQTT_CONFIG_
+
+#include "os/mynewt.h"
+#include "modlog/modlog.h"
+#include "coremqtt/coremqtt.h"
+
+#define MQTT_SUB_UNSUB_MAX_VECTORS MYNEWT_VAL(COREMQTT_SUB_UNSUB_MAX_VECTORS)
+#define MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT                                  \
+    MYNEWT_VAL(COREMQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT)
+#define MQTT_PINGRESP_TIMEOUT_MS MYNEWT_VAL(COREMQTT_PINGRESP_TIMEOUT_MS)
+#define PACKET_TX_TIMEOUT_MS     MYNEWT_VAL(COREMQTT_PACKET_TX_TIMEOUT_MS)
+#define PACKET_RX_TIMEOUT_MS     MYNEWT_VAL(COREMQTT_PACKET_RX_TIMEOUT_MS)
+#define MQTT_RECV_POLLING_TIMEOUT_MS                                          \
+    MYNEWT_VAL(COREMQTT_RECV_POLLING_TIMEOUT_MS)
+#define MQTT_SEND_TIMEOUT_MS MYNEWT_VAL(COREMQTT_SEND_TIMEOUT_MS)
+
+/*
+ * coreMQTT log macros take a single parenthesized argument list, e.g.
+ * LogError(("fmt %d", x)). Levels below the configured minimum compile to
+ * nothing (default definitions from core_mqtt_config_defaults.h).
+ */
+#define COREMQTT_LOG_ENABLED(lvl_)                                            \
+    (MYNEWT_VAL(COREMQTT_LOG_LVL) <= (lvl_) && MYNEWT_VAL(LOG_LEVEL) <= (lvl_))
+
+#if COREMQTT_LOG_ENABLED(LOG_LEVEL_ERROR)
+#define COREMQTT_LOG_ERROR_(...) coremqtt_log(LOG_LEVEL_ERROR, __VA_ARGS__)
+#define LogError(message)        COREMQTT_LOG_ERROR_ message
+#endif
+
+#if COREMQTT_LOG_ENABLED(LOG_LEVEL_WARN)
+#define COREMQTT_LOG_WARN_(...) coremqtt_log(LOG_LEVEL_WARN, __VA_ARGS__)
+#define LogWarn(message)        COREMQTT_LOG_WARN_ message
+#endif
+
+#if COREMQTT_LOG_ENABLED(LOG_LEVEL_INFO)
+#define COREMQTT_LOG_INFO_(...) coremqtt_log(LOG_LEVEL_INFO, __VA_ARGS__)
+#define LogInfo(message)        COREMQTT_LOG_INFO_ message
+#endif
+
+#if COREMQTT_LOG_ENABLED(LOG_LEVEL_DEBUG)
+#define COREMQTT_LOG_DEBUG_(...) coremqtt_log(LOG_LEVEL_DEBUG, __VA_ARGS__)
+#define LogDebug(message)        COREMQTT_LOG_DEBUG_ message
+#endif
+
+#endif
diff --git a/net/mqtt/coremqtt/include/coremqtt/coremqtt.h 
b/net/mqtt/coremqtt/include/coremqtt/coremqtt.h
new file mode 100644
index 000000000..a8e4c8d2c
--- /dev/null
+++ b/net/mqtt/coremqtt/include/coremqtt/coremqtt.h
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_COREMQTT_
+#define H_COREMQTT_
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Returns the current time in milliseconds.
+ *
+ * Can be passed as the time function to MQTT_Init(). The value wraps
+ * around after about 49 days, which coreMQTT handles.
+ *
+ * @return Milliseconds since boot (truncated to 32 bits).
+ */
+uint32_t coremqtt_time_ms(void);
+
+/**
+ * Logs a formatted coreMQTT message to the coreMQTT log module.
+ *
+ * Used by the coreMQTT logging macros; a newline is appended to every
+ * message.
+ *
+ * @param level  Log level (LOG_LEVEL_*).
+ * @param fmt    printf-style format string.
+ */
+void coremqtt_log(uint8_t level, const char *fmt, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/net/mqtt/coremqtt/pkg.yml b/net/mqtt/coremqtt/pkg.yml
new file mode 100644
index 000000000..c50654b8e
--- /dev/null
+++ b/net/mqtt/coremqtt/pkg.yml
@@ -0,0 +1,51 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: net/mqtt/coremqtt
+pkg.description: MQTT v5.0 client library (FreeRTOS coreMQTT)
+pkg.author: "Apache Mynewt <[email protected]>"
+pkg.homepage: "https://github.com/FreeRTOS/coreMQTT";
+pkg.keywords:
+    - mqtt
+pkg.type: sdk
+
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+    - "@apache-mynewt-core/sys/log/modlog"
+
+pkg.include_dirs:
+    - "include"
+    - "@coremqtt/source/include"
+    - "@coremqtt/source/interface"
+
+pkg.source_files:
+    - "src/coremqtt.c"
+    - "@coremqtt/source/core_mqtt.c"
+    - "@coremqtt/source/core_mqtt_prop_deserializer.c"
+    - "@coremqtt/source/core_mqtt_prop_serializer.c"
+    - "@coremqtt/source/core_mqtt_serializer.c"
+    - "@coremqtt/source/core_mqtt_serializer_private.c"
+    - "@coremqtt/source/core_mqtt_state.c"
+
+repository.coremqtt:
+    type: github
+    vers: v5.0.2-commit
+    branch: main
+    user: FreeRTOS
+    repo: coreMQTT
diff --git a/net/mqtt/coremqtt/src/coremqtt.c b/net/mqtt/coremqtt/src/coremqtt.c
new file mode 100644
index 000000000..cf17b57b3
--- /dev/null
+++ b/net/mqtt/coremqtt/src/coremqtt.c
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include "os/mynewt.h"
+#include "modlog/modlog.h"
+#include "coremqtt/coremqtt.h"
+
+uint32_t
+coremqtt_time_ms(void)
+{
+    return (uint32_t)(os_get_uptime_usec() / 1000);
+}
+
+void
+coremqtt_log(uint8_t level, const char *fmt, ...)
+{
+    char buf[MYNEWT_VAL(COREMQTT_LOG_BUF_SIZE)];
+    va_list args;
+    int len;
+
+    va_start(args, fmt);
+    /* Leave room for the newline */
+    len = vsnprintf(buf, sizeof(buf) - 1, fmt, args);
+    va_end(args);
+
+    if (len < 0) {
+        return;
+    }
+    if (len > (int)sizeof(buf) - 2) {
+        len = sizeof(buf) - 2;
+    }
+    /* Some coreMQTT messages already end with a newline */
+    if (len == 0 || buf[len - 1] != '\n') {
+        buf[len++] = '\n';
+    }
+
+    modlog_append(MYNEWT_VAL(COREMQTT_LOG_MOD), level, LOG_ETYPE_STRING, buf, 
len);
+}
diff --git a/net/mqtt/coremqtt/syscfg.yml b/net/mqtt/coremqtt/syscfg.yml
new file mode 100644
index 000000000..eec4b71d0
--- /dev/null
+++ b/net/mqtt/coremqtt/syscfg.yml
@@ -0,0 +1,70 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+    COREMQTT_SUB_UNSUB_MAX_VECTORS:
+        description: >
+            Maximum number of topic filters in a single SUBSCRIBE or
+            UNSUBSCRIBE packet sent with a single transport writev call.
+        value: 4
+    COREMQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT:
+        description: >
+            Number of receive attempts for CONNACK when MQTT_Connect() is
+            called with a timeout of 0.
+        value: 5
+    COREMQTT_PINGRESP_TIMEOUT_MS:
+        description: >
+            Time (in milliseconds) to wait for PINGRESP after sending
+            PINGREQ.
+        value: 5000
+    COREMQTT_PACKET_TX_TIMEOUT_MS:
+        description: >
+            Maximum time (in milliseconds) without any packet sent before
+            MQTT_ProcessLoop() sends PINGREQ. The keep alive interval used
+            is the smaller of this and the one negotiated with the broker.
+        value: 30000
+    COREMQTT_PACKET_RX_TIMEOUT_MS:
+        description: >
+            Maximum time (in milliseconds) without any packet received
+            before MQTT_ProcessLoop() sends PINGREQ.
+        value: 30000
+    COREMQTT_RECV_POLLING_TIMEOUT_MS:
+        description: >
+            Maximum time (in milliseconds) to keep calling transport receive
+            without getting any data once reception of a packet has started.
+        value: 10
+    COREMQTT_SEND_TIMEOUT_MS:
+        description: >
+            Maximum time (in milliseconds) allowed for sending a single
+            MQTT packet over the transport.
+        value: 20000
+
+    COREMQTT_LOG_MOD:
+        description: 'Numeric module ID to use for coreMQTT log messages.'
+        value: 160
+    COREMQTT_LOG_LVL:
+        description: >
+            Minimum level for the coreMQTT log. coreMQTT logs every packet
+            and state change at info level.
+        value: 2
+    COREMQTT_LOG_BUF_SIZE:
+        description: >
+            Size of the stack buffer used for formatting a single coreMQTT
+            log message. Longer messages are truncated.
+        value: 128

Reply via email to