• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created about 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Client implementation of the MQTT 3.1.1 specification for embedded devices

coreMQTT Client Library

This repository contains the coreMQTT library that has been optimized for a low memory footprint. The coreMQTT library is compliant with the MQTT 3.1.1 standard. It has no dependencies on any additional libraries other than the standard C library, a customer-implemented network transport interface, and optionally a user-implemented platform time function. This library is distributed under the MIT Open Source License.

This library has gone through code quality checks including verification that no function has a GNU Complexity score over 8, and checks against deviations from mandatory rules in the MISRA coding standard. Deviations from the MISRA C:2012 guidelines are documented under MISRA Deviations. This library has also undergone both static code analysis from Coverity static analysis, and validation of memory safety through the CBMC automated reasoning tool.

See memory requirements for this library here.

coreMQTT v2.1.0 source code is part of the FreeRTOS 202210.00 LTS release.

MQTT Config File

The MQTT client library exposes build configuration macros that are required for building the library. A list of all the configurations and their default values are defined in core_mqtt_config_defaults.h. To provide custom values for the configuration macros, a custom config file named core_mqtt_config.h can be provided by the application to the library.

By default, a core_mqtt_config.h custom config is required to build the library. To disable this requirement and build the library with default configuration values, provide MQTT_DO_NOT_USE_CUSTOM_CONFIG as a compile time preprocessor macro.

Thus, the MQTT library can be built by either:

  • Defining a core_mqtt_config.h file in the application, and adding it to the include directories list of the library
    OR
  • Defining the MQTT_DO_NOT_USE_CUSTOM_CONFIG preprocessor macro for the library build.

Sending metrics to AWS IoT

When establishing a connection with AWS IoT, users can optionally report the Operating System, Hardware Platform and MQTT client version information of their device to AWS. This information can help AWS IoT provide faster issue resolution and technical support. If users want to report this information, they can send a specially formatted string (see below) in the username field of the MQTT CONNECT packet.

Format

The format of the username string with metrics is:

<Actual_Username>?SDK=<OS_Name>&Version=<OS_Version>&Platform=<Hardware_Platform>&MQTTLib=<MQTT_Library_name>@<MQTT_Library_version>

Where

  • <Actual_Username> is the actual username used for authentication, if username and password are used for authentication. When username and password based authentication is not used, this is an empty value.
  • <OS_Name> is the Operating System the application is running on (e.g. FreeRTOS)
  • <OS_Version> is the version number of the Operating System (e.g. V10.4.3)
  • <Hardware_Platform> is the Hardware Platform the application is running on (e.g. WinSim)
  • <MQTT_Library_name> is the MQTT Client library being used (e.g. coreMQTT)
  • <MQTT_Library_version> is the version of the MQTT Client library being used (e.g. 1.0.2)

Example

  • Actual_Username = โ€œiotuserโ€, OS_Name = FreeRTOS, OS_Version = V10.4.3, Hardware_Platform_Name = WinSim, MQTT_Library_Name = coremqtt, MQTT_Library_version = 2.1.0. If username is not used, then โ€œiotuserโ€ can be removed.
/* Username string:
 * iotuser?SDK=FreeRTOS&Version=v10.4.3&Platform=WinSim&[email protected]
 */

#define OS_NAME                   "FreeRTOS"
#define OS_VERSION                "V10.4.3"
#define HARDWARE_PLATFORM_NAME    "WinSim"
#define MQTT_LIB                  "[email protected]"

#define USERNAME_STRING           "iotuser?SDK=" OS_NAME "&Version=" OS_VERSION "&Platform=" HARDWARE_PLATFORM_NAME "&MQTTLib=" MQTT_LIB
#define USERNAME_STRING_LENGTH    ( ( uint16_t ) ( sizeof( USERNAME_STRING ) - 1 ) )

MQTTConnectInfo_t connectInfo;
connectInfo.pUserName = USERNAME_STRING;
connectInfo.userNameLength = USERNAME_STRING_LENGTH;
mqttStatus = MQTT_Connect( pMqttContext, &connectInfo, NULL, CONNACK_RECV_TIMEOUT_MS, pSessionPresent );

Upgrading to v2.0.0 and above

With coreMQTT versions >=v2.0.0, there are breaking changes. Please refer to the coreMQTT version >=v2.0.0 Migration Guide.

Building the Library

The mqttFilePaths.cmake file contains the information of all source files and the header include path required to build the MQTT library.

Additionally, the MQTT library requires two header files that are not part of the ISO C90 standard library, stdbool.h and stdint.h. For compilers that do not provide these header files, the source/include directory contains the files stdbool.readme and stdint.readme, which can be renamed to stdbool.h and stdint.h, respectively, to provide the type definitions required by MQTT.

As mentioned in the previous section, either a custom config file (i.e. core_mqtt_config.h) OR MQTT_DO_NOT_USE_CUSTOM_CONFIG macro needs to be provided to build the MQTT library.

For a CMake example of building the MQTT library with the mqttFilePaths.cmake file, refer to the coverity_analysis library target in test/CMakeLists.txt file.

Building Unit Tests

Checkout CMock Submodule

By default, the submodules in this repository are configured with update=none in .gitmodules to avoid increasing clone time and disk space usage of other repositories (like amazon-freertos that submodules this repository).

To build unit tests, the submodule dependency of CMock is required. Use the following command to clone the submodule:

git submodule update --checkout --init --recursive test/unit-test/CMock

Platform Prerequisites

  • Docker

or the following:

  • For running unit tests
    • C90 compiler like gcc
    • CMake 3.13.0 or later
    • Ruby 2.0.0 or later is additionally required for the CMock test framework (that we use).
  • For running the coverage target, gcov and lcov are additionally required.

