Skip to main content

Memfault MCUmgr Command Group

Introduction

The Memfault MCUmgr Command Group provides a standardized way for devices using MCUmgr to query device information and project credentials needed for Memfault OTA (FOTA) over Bluetooth. This custom command group enables mobile applications or gateway devices to retrieve the necessary metadata to check for and download firmware updates from the Memfault cloud.

This approach provides an alternative to using the Memfault Diagnostic Service (MDS) or overloading Bluetooth Device Information Service (DIS) fields for FOTA implementations.

Overview

The Memfault MCUmgr Command Group allows gateway applications to:

  1. Query device metadata (serial number, hardware version, software type, current firmware version)
  2. Retrieve the Memfault Project Key for authentication
  3. Use this information to query the Memfault cloud for available OTA updates

Device Metadata Fields

The following fields are required for Memfault OTA operations:

FieldExampleDescription
Device Serial404CCA453500Unique identifier for each device in your Memfault project. Used to target specific devices for OTA releases.
Hardware Versionv1, dvt, evtDifferentiates board revisions. Allows different FOTA payloads for different hardware versions.
Software Typeapp, sensor-hubDistinguishes between multiple chip firmwares in multi-chip systems.
Current Version1.2.3Current firmware version. Used to determine if the device is eligible for an update.
Project Key32-character alphanumeric stringMemfault routing token for API authentication.

MCUmgr Command Group Details

Group ID

The Memfault MCUmgr Command Group uses Group ID 128.

Commands

Command 0: Read Device Info

Retrieves device metadata needed for OTA queries.

Request:

{}

Response:

{
"device_serial": "<string>",
"hardware_version": "<string>",
"software_type": "<string>",
"current_version": "<string>"
}

All values are read from the memfault_platform_get_device_info() API, which is the same function used by MDS and Memfault's serialization code.

Command 1: Read Project Key

Retrieves the Memfault Project Key for API authentication.

Request:

{}

Response:

{
"project_key": "<string>"
}

Implementation Guide

Enable the Memfault MCUmgr Command Group in your firmware by following these steps:

  1. Ensure MCUmgr is integrated into your firmware. Refer to the MCUmgr Documentation for setup instructions.

  2. Enable the Memfault MCUmgr Command Group with this Kconfig option:

    CONFIG_MEMFAULT_MCUMGR_GRP=y
  3. Include a Memfault Project Key by setting the appropriate Kconfig option:

    # for Nordic nRF Connect SDK Project:
    CONFIG_MEMFAULT_NCS_PROJECT_KEY="<your_project_key>"
    # for other platforms using Memfault SDK:
    CONFIG_MEMFAULT_PROJECT_KEY="<your_project_key>"

Gateway Implementation

The nRF Connect Device Manager provides both libraries and a demonstration mobile app that can be used to execute Memfault FOTA using the MCUmgr Command Group.

Python Test Client

A simple Python script using the smpmgr CLI tool can be used to test the Memfault MCUmgr Command Group. In this example uvx is used to execute the smpmgr CLI tool:

❯ uvx smpmgr --ble <BLE address> --plugin-path=<path to Memfault SDK>/scripts memfault device-info

Authorization

By default the Memfault MCUmgr commands will be accessible to any connected client. To restrict access, use the authorization callback like so:

  #include "memfault/ports/zephyr/memfault_mcumgr.h"
static bool prv_memfault_mgmt_is_access_allowed(void *user_arg) {
(void)user_arg;

// Implement your authorization logic here!
return true; // false to deny access
}

...

// In your initialization code, install the callback
memfault_mcumgr_set_access_callback(NULL, // optional user_arg
&s_memfault_mcumgr_access_allowed);