# Memfault

This section covers how to connect the versatile Conexio Stratus device to the Memfault platform. Specifically, this post will demonstrate how to:

* Setup the toolchains and the Memfault API using the RF Connect SDK.
* Connect the Stratus kit to the Memfault cloud.
* Trigger fault cases and send crash data to the Memfault’s backend over the cellular network.

### Registration and Device Setup on the Memfault Cloud <a href="#registration-and-device-setup-on-the-memfault-cloud" id="registration-and-device-setup-on-the-memfault-cloud"></a>

Sign up for the Memfault cloud and create a user account [<mark style="color:red;">here</mark>](https://memfault.com/register/).

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FP3aOR4XOKrKcJuLX4ypa%2Ffig_1.png?alt=media\&token=657402fd-6532-4cf8-9d8a-05a9178fd942)

Once your account is created, create a new project in Memfault by navigating to the project selector in the left-hand sidebar. You can find an option to **Create Project** below your list of existing projects. More information regarding how to use the Memfault platform can be found [<mark style="color:red;">here</mark>](https://docs.memfault.com/docs/platform/projects-and-fleets).

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FGZNfj1eolgxbJNLkRIWi%2Ffig_2.png?alt=media\&token=39edef91-3ea7-473a-a673-06c9714c4c53)

Click **Create Project** and give your project a preferred **Name**, followed by the MCU type. In our case, it will be the **Embedded MCU** with **nRF91** as the Primary chip type. Then click **Next** to choose the OS options.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2F9fP4YfN8sJJnUsTo5rXL%2Ffig_3.png?alt=media\&token=d46e6836-4903-423b-b5ea-3e676caaeb28)

Under OS, we will select **Zephyr** as the main OS for our device. Hit Next and select the connectivity type.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FXg6cuDFVBHd6iYcwXQqd%2Ffig_4.png?alt=media\&token=cc7da129-8e69-4430-9ecd-c96f4229fc97)

For connectivity, Conexio Stratus is a **Cellular/LTE** device.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FG54jJt4JJGS1yA30vBEk%2Ffig_5.png?alt=media\&token=aa26df64-66a6-4f9a-b521-491a71a79252)

For the **Tooling**, we will select **GCC** as the main compiler and **CMake** as the toolchain used by the ZephyrOS. Finally, complete the project creation by hitting **Create**.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2F55lPr5HzmDlIP2UIugeY%2Ffig_6.png?alt=media\&token=1ec94768-0b6d-4da2-a5fc-1cd679790f7b)

Once the project is created, head down to the **Settings** tab and click **General**. Here, you should see your Memfault Project Key on the right-hand box.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FOzI8PLgZJf7CJ3S68qJV%2Ffig_7.png?alt=media\&token=e1e51e69-6d57-4e8e-9131-2801cb6c3151)

Copy this key as later we will need this to authenticate our Stratus device with the Memfault platform.

At this point, we have all the required details to connect and publish data from our Conexio Stratus device to the Memfault backend. Let’s head over to the device firmware setup and configuration side.

## Stratus Sample Application <a href="#stratus-sample-application" id="stratus-sample-application"></a>

