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

Light_switch NRF_ERROR_FORBIDDEN error

I get NRF_ERROR_FORBIDDEN error when I want to send a software message to the server device in the Light_switch application, except for the button. But when I press the button, the message is transmitted. What could be the solution to this?

Geliştirme Kitini Kullanma: Nrf-52 DK

SDK Sürümü: nRF5_SDK_15.0

Ağ Sürümü: : nrf5_SDK_for_Mesh_v2.2.0

static void send_message(uint32_t button_number)
{
   
    //uint32_t button_number=0;
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Send message: \n");
     __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
    uint32_t status = NRF_SUCCESS;
    generic_onoff_set_params_t set_params;
    model_transition_t transition_params;
    static uint8_t tid = 0;

    /* Button 1: ON, Button 2: Off, Client[0]
     * Button 2: ON, Button 3: Off, Client[1]
     */

    switch(button_number)
    {
        case 0:
        case 2:
            set_params.on_off = APP_STATE_ON;
            break;

        case 1:
        case 3:
            set_params.on_off = APP_STATE_OFF;
            break;
    }

    set_params.tid = tid++;
    set_params.sensor_value=123;
    transition_params.delay_ms = APP_CONFIG_ONOFF_DELAY_MS;
    transition_params.transition_time_ms = APP_CONFIG_ONOFF_TRANSITION_TIME_MS;
     __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Sending msg: ONOFF SET %d Sensor_Value %d delay_ms %d transition_time_ms %d\n", set_params.on_off,set_params.sensor_value, transition_params.delay_ms,transition_params.transition_time_ms);

    switch (button_number)
    {
        case 0:
        case 1:
            /* Demonstrate acknowledged transaction, using 1st client model instance */
            /* In this examples, users will not be blocked if the model is busy */
            button_counter++;
            (void)access_model_reliable_cancel(m_clients[0].model_handle);
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "model_handle: %u\n",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);
            write_eeprom(button_address,button_counter);
            break;

        case 2:
        case 3:
            /* Demonstrate un-acknowledged transaction, using 2nd client model instance */
            status = generic_onoff_client_set_unack(&m_clients[1], &set_params,
                                                    &transition_params, APP_UNACK_MSG_REPEAT_COUNT);
            hal_led_pin_set(BSP_LED_1, set_params.on_off);
            break;
      }
 __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status: %u\n", status);
    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, "Client %u cannot send\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, "Publication not configured for client %u\n", button_number);
            break;
         case NRF_ERROR_FORBIDDEN:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "NRF_ERROR_FORBIDDEN for client %u\n", button_number);
            break;
        default:
            ERROR_CHECK(status);
            break;
   }
}
int main(void)
{
  bool status1=true ;
    initialize();
    execution_start(start);
    start_eeprom();
    correctly_send_counter=read_eeprom(correctly_send_address);
    button_counter=read_eeprom(button_address);
    if(correctly_send_counter>2000  ||  button_counter>2000 ){
      correctly_send_counter=0;
      button_counter=0;
    }
  send_message(0);
    
    for (;;)
    {
        (void)sd_app_evt_wait();
        if(flag){
         flag=false;
          for(int i=0; i<5; i++){
            hal_led_pin_set(BSP_LED_3,1);
            nrf_delay_ms(100);
            hal_led_pin_set(BSP_LED_3,0);
            nrf_delay_ms(100);
           }
         
        }
        if(status1){
        
        status1=false;
        }
        if(correctly_send_flag){
          write_eeprom(correctly_send_address,correctly_send_counter);
          correctly_send_flag=false;
        }
    }
}

Error Output :

Parents Reply Children
No Data
Related