Steps to build Unit Tests

  1. If using docker, launch the container:

    1. docker build -t coremqtt .
    2. docker run -it -v "$PWD":/workspaces/coreMQTT -w /workspaces/coreMQTT coremqtt
  2. Go to the root directory of this repository. (Make sure that the CMock submodule is cloned as described above)

  3. Run the cmake command: cmake -S test -B build

  4. Run this command to build the library and unit tests: make -C build all

  5. The generated test executables will be present in build/bin/tests folder.

  6. Run cd build && ctest to execute all tests and view the test run summary.

CBMC

To learn more about CBMC and proofs specifically, review the training material here.

The test/cbmc/proofs directory contains CBMC proofs.

In order to run these proofs you will need to install CBMC and other tools by following the instructions here.

Reference examples

Please refer to the demos of the MQTT client library in the following locations for reference examples on POSIX and FreeRTOS platforms:

Platform Location Transport Interface Implementation
POSIX AWS IoT Device SDK for Embedded C POSIX sockets for TCP/IP and OpenSSL for TLS stack
FreeRTOS FreeRTOS/FreeRTOS FreeRTOS+TCP for TCP/IP and mbedTLS for TLS stack
FreeRTOS FreeRTOS AWS Reference Integrations Based on Secure Sockets Abstraction

Documentation

Existing Documentation

For pre-generated documentation, please see the documentation linked in the locations below:

Location
AWS IoT Device SDK for Embedded C
FreeRTOS.org

Note that the latest included version of coreMQTT may differ across repositories.

Generating Documentation

The Doxygen references were created using Doxygen version 1.9.2. To generate the Doxygen pages, please run the following command from the root of this repository:

doxygen docs/doxygen/config.doxyfile

Contributing

See CONTRIBUTING.md for information on contributing.

More Repositories

1

FreeRTOS

'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.
C
5,093
star
2

FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
C
2,629
star
3

FreeRTOS-LTS

227
star
4

FreeRTOS-Kernel-Book

208
star
5

FreeRTOS-Plus-TCP

FreeRTOS-Plus-TCP library repository. +TCP files only. Submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
C
132
star
6

coreJSON

A parser strictly enforcing the ECMA-404 JSON standard, suitable for microcontrollers
C
104
star
7

Lab-Project-FreeRTOS-POSIX

This repository contains FreeRTOS+POSIX source code, which could be consumed as a submodule.
C
95
star
8

FreeRTOS-Cellular-Interface

FreeRTOS Cellular Interface implementation of the 3GPP TS v27.007 standard.
C
82
star
9

Lab-Project-FreeRTOS-FAT

This repository contains FreeRTOS+FAT source code, which could be consumed as a submodule.
C
78
star
10

coreHTTP

Client implementation of a subset of HTTP 1.1 protocol designed for embedded devices.
C
78
star
11

iot-reference-esp32

C
76
star
12

FreeRTOS-Labs

C
59
star
13

FreeRTOS-SMP-Demos

C
53
star
14

Lab-Project-FreeRTOS-LoRaWAN

Reference implementation of LoRaWAN connectivity on FreeRTOS.
C
50
star
15

iot-reference-stm32u5

C
43
star
16

corePKCS11

Software implementation of the PKCS #11 standard.
C
37
star
17

coreMQTT-Agent-Demos

Demonstrates use of coreMQTT-Agent for simple MQTT connection sharing among different threads of execution.
C
31
star
18

coreMQTT-Agent

Implements an MQTT agent (or daemon) task for simple MQTT connection sharing among different threads of execution.
C
29
star
19

backoffAlgorithm

Algorithm for calculating exponential backoff with jitter for network retry attempts.
C
27
star
20

Lab-Project-FreeRTOS-Cellular-Demo

C
26
star
21

Lab-Project-FreeRTOS-MCUBoot

C
25
star
22

FreeRTOS-Community-Supported-Demos

C
22
star
23

coreSNTP

SNTPv4 client designed for embedded devices.
C
20
star
24

Lab-Project-Espressif-Demos

C
19
star
25

iot-reference-arm-corstone3xx

Featured FreeRTOS IoT Integration targeting an Arm Corstone-3xx platform based on Arm Cortex-M MCU.
C
17
star
26

FreeRTOS-Kernel-Community-Supported-Ports

C
17
star
27

iot-reference-nxp-rt1060

Reference IoT project which integrates NXP IMXRT 1060 platform with FreeRTOS LTS libraries
C
17
star
28

CI-CD-Github-Actions

Common GitHub Actions for CI/CD on FreeRTOS library repositories.
C
16
star
29

FreeRTOS-Partner-Supported-Demos

C
9
star
30

FreeRTOS-Cellular-Interface-Reference-Quectel-BG96

C
9
star
31

CMSIS-Packs

This repository contains a Package Index File that describes the locations of CMSIS Packs for various FreeRTOS libraries.
8
star
32

FreeRTOS-Kernel-Partner-Supported-Ports

C
8
star
33

freertos-gdb

Python
8
star
34

FreeRTOS-Cellular-Interface-Community-Supported-Ports

C
7
star
35

Lab-Project-ota-example-for-AWS-IoT-Core

An example of an AWS IoT Core OTA orchestrator, running on the FreeRTOS POSIX port
C
5
star
36

FreeRTOS-Libraries-Integration-Tests

C
5
star
37

FreeRTOS-SESIP

C
4
star
38

FreeRTOS-Cellular-Interface-Reference-Sierra-Wireless-HL7802

C
2
star
39

FreeRTOS-Cellular-Interface-Reference-ublox-SARA-R4

C
2
star
40

Lab-Project-CMSIS-Packs-Demos

C
1
star