We have extended the memfault sample application provided in the nRF Connect SDK to connect the Stratus kit to the Memafult and stream device diagnostics data. The complete source code for this tutorial can be found in this [<mark style="color:red;">GitHub repo</mark>](https://github.com/Conexiotechnologies/conexio-stratus-firmware/tree/main/samples/memfault). This sample application allows capturing:

* LTE metrics, specifically, the time to connect to the LTE network.
* Core dumps by triggering crash via button press or through shell commands.
* Offloading all the captured data to the Memfault backend.

### **Add Memfault credentials to the Application Code**

First, we will have to add the Memfault Project Key that we copied above into the application code. To do so, edit the `conexio_stratus_firmware/samples/memfault/prj.conf` with your project key and update the following parameters.

```
CONFIG_MEMFAULT_NCS_PROJECT_KEY="YOUR-MEMFAULT-PROJECT-KEY"
```

To correctly fetch the device hardware version and type together with the IMEI, the following configurations need to be added for the Stratus device:

```
# Add Conexio Stratus hardware configurations
CONFIG_MEMFAULT_NCS_HW_VERSION="stratus"
CONFIG_MEMFAULT_NCS_FW_TYPE="nrf91ns-fw"
CONFIG_MEMFAULT_NCS_DEVICE_ID_IMEI=y
```

In addition, we will also enable the periodic upload of the device diagnostics and heartbeat data over HTTP protocol by enabling:

```
CONFIG_MEMFAULT_HTTP_PERIODIC_UPLOAD=y
```

This allows sending the data that has been captured by the device to the memfault cloud periodically with an interval defined by:

```
CONFIG_MEMFAULT_HTTP_PERIODIC_UPLOAD_INTERVAL_SECS
```

You can browse other configurations in the `prj.conf` file. Now we are all set to compile and upload our firmware to the device.

### **Compiling the Sample Application using `West`**

To compile the application using west, open a terminal window in the application directory and issue the following command:

```
west build -b conexio_stratus_ns
```

In case you do not want to recall the west commands simply command the following in the terminal, and the included python script in the project directory will take care of the rest.

### **Flashing the Sample Application**

Once the application is compiled successfully, connect the Stratus device to the USB port and put it into the DFU mode.

Then flash the compiled firmware using **newtmgr**:

```
newtmgr -c serial image upload build/zephyr/app_update.bin
```

Open up a serial console with a baud rate of 115200, hit the reset button on the Stratus device, and the following serial UART output will be displayed in the terminal.

```
uart:~$ *** Booting Zephyr OS build v2.6.99-ncs1  ***
<inf> <mflt>: Reset Reason, RESETREAS=0x1
inf> <mflt>: Reset Causes:
<inf> <mflt>:  Pin Reset
<inf> <mflt>: GNU Build ID: 098b8b74929371d5ad655dfe0d8df6cf8e59cd91
Conexio Stratus Memfault sample has started
<inf> memfault_sample: Connecting to LTE network, this may take several minutes...
<inf> memfault_sample: Active LTE mode changed: LTE-M
<inf> memfault_sample: Network registration status: Connected - roaming
<inf> memfault_sample: Connected to LTE network. Time to connect: 2301 ms
```

Once the device is booted up and connected to the available LTE network, it will then display the time-to-connect metric (`Ncs_LteTimeToConnect`) on the terminal. Subsequently, all the captured Memfault data including the reset reason will be sent to the Memfault cloud.

```
<inf> memfault_sample: Sending already captured data to Memfault
uart:~$ <dbg> <mflt>: Response Complete: Parse Status 0 HTTP Status 202!
<dbg> <mflt>: Body: Accepted
<dbg> <mflt>: Response Complete: Parse Status 0 HTTP Status 202!
<dbg> <mflt>: Body: Accepted
<dbg> <mflt>: No more data to send
```

### **Uploading Symbol Files**

In order to properly decode and parse the uploaded device data such as core dumps, Memfault needs to be able to find the Symbol File (ELF) that corresponds to the software that produced the uploaded data. Without an exact match, Memfault will not be able to decode the uploaded data.

To upload the symbol file generated from your project build to your Memfault account, go to the Memfault console and select the project that you created earlier and navigate to the **Software > Symbol Files** in the left menu. Then click **Upload Symbol File** in the top right-hand corner.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2Fe9bfDzKfbkbgbA9CvPA7%2Ffig_8.png?alt=media\&token=efe3302a-46e8-4e96-bb39-30b12726001b)

Select the Software Type and Version for your device and then click Select File. Browse and navigate to your project directory and select `zephyr.elf` file: `conexio_stratus_firmware/samples/memfault/build/zephyr/zephyr.elf`

Finally, click **Add** to upload the Symbol file.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FDYdrfqFsHRR4MqB7ONtO%2Ffig_9.png?alt=media\&token=77f62b97-0e13-417d-b133-0df48861f5cd)

### Exploring the Memfault Console <a href="#exploring-the-memfault-console" id="exploring-the-memfault-console"></a>

After uploading the symbol file, we can now see the parsed data on the Memfault console. Let’s explore the console and how we can see various metrics and the overall fleet information.

First, let’s see the connectivity status of our device. To view, click on the **Fleet > Devices** on the left-hand pane. Under **Cohort** (i.e., the grouping of devices), select default, and for the **Device Serial** select the IMEI number of the Stratus device. Next, it should display the device information of the connected devices. Here, we can see the firmware version running on the device (`0.0.1+098b8b`), the hardware version (`stratus`), and the last time device communicated to the Memfault cloud. If you see your device here, it confirms that it is able to successfully connect and offload the device data to the cloud backend.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FOpedDGw5V0SNNWY3gK7A%2Ffig_10.png?alt=media\&token=83da3318-f5db-4190-a449-ec7dfca91e10)

