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

BLE MESH stack 3.0 - message send on timer issue

Hi,

i'm using BLE MESH 3.0 Light Switch Example code. i want to send Light on-Off  command every 2 second Timer base instead of Button press.

i got an error below.

Parents
  • Hello Bjorn Kvaale

    Thanks But i'm using BLE MESH SDK 3.0 .I want to send Light On/Off Command evrny 10Second.

    If i print String every 10 second and command send on Button pressed it's working well . but i send command every 10 second code is stuck.

    APP_TIMER_DEF(m_temp_timer);
    uint8_t sec_2 =0;
    static void temp_handler(void * p_context)
    {
      UNUSED_VARIABLE(p_context);
      sec_2=1;
    }
    
    static void msg_send_to_server(void)
    {
    
        uint32_t status = NRF_SUCCESS;
        generic_onoff_set_params_t set_params;
        model_transition_t transition_params;
    
    
        static uint8_t tid = 0;
    
        set_params.on_off[0] = APP_STATE_ON;
         
    
        set_params.tid = tid++;
        transition_params.delay_ms = APP_CONFIG_ONOFF_DELAY_MS;//50MS
        transition_params.transition_time_ms = APP_CONFIG_ONOFF_TRANSITION_TIME_MS;//100MS
    
        /* Demonstrate acknowledged transaction, using 1st client model instance */
        /* In this examples, users will not be blocked if the model is busy */
        // (void)access_model_reliable_cancel(m_clients[0].model_handle);
        status = generic_onoff_client_set(&m_clients[0], &set_params, &transition_params);
    
        hal_led_pin_set(BSP_LED_0, set_params.on_off);  
    
        switch (status)
        {
            case NRF_SUCCESS:
                break;
    
            case NRF_ERROR_NO_MEM:
            case NRF_ERROR_BUSY:
            case NRF_ERROR_INVALID_STATE:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "\nClient %u cannot send\r\n", button_number);
                hal_led_blink_ms(LEDS_MASK, LED_BLINK_SHORT_INTERVAL_MS, LED_BLINK_CNT_NO_REPLY);
                break;
    
            case NRF_ERROR_INVALID_PARAM:
                /* Publication not enabled for this client. One (or more) of the following is wrong:
                 * - An application key is missing, or there is no application key bound to the model
                 * - The client does not have its publication state set
                 *
                 * It is the provisioner that adds an application key, binds it to the model and sets
                 * the model's publication state.
                 */
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "\n Publication not configured for client %u\r\n", button_number);
                break;
    
            default:
                ERROR_CHECK(status);
                break;
        }
    }
    
    static void initialize(void)
    {
    
    
        __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS | LOG_SRC_BEARER, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"\n----- BLE Mesh Light Switch Client Demo -----\r\n");
    
      
    
        ERROR_CHECK(app_timer_init());
        hal_leds_init();
    
    #if BUTTON_BOARD
        ERROR_CHECK(hal_buttons_init(button_event_handler));
    #endif
    
        ble_stack_init();
    
    #if MESH_FEATURE_GATT_ENABLED
        gap_params_init();
        conn_params_init();
    #endif
        mesh_init();
        
    
       ERROR_CHECK(app_timer_create(&m_temp_timer, APP_TIMER_MODE_REPEATED, temp_handler));
       ERROR_CHECK(app_timer_start(m_temp_timer, MAX(APP_TIMER_MIN_TIMEOUT_TICKS, HAL_MS_TO_RTC_TICKS(10000)), NULL));
    
    }
    
    
    int main(void)
    {
    
       initialize();
        start();
    
        for (;;)
        {
    
           if(sec_2)
           {
             msg_send_to_server();
             __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"\n----- 2Second Timer Run-----\r\n");
             sec_2=0;
           }
    
    
        
            (void)sd_app_evt_wait();
        }
    
    
    
    }

    Got an above Error. Please reply me ASAP.

    Thanks,

    Nikunj

Reply
  • Hello Bjorn Kvaale

    Thanks But i'm using BLE MESH SDK 3.0 .I want to send Light On/Off Command evrny 10Second.

    If i print String every 10 second and command send on Button pressed it's working well . but i send command every 10 second code is stuck.

    APP_TIMER_DEF(m_temp_timer);
    uint8_t sec_2 =0;
    static void temp_handler(void * p_context)
    {
      UNUSED_VARIABLE(p_context);
      sec_2=1;
    }
    
    static void msg_send_to_server(void)
    {
    
        uint32_t status = NRF_SUCCESS;
        generic_onoff_set_params_t set_params;
        model_transition_t transition_params;
    
    
        static uint8_t tid = 0;
    
        set_params.on_off[0] = APP_STATE_ON;
         
    
        set_params.tid = tid++;
        transition_params.delay_ms = APP_CONFIG_ONOFF_DELAY_MS;//50MS
        transition_params.transition_time_ms = APP_CONFIG_ONOFF_TRANSITION_TIME_MS;//100MS
    
        /* Demonstrate acknowledged transaction, using 1st client model instance */
        /* In this examples, users will not be blocked if the model is busy */
        // (void)access_model_reliable_cancel(m_clients[0].model_handle);
        status = generic_onoff_client_set(&m_clients[0], &set_params, &transition_params);
    
        hal_led_pin_set(BSP_LED_0, set_params.on_off);  
    
        switch (status)
        {
            case NRF_SUCCESS:
                break;
    
            case NRF_ERROR_NO_MEM:
            case NRF_ERROR_BUSY:
            case NRF_ERROR_INVALID_STATE:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "\nClient %u cannot send\r\n", button_number);
                hal_led_blink_ms(LEDS_MASK, LED_BLINK_SHORT_INTERVAL_MS, LED_BLINK_CNT_NO_REPLY);
                break;
    
            case NRF_ERROR_INVALID_PARAM:
                /* Publication not enabled for this client. One (or more) of the following is wrong:
                 * - An application key is missing, or there is no application key bound to the model
                 * - The client does not have its publication state set
                 *
                 * It is the provisioner that adds an application key, binds it to the model and sets
                 * the model's publication state.
                 */
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "\n Publication not configured for client %u\r\n", button_number);
                break;
    
            default:
                ERROR_CHECK(status);
                break;
        }
    }
    
    static void initialize(void)
    {
    
    
        __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS | LOG_SRC_BEARER, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"\n----- BLE Mesh Light Switch Client Demo -----\r\n");
    
      
    
        ERROR_CHECK(app_timer_init());
        hal_leds_init();
    
    #if BUTTON_BOARD
        ERROR_CHECK(hal_buttons_init(button_event_handler));
    #endif
    
        ble_stack_init();
    
    #if MESH_FEATURE_GATT_ENABLED
        gap_params_init();
        conn_params_init();
    #endif
        mesh_init();
        
    
       ERROR_CHECK(app_timer_create(&m_temp_timer, APP_TIMER_MODE_REPEATED, temp_handler));
       ERROR_CHECK(app_timer_start(m_temp_timer, MAX(APP_TIMER_MIN_TIMEOUT_TICKS, HAL_MS_TO_RTC_TICKS(10000)), NULL));
    
    }
    
    
    int main(void)
    {
    
       initialize();
        start();
    
        for (;;)
        {
    
           if(sec_2)
           {
             msg_send_to_server();
             __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"\n----- 2Second Timer Run-----\r\n");
             sec_2=0;
           }
    
    
        
            (void)sd_app_evt_wait();
        }
    
    
    
    }

    Got an above Error. Please reply me ASAP.

    Thanks,

    Nikunj

Children
Related