Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Implementing multiple server from light switch example on nRF52840 DK produces mesh error 19

I'm currently modifying the light switch server example so that LED 1 and LED 2 can be controlled by buttons on a client board. For example, Button 1 will turn on or off LED 1, and Button 2 will turn on or off LED 2. I'm following this example to add a server model for LED 2, and I have done the following:

  • Increased ACCESS_MODEL_COUNT and ACCESS_ELEMENT COUNT by 1 
    /**
     * The number of models in the application.
     *
     * @note To fit the configuration and health models, this value must equal at least
     * the number of models needed by the application plus two.
     */
    #define ACCESS_MODEL_COUNT (/* Element 0:                                       */ \
                                1 + /* Config Server                                */ \
                                1 + /* Health Server                                */ \
                                2 + /* Generic OnOff Server                         */ \
                                1 + /* Default Transition Time Server               */ \
                                1 + /* Scene Server                                 */ \
                                1   /* Scene Setup Server (extends Scene Server)    */) // added 1 generic on off server
    
    /**
     * The number of elements in the application.
     *
     * @warning If the application is to support _multiple instances_ of the _same_ model, these instances
     * cannot be in the same element and a separate element is needed for each new instance of the same model.
     */
    #define ACCESS_ELEMENT_COUNT (2)     // added +1
  • Added another app_onoff_server_get_cb and app_onoff_server_set_cb
    /* Callback for updating the hardware state of LED0*/
    static void app_onoff_server_set_cb_0(const app_onoff_server_t * p_server, bool onoff)
    {
        /* Resolve the server instance here if required, this example uses only 1 instance. */
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setting GPIO value: %d\n", onoff)
    
        hal_led_pin_set(ONOFF_SERVER_0_LED, onoff);
    }
    
    /* Callback for updating the hardware state of LED1*/
    static void app_onoff_server_set_cb_1(const app_onoff_server_t * p_server, bool onoff)
    {
        /* Resolve the server instance here if required, this example uses only 1 instance. */
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setting GPIO value: %d\n", onoff)
    
        hal_led_pin_set(ONOFF_SERVER_1_LED, onoff);
    }
    
    /* Callback for reading the hardware state of LED0 */
    static void app_onoff_server_get_cb_0(const app_onoff_server_t * p_server, bool * p_present_onoff)
    {
        /* Resolve the server instance here if required, this example uses only 1 instance. */
    
        *p_present_onoff = hal_led_pin_get(ONOFF_SERVER_0_LED);
    }
    
    /* Callback for reading the hardware state of LED1 */
    static void app_onoff_server_get_cb_1(const app_onoff_server_t * p_server, bool * p_present_onoff)
    {
        /* Resolve the server instance here if required, this example uses only 1 instance. */
    
        *p_present_onoff = hal_led_pin_get(ONOFF_SERVER_1_LED);
    }
  • Added another APP_ONOFF_SERVER_DEF
    /* Generic OnOff server structure definition and initialization */
    APP_ONOFF_SERVER_DEF(m_onoff_server_0,
                         APP_FORCE_SEGMENTATION,
                         APP_MIC_SIZE,
                         app_onoff_server_set_cb_0,
                         app_onoff_server_get_cb_0,
                         app_onoff_server_transition_cb)
    
    APP_ONOFF_SERVER_DEF(m_onoff_server_1,
                         APP_FORCE_SEGMENTATION,
                         APP_MIC_SIZE,
                         app_onoff_server_set_cb_1,
                         app_onoff_server_get_cb_1,
                         app_onoff_server_transition_cb)      // added
  • And then initialized the new server in app_model_init
    static void app_model_init(void)
    {
        /* Instantiate onoff server on element index APP_ONOFF_ELEMENT_INDEX */
        ERROR_CHECK(app_onoff_init(&m_onoff_server_0, APP_ONOFF_ELEMENT_INDEX));
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "App OnOff Model Handle: %d\n", m_onoff_server_0.server.model_handle);
        ERROR_CHECK(app_onoff_init(&m_onoff_server_1, APP_ONOFF_ELEMENT_INDEX+1));                                  // added to initialize 2nd server
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "App OnOff Model Handle: %d\n", m_onoff_server_1.server.model_handle);
    
    #if SCENE_SETUP_SERVER_INSTANCES_MAX > 0
        /* Instantiate Generic Default Transition Time server as needed by Scene models */
        ERROR_CHECK(app_dtt_init(&m_dtt_server_0, APP_ONOFF_ELEMENT_INDEX));
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "App DTT Model Handle: %d\n", m_dtt_server_0.server.model_handle);
    
        /* Instantiate scene server and register onoff server to have scene support */
        ERROR_CHECK(app_scene_model_init(&m_scene_server_0, APP_ONOFF_ELEMENT_INDEX));
        ERROR_CHECK(app_scene_model_add(&m_scene_server_0, &m_onoff_server_0.scene_if));
        ERROR_CHECK(app_onoff_scene_context_set(&m_onoff_server_0, &m_scene_server_0));
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "App Scene Model Handle: %d\n", m_scene_server_0.scene_setup_server.model_handle);
    #endif
    }

Building the program results in no problem. However, when I flashed it into the nRF52840 DK, all 4 LEDs lit up and this is the message in Debug Terminal:

<t:          0>, main.c,  400, ----- BLE Mesh Light Switch Server Demo -----
<t:      12926>, main.c,  356, Initializing and adding models
<t:      12929>, main.c,  208, App OnOff Model Handle: 2
<t:      12933>, app_error_weak.c,  115, Mesh error 19 at 0x00027901

From nrf_error.h, mesh error 19 is "Not enough resources for operation." I'm assuming that the error happened because of the second app_onoff_init, but I am not sure. Any advice on how to fix this error? Thank you. 

  • Hi,

    I see that you're following a guide/suggestion from a 4 year old guide using nRF5 SDK for Mesh v2.2.0. Are you using the same SDK version? We strongly recommend you to 1) preferably use nRF Connect SDK for develeopment of newer apps, 2) if you have to use nRF5 SDK for Mesh: to use the newest version of the SDK. nRF5 SDK is currently in maintenance mode so we will provide support in terms of adding and implementing new features in the SDK.

    If you want to get started with nRF Connect SDK, I highly recommend you have a look at academy.nordicsemi.com/.../ to get started

    I'm following this example to add a server model for LED 2, and I have done the following:
    • As for following this sample, have you also changed ACCESS_SUBSCRIPTION_LIST_COUNT  as the suggested answer in the case you're following does?
    • Can you enter a debug session and trace where 0x00027901 is in your application?

    Let me know about these things then we can see if we can manage to pinpoint the issue.

    Kind regards,
    Andreas

  • Hi Andreas,

    I found out the error after debugging. Apparently, I also need to increase the GENERIC_ONOFF_SERVER_INSTANCES_MAX in nrf_mesh_config_app.h from 1 to 2. I am now able to run the application after changing the code into this: 

    /**
     * The number of (root only) generic onoff instances used by the application.
     */
    #define GENERIC_ONOFF_SERVER_INSTANCES_MAX (2)

    Thank you for the assistance and the nRF Connect SDK reference; I will check it out.

Related