Next, in the Dashboard tab, clicking **Overview** should display the overall fleet status such as the number of active devices, software versions running on those devices, fault traces, issues, and the reboot reasons.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FABpJ6Um5F5FCnUk87unc%2Ffig_11.png?alt=media\&token=651c0208-4d61-4abe-b161-37e1f7c03ece)

Device reboots can provide one of the vital insights to the IoT administrators as to what might be the root cause of issues on your device if it’s constantly failing or rebooting too often. This is usually a good starting point for troubleshooting. Device reboots can be caused due to mechanical or physical issues on the device such as power supply, faulty components, batteries, or software lockups, i,e., watchdog timers failing to kick, issues with drivers, etc.

Memafult is able to capture these issues and much more in detail.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FVNMf2EgoYLVdhc28r3N9%2Ffig_12.png?alt=media\&token=c249f5f7-9505-4b9f-a38f-788c14638422)

Let’s head over to the **Metrics** pane to view some of the metrics that we have captured using our sample application running on the Stratus device, i.e., LTE connectivity time and the stack usage metrics. Connectivity status provides good insights as to how long the devices across the fleet are taking to connect to the available LTE network. Longer connectivity times are a good indication for the poor cellular networks and whether devices in that particular region should utilize external or internal antennas for improving the connection - useful information for hardware design engineers.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FGndLcAY2G4c6v3RBLBEI%2Ffig_13.png?alt=media\&token=4181714a-11d1-4319-9916-b0d4a3f1df24)

Explore around the console to view other detailed analyses of faults reported by the device under the **Issues** tab.

### **Manual Coredump Collection**

The sample application enables the Memfault shell by default which provides a serial terminal interface that can be used to issue commands to the device such as `mflt crash` to generate a coredump and `mflt post_chunks` to upload the coredump.

```
CONFIG_MEMFAULT_SHELL=y
```

These coredumps can also be triggered by pressing **button 1** (Mode button) on the Stratus device which triggers a stack overflow.

The shell offers multiple commands to test a wide range of functionality offered by the Memfault SDK. Run the command `mflt help` in the terminal for more information on the available commands. The list of available Memfault test commands is shown below.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2F1Iaqy3gMJgI09RCNfCbN%2Ffig_14.png?alt=media\&token=ca9bd8d4-a82c-43da-9dbe-8b12af7922b3)

For instance, running `mflt get_device_info` displays all the relevant information of the connected device.

{% hint style="success" %}
This is the same information that we have seen captured by the Memfault cloud previously in their console under the devices tab.
{% endhint %}

```
uart:~$ mflt get_device_info
mflt get_device_info
<inf> <mflt>: S/N: 352656103852334
<inf> <mflt>: SW type: nrf91ns-fw
<inf> <mflt>: SW version: 0.0.1+098b8b
<inf> <mflt>: HW version: stratus
```

Now to trigger a device crash and submit the trace to the Memfault backend, we will submit `mflt crash` command. The crash causes the usage fault as shown below after which the device will reset and send the crash data to the Memfault cloud for further inspection and analysis.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FcoHJqDeqYIXB8joSfaE1%2Ffig_15.png?alt=media\&token=5647bb44-cec0-4735-a0e4-096ac8385db5)

To view the device crash detail, head over to the **Issues** tab in the console and you should see the list of issues captured from this device. Here, the manual crash is registered as **Assert at memfault\_demo\_cli\_cmd\_crash**. Click on this issue to inspect it in detail.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FJ2aeQ3wgKGYclp1hcEiz%2Ffig_16.png?alt=media\&token=862e9eae-a1a7-4cfd-ac27-9cca04d7dc16)

The detailed analysis allows us to get an in-depth view of the fault down to the register level. This is pretty interesting and helpful at the same time providing a readable and comprehensive view than what we would see with the gdb server.

![](https://3229153654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXjGw-Z8_tCuNQB93OW%2Fuploads%2FrVPY8ylNAR7SpytljKJD%2Ffig_17.png?alt=media\&token=e153d53d-36c5-4886-863f-91ea80b220fc)

And that wraps up this tutorial.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.conexiotech.com/master/sample-applications/memfault.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
