This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Light Switch Client stop due to ++m_scheduler.event_count < 0?

I am working on nrf5_SDK_for_Mesh_v2.2.0 with nRF5_SDK_15.0.0 and softdevice 6.0.0. I run code on PCA10040 dev boards. I am trying use a timer to send onoff message from a client to two servers. but the client stopped after 2 hrs, it returns an error "Mesh assert at 0x0002C860". I use addr2line tool to check where it happened, and found it happened in mesh/core/src/timmer_scheduler.c:91 which calls NRF_MESH_ASSERT(++m.scheduler.event_count > 0)

in this case, the client sends the message every 50ms, and I set the APP_CONFIG_ONOFF_DELAY_MS and APP_CONFIG_ONOFF_TRANSITION_TIME_MS to 0.

is there any limitation on the sending speed side? if not what may cause this problem?

  • The assert NRF_MESH_ASSERT(++m_scheduler.event_count > 0) failed, due to an overflow (since event_count is of type uint16_t and can't contain a negative value). 

    The only place event_count is decremented is inside the function fire_timers(..). However, if the functions timer_sch_reschedule(..) or timer_sch_abort is called, the function remove_evt(..) will be called, and inside remove_evt(..), event_count is not decremented. After 2 hours of running your application, these functions have been called enough times to make event_count overflow

    Thus, the error you encountered is due to a bug in the code, and is reported.

    The problem can be solved by adding 

    m_scheduler.event_count--;

    inside the function remove_evt(..).

    Best regards, Simon

  • this is not working, it causing mesh assert. Could you please explain how to implement this? (Also checked if the event_count > 0 condition before --)

  • I just discovered this issue myself, and out of curiosity, I searched to see if anyone else has reported it.

    I can add a clarification to the provided solution: since the count is incremented when an event is added to the queue, so too must the count be decremented when an event is removed from the queue. There are 2 places that events can be removed from the scheduler queue: in fire_timers and in remove_evt. I copied the decrement instruction from fire_timers and inserted it in remove_evt before line 108:

    if (p_it->p_next == p_evt)
    {
        NRF_MESH_ASSERT(m_scheduler.event_count-- > 0); //ATTENTION: unofficial modification
        p_it->p_next = p_evt->p_next;
        break;
    }

Related