nRF5 SDK for Mesh v5.0.0
Adding custom examples

You can create your own examples and add them to the compilation for both SEGGER Embedded Studio and CMake. Do this only when you are familiar with the toolchain and how to build the stack and the examples.

The process of adding new examples is composed of the following stages:

Note
The custom example to be added is referred to as my_app on this page. Replace this name with the name of your application each time it is mentioned.

Creating custom example folder and CMakeLists file

To add folders and the CMakeLists.txt file for your custom example:

  1. In the examples folder of your nRF5 SDK for Mesh installation path, add a new my_app folder.
  2. Copy the contents of one of the existing example folders to this new folder. For example, copy the contents of examples/beaconing.
  3. In the examples/CMakeLists.txt file, depending on your platform (see Compatibility):
    • If your example supports the nRF52810 or nRF52820 SoC, add the new folder as a new add_subdirectory command entry. For example:
          set(WEAK_SOURCE_FILES
              "${CMAKE_CURRENT_SOURCE_DIR}/common/src/nrf_mesh_weak.c"
              "${CMAKE_CURRENT_SOURCE_DIR}/common/src/app_error_weak.c"
              "${CMAKE_CURRENT_SOURCE_DIR}/common/src/assertion_handler_weak.c"
              CACHE INTERNAL "")
          add_subdirectory("common")
          add_subdirectory("beaconing")
          add_subdirectory("pb_remote")
          add_subdirectory("provisioner")
          add_subdirectory("my_app")
      
    • If your example does not support the nRF52810 or nRF52820 SoC, add the new folder as a new add_subdirectory command entry in the platform-related if section. For example:
          if ((NOT PLATFORM MATCHES "nrf52810") AND (NOT PLATFORM MATCHES "nrf52820"))
              add_subdirectory("my_app")
              add_subdirectory("sensor")
              add_subdirectory("scene")
              add_subdirectory("light_lightness")
              add_subdirectory("light_lc")
              add_subdirectory("light_ctl")
              add_subdirectory("enocean_switch")
              add_subdirectory("dimming")
              add_subdirectory("lpn")
              add_subdirectory("dfu")
              add_subdirectory("serial")
              add_subdirectory("light_switch")
          endif()
      
  4. Modify the target name in the first line of the examples/my_app/CMakeLists.txt file to set(target "my_app").

Defining application configuration

When you created custom example folder and CMakeLists.txt file, you also copied the following files used for configuring the application:

To define the example configuration:

  1. In the examples/my_app/CMakeLists.txt file, add or remove the application support modules based on your needs.
  2. Edit the include/app_config.h file to match your application configuration and override the configuration of the nRF5 SDK (see SDK configuration header file).
  3. Edit nrf_mesh_config_app.h file to modify:

After defining the configuration, build the example with the following procedure.


Building and running custom examples

The building procedure for custom examples is similar to the standard building procedure, with the following differences:

When running the example in CMake-based environment, flash your example with the following command:

build $ ninja flash_my_app 

Documentation feedback | Developer Zone | Subscribe | Updated