Forwarding Chunks via Golioth
Golioth is an IoT platform that provides cloud services for embedded devices. If your project is using Golioth, you can leverage their CoAP client to forward Memfault chunk data to Memfault.
Step 1: Set up the memfault
destination
See https://docs.golioth.io/data-routing/destinations/memfault/ for instructions on setting up Memfault as a destination.
(Recommended) Use primary_hardware_id
as alternate_id
By default, Golioth will attach the Golioth Device ID to Memfault chunk data as
the reported Memfault Device Serial. Optionally, an alternate_id
can be
specified to attach a different identifier.
It is recommended to set the alternate_id
to the primary_hardware_id
, since
this typically maps to the device identifier users want to search by in
Memfault. This can be configured in Golioth in the memfault
destination
config:
destination:
type: memfault
version: v1
parameters:
project_key: $MEMFAULT_PROJECT_KEY
alternate_id: primary_hardware_id
If there are more device identifiers you want to attach to Memfault data beyond
a device id, you can set a metric using the
metrics API (on-device) or via the
REST API /attributes
endpoint.
Then, configure it as an Attribute in
the Memfault platform to be able to filter devices by it.
Step 2: Configure Memfault Data Upload
In a periodic task, drain chunks and upload to Golioth via Streaming mode with a Golioth blockwise stream. See the Memfault + Golioth example app for a sample implementation.
Step 3: Configure Device Info
Golioth will attach the chosen device id to Memfault data when uploading to the Memfault cloud. Therefore, the on-device Memfault serial can be empty, but the remaining device info should be customized.
- Option 1: NCS Built-in Device Info
- Option 2: Custom Device Info
By default, NCS provides a built-in memfault_platform_get_device_info()
function with helpful defaults. See
Kconfig options in NCS
for configuring these!
If you need to provide a custom implementation of
memfault_platform_get_device_info()
, for example if your software version is
not available at compile-time, first set the following in your proj.conf
:
CONFIG_MEMFAULT_DEVICE_INFO_CUSTOM=y
CONFIG_MEMFAULT_NCS_DEVICE_ID_RUNTIME=y
Then, implement the memfault_platform_get_device_info()
function as follows,
customizing appropriately:
The Device Serial will typically be
reported by Golioth,
therefore the value set here will not be used. However, it must still be
populated but it can set be to a dummy value (e.g. "NULL"
).
#include "memfault/core/platform/device_info.h"
void memfault_platform_get_device_info(sMemfaultDeviceInfo *info) {
// !FIXME: Populate with platform device information
//
// *NOTE* All fields must be populated, and the values assigned to the fields
// must have static lifetime: the data is accessed when this function returns.
// In this example, the fields are string literals, which are placed either
// inline into .text data tables, or in .rodata, and the pointers are valid
// for the lifetime of the program
//
// See https://mflt.io/version-nomenclature for more context
*info = (sMemfaultDeviceInfo) {
// Set the device serial to a unique value.
// It is typically set to a unique identifier like a serial number
// or MAC address.
// This is used to de-deduplicate data in Memfault cloud
.device_serial = "DEMOSERIAL",
// Set the device software type.
// It can be simply "app" for a single-chip device, otherwise it
// should match the component name, eg "ble", "sensor" etc.
// This is used to filter devices in the Memfault UI
.software_type = "app-main",
// Set the device software version.
// If using Memfault OTA, this should exactly match the OTA Release
// Version name for the installed image
.software_version = "1.0.0-dev",
// Set the device hardware revision.
// This is used to filter/group devices in the Memfault UI
.hardware_version = "evt",
};
}
Step 4: Remove the Memfault Project Key
If you are not connecting directly with Memfault's servers for data upload or OTA, you can set it to a dummy value:
- NCS
- ESP-IDF
# Disable the HTTP client (needed only for nRF91 projects)
CONFIG_MEMFAULT_HTTP_ENABLE=n
# Set to a dummy value
CONFIG_MEMFAULT_NCS_PROJECT_KEY="NULL"
CONFIG_MEMFAULT_NCS_PROJECT_KEY
is optional in nRF Connect SDK >=v3.0.0 for
any device that does not use MDS or the Memfault HTTP client to upload chunks,
which applies for all NCS-based projects leveraging Golioth for chunks
forwarding.
# Disable periodic data upload (enabled by default)
CONFIG_MEMFAULT_HTTP_PERIODIC_UPLOAD=n
# Set to a dummy value
CONFIG_MEMFAULT_PROJECT_KEY="NULL"