Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Multiple generic level models using same level_set_cb()

Hello,

I am using 15.2.0 SDK and 3.1.0 Mesh SDK.

I was trying to control two LED's on the nRF52DK using two generic level server models. I made following changes to the code for dimming_server:

Added an extra PWM module, initialized and enabled it to control different LED -

APP_PWM_INSTANCE(PWM1, 2);
app_pwm_config_t m_pwm1_config = APP_PWM_DEFAULT_CONFIG_1CH(1000, BSP_LED_1);
uint32_t status1 = app_pwm_init(&PWM1, &m_pwm1_config, NULL); APP_ERROR_CHECK(status1);
app_pwm_enable(&PWM1);

Then, created a new level server model -

APP_LEVEL_SERVER_DEF(m_level_server_1, APP_CONFIG_FORCE_SEGMENTATION, APP_CONFIG_MIC_SIZE, NULL, app_level_server_set_cb, app_level_server_get_cb);

Modified level_set_cb() as below differentiate between models using model handles -

static void app_level_server_set_cb(const app_level_server_t * p_server, int16_t present_level)
{
    /* Resolve the server instance here if required, this example uses only 1 instance. */
    m_pwm0_present_level = present_level;
    if(p_server->server.model_handle == m_level_server_0.server.model_handle)    
         (void) app_pwm_channel_duty_ticks_set(&PWM0, 0, scaled_pwm_ticks_get(m_pwm0_present_level));
    else if(p_server -> server.model_handle == m_level_server_1.server.model_handle)
         (void) app_pwm_channel_duty_ticks_set(&PWM1, 0, scaled_pwm_ticks_get(m_pwm0_present_level));   
}

And initiated both the generic level models in the app_model_init().

I provisioned the board and when I try to set the dimming level using the app, both the models control BSP_LED_0 whereas they are supposed to control different LED's.

Similar behavior is observed with generic_onoff models too.

I am using the model handle to differentiate between them which ain't working. Is there any other way to achieve the control over two LED's?

Thank you.  

Parents
  • Hi,

    Have you made sure you define the 2 models on 2 different elements ? 

    By spec, on an element there should be only one model per one opcode. In your case my understanding is that the access layer will just call the call back for the first model and ignore the 2nd one. 

    If you have the model bound to two different elements, you can simply use the different address of the element to control each server. You can find multiple same models bound to different elements in the light switch client example. 

  • Hi, 

    If you have the model bound to two different elements, you can simply use the different address of the element to control each server.

    I will try it out and update you. 

    I am curious to know why model_handle (which is unique to each model) isn't able to differentiate? You have any idea about this?

    Thank you.

Reply Children
No Data
Related