|
| 1 | +.. _ble_mds_sample: |
| 2 | + |
| 3 | +Bluetooth: Memfault Diagnostic Service (MDS) |
| 4 | +############################################ |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +The Memfault Diagnostic Service sample demonstrates how to expose diagnostic data collected by the `Memfault SDK`_ over Bluetooth LE using |BMlong|. |
| 11 | +The sample advertises the Memfault Diagnostic Service (MDS) and the Battery Service. |
| 12 | +A Bluetooth gateway can connect to the device, read the Memfault upload information, and stream diagnostic chunks to the Memfault cloud. |
| 13 | + |
| 14 | +Requirements |
| 15 | +************ |
| 16 | + |
| 17 | +The sample supports the following development kits: |
| 18 | + |
| 19 | +.. tabs:: |
| 20 | + |
| 21 | + .. group-tab:: Simple board variants |
| 22 | + |
| 23 | + The following board variants do **not** have DFU capabilities: |
| 24 | + |
| 25 | + .. include:: /includes/supported_boards_all_non-mcuboot_variants_s115.txt |
| 26 | + |
| 27 | + .. include:: /includes/supported_boards_all_non-mcuboot_variants_s145.txt |
| 28 | + |
| 29 | + .. group-tab:: MCUboot board variants |
| 30 | + |
| 31 | + The following board variants have DFU capabilities: |
| 32 | + |
| 33 | + .. include:: /includes/supported_boards_all_mcuboot_variants_s115.txt |
| 34 | + |
| 35 | + .. include:: /includes/supported_boards_all_mcuboot_variants_s145.txt |
| 36 | + |
| 37 | +Overview |
| 38 | +******** |
| 39 | + |
| 40 | +The sample uses the bare-metal SoftDevice Bluetooth libraries to initialize advertising, the Battery Service, the Device Information Service, and MDS. |
| 41 | +The Memfault SDK collects reboot information, logs, metrics, trace events, and coredumps. |
| 42 | +When an MDS gateway subscribes to the Data Export characteristic and enables streaming, the application calls :c:func:`ble_mds_process` from the main loop to send pending Memfault chunks. |
| 43 | + |
| 44 | +Metrics |
| 45 | +======= |
| 46 | + |
| 47 | +The sample defines the following application metrics in :file:`samples/bluetooth/ble_mds/memfault_config/memfault_metrics_heartbeat_config.def`: |
| 48 | + |
| 49 | +* ``button_press_count`` - The number of **Button 2** presses. |
| 50 | +* ``battery_soc_pct`` - The simulated battery level. |
| 51 | +* ``button_elapsed_time_ms`` - The time measured between two **Button 0** presses. |
| 52 | + |
| 53 | +Pressing **Button 0** the second time stops the timer and triggers a heartbeat collection. |
| 54 | + |
| 55 | +Trace events |
| 56 | +============ |
| 57 | + |
| 58 | +The sample defines the ``button_state_changed`` trace reason in :file:`samples/bluetooth/ble_mds/memfault_config/memfault_trace_reason_user_config.def`. |
| 59 | +The event is collected when **Button 1** changes state. |
| 60 | + |
| 61 | +Core dumps |
| 62 | +========== |
| 63 | + |
| 64 | +Press **Button 3** to trigger a hardfault exception by division by zero. |
| 65 | +After reboot, reconnect with an MDS gateway to transfer the collected coredump data to Memfault. |
| 66 | + |
| 67 | +User interface |
| 68 | +************** |
| 69 | + |
| 70 | +LED 0: |
| 71 | + Blinks while the sample is running. |
| 72 | + |
| 73 | +LED 1: |
| 74 | + Lit when a Bluetooth LE central is connected. |
| 75 | + |
| 76 | +Button 0: |
| 77 | + Starts or stops the ``button_elapsed_time_ms`` metric timer. |
| 78 | + The second press stops the timer and triggers a Memfault heartbeat. |
| 79 | + |
| 80 | +Button 1: |
| 81 | + Triggers the ``button_state_changed`` trace event on press and release. |
| 82 | + |
| 83 | +Button 2: |
| 84 | + Increments the ``button_press_count`` metric and triggers a Memfault heartbeat. |
| 85 | + |
| 86 | +Button 3: |
| 87 | + Simulates a crash by triggering a hardfault exception. |
| 88 | + |
| 89 | +Configuration |
| 90 | +************* |
| 91 | + |
| 92 | +The sample configuration is split between the :file:`prj.conf` file and sample-specific Kconfig options in :file:`Kconfig`. |
| 93 | + |
| 94 | +Set :kconfig:option:`CONFIG_MEMFAULT_NCS_PROJECT_KEY` to the project key for your Memfault project before using a real gateway. |
| 95 | +The sample uses :kconfig:option:`CONFIG_MEMFAULT_NCS_DEVICE_ID_HW_ID` with :kconfig:option:`CONFIG_HW_ID_LIBRARY_SOURCE_DEVICE_ID` so each device reports a hardware-derived Memfault device ID. |
| 96 | +It selects :kconfig:option:`CONFIG_MEMFAULT_REBOOT_REASON_GET_BASIC` for compatibility across the bare-metal board variants supported by this sample. |
| 97 | +You can configure the advertising name with the :kconfig:option:`CONFIG_SAMPLE_BLE_DEVICE_NAME` Kconfig option. |
| 98 | + |
| 99 | +The MDS library settings use the ``CONFIG_BLE_MDS`` prefix. |
| 100 | +For Memfault SDK options that are not configurable through Kconfig, use :file:`samples/bluetooth/ble_mds/memfault_config/memfault_platform_config.h`. |
| 101 | + |
| 102 | +Building and running |
| 103 | +******************** |
| 104 | + |
| 105 | +This sample can be found under :file:`samples/bluetooth/ble_mds/` in the |BMshort| folder structure. |
| 106 | + |
| 107 | +For details on how to create, configure, and program a sample, see :ref:`getting_started_with_the_samples`. |
| 108 | + |
| 109 | +Testing |
| 110 | +======= |
| 111 | + |
| 112 | +You can test this sample using `nRF Connect Device Manager`_ or another MDS-compatible Bluetooth gateway. |
| 113 | + |
| 114 | +1. Configure :kconfig:option:`CONFIG_MEMFAULT_NCS_PROJECT_KEY` for your Memfault project. |
| 115 | +#. Compile and program the application. |
| 116 | +#. Connect to the kit with a terminal emulator, for example the `Serial Terminal app`_. |
| 117 | +#. Reset the kit. |
| 118 | +#. In the terminal, observe that the ``BLE MDS sample initialized`` message is printed. |
| 119 | +#. Observe that the ``Advertising as nRF_BM_MDS`` message is printed. |
| 120 | + You can configure this name using the :kconfig:option:`CONFIG_SAMPLE_BLE_DEVICE_NAME` Kconfig option. |
| 121 | +#. Open `nRF Connect Device Manager`_ and scan for devices. |
| 122 | +#. Connect to the device and open the diagnostics view. |
| 123 | +#. Use the buttons to generate metrics, trace events, and a coredump. |
| 124 | +#. Upload the generated symbol file from the build directory to your Memfault project so that uploaded data can be decoded. |
| 125 | + |
| 126 | +Dependencies |
| 127 | +************ |
| 128 | + |
| 129 | +This sample uses the following |BMshort| libraries: |
| 130 | + |
| 131 | +* :c:func:`ble_adv_init` |
| 132 | +* :c:func:`ble_bas_init` |
| 133 | +* :c:func:`ble_dis_init` |
| 134 | +* :c:func:`ble_mds_init` |
| 135 | +* :c:func:`bm_buttons_init` |
| 136 | +* :c:func:`bm_timer_init` |
| 137 | + |
| 138 | +In addition, it uses the `Memfault SDK`_. |
0 commit comments