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

I want to combine Switch_light client & provisioner, i want provisioner to control any node.Here is my steps, is some steps miss or wrong? it does'nt work yet!

Step1 : init a Client model in Provisoner:

void user_client_add(void)
{
    m_clients[0].settings.p_callbacks = &client_cbs;
           m_clients[0].settings.timeout = 0;
           m_clients[0].settings.force_segmented = false;
           m_clients[0].settings.transmic_size = NRF_MESH_TRANSMIC_SIZE_SMALL;
    
           ERROR_CHECK(generic_onoff_client_init(&m_clients[0], 0));

}
void models_init_cb(void)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
    m_dev_handles.m_netkey_handle = DSM_HANDLE_INVALID;
    m_dev_handles.m_appkey_handle = DSM_HANDLE_INVALID;
    m_dev_handles.m_self_devkey_handle = DSM_HANDLE_INVALID;

    /* This app requires following models :
     * config client : To be able to configure other devices
     * health client : To be able to interact with other health servers */
    ERROR_CHECK(config_client_init(app_config_client_event_cb));
    ERROR_CHECK(health_client_init(&m_dev_handles.m_health_client_instance, 0, app_health_event_cb));
    //simple_onoff_client.status_cb = simple_on_off_status_cb;
    //ERROR_CHECK(simple_on_off_client_init(&simple_onoff_client,0));
    
    user_client_add();
}

Step2 :config this client:

/* Binds the local models correctly with the desired keys */
void app_default_models_bind_setup(void)
{
    /* Bind health client to App key, and configure publication key */
    ERROR_CHECK(access_model_application_bind(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
    ERROR_CHECK(access_model_publish_application_set(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));

    /* Bind self-config server to the self device key */
    ERROR_CHECK(config_server_bind(m_dev_handles.m_self_devkey_handle));
    /*bind gen_onoff client to app key,, and configure publication key*/
    ERROR_CHECK(access_model_application_bind(m_clients[0].model_handle,m_dev_handles.m_appkey_handle));
    ERROR_CHECK(access_model_publish_application_set(m_clients[0].model_handle, m_dev_handles.m_appkey_handle));
}

Step3:set the pub address of this client & control the remote gen_onoff_Server model:  but it can not work at this step, the status return 7 , how to slove it ??

 case 1:
            {
             set_params.tid = tid++;
             transition_params.delay_ms = 50;
             transition_params.transition_time_ms = 100;
             set_params.on_off = !set_params.on_off;
             if (access_model_publish_address_get(m_clients[0].model_handle, &publish_address_handle) != NRF_SUCCESS)
             {
             }
             if(i == 0)
             {
              
                status = dsm_address_publish_add(GROUP_ADDRESS_ODD, &publish_address_handle);
                printf("get publish_address_handle failed :%d %x \n ",status,GROUP_ADDRESS_ODD);
                
                i=!i;
             }
             else
             { 
                status = dsm_address_publish_add(GROUP_ADDRESS_EVEN, &publish_address_handle);
                printf("add publish_address_ :%d %x\n ",status,GROUP_ADDRESS_EVEN);
                
                i=0;
             }
             (void)access_model_reliable_cancel(m_clients[0].model_handle);
             status = generic_onoff_client_set(&m_clients[0], &set_params, &transition_params);
             printf("generic onoff send %d \n",status);
             hal_led_pin_set(BSP_LED_1, set_params.on_off);
             break;
            }

By the way: if i want to control any node in the mesh net , how to do it? does it  by pub & sub a address to implement ?

  • I trace the code ,find some msg here, is that i add a publication address wrong , how to add it ?

    static bool check_tx_params(access_model_handle_t handle, const access_message_tx_t * p_tx_message, const access_message_rx_t * p_rx_message, uint32_t * p_status)
    {
        NRF_MESH_ASSERT(NULL != p_status);
    
        /* Various checks being done here to ensure that model does not publish a message if
           publication is disabled by setting - Unassigned publish address, or deleted app key */
        if (p_tx_message->length >= ACCESS_MESSAGE_LENGTH_MAX)
        {
            *p_status = NRF_ERROR_INVALID_LENGTH;
        }
        else if (!model_handle_valid_and_allocated(handle) ||
                 m_model_pool[handle].model_info.element_index >= ACCESS_ELEMENT_COUNT)
        {
            *p_status = NRF_ERROR_NOT_FOUND;
        }
        else if ((p_rx_message == NULL &&
                 (m_model_pool[handle].model_info.publish_appkey_handle  == DSM_HANDLE_INVALID ||
                  m_model_pool[handle].model_info.publish_address_handle == DSM_HANDLE_INVALID)) ||
                  !is_valid_opcode(p_tx_message->opcode))
        {
            
            printf("%s....%d \n",__FUNCTION__,__LINE__);
            printf("p_rx_message :%p \n",p_rx_message);
            printf("m_model_pool[handle].model_info.publish_address_handle :%d \n",m_model_pool[handle].model_info.publish_address_handle);
            printf("m_model_pool[handle].model_info.publish_appkey_handle:%d \n",m_model_pool[handle].model_info.publish_appkey_handle);
            printf("is_valid_opcode(p_tx_message->opcode):%d \n",is_valid_opcode(p_tx_message->opcode));
            *p_status = NRF_ERROR_INVALID_PARAM;
        }
        else
        {
            *p_status = NRF_SUCCESS;
        }
    
        return (NRF_SUCCESS == *p_status);
    }

    p_rx_message :00000000
    m_model_pool[handle].model_info.publish_address_handle :65535
    m_model_pool[handle].model_info.publish_appkey_handle:0
    is_valid_opcode(p_tx_message->opcode):1

  • wa! it finally OK!  it works

    step3 SHOULD like this:

     case 1:
                {
                     set_params.tid = tid++;
                     transition_params.delay_ms = 50;
                     transition_params.transition_time_ms = 100;
                     set_params.on_off = !set_params.on_off;
                     dsm_address_publish_add(GROUP_ADDRESS_ODD,&publish_address_handle);
                     dsm_address_publish_add(GROUP_ADDRESS_EVEN,&publish_address_handle_1);
                     if(recv_sucess == 0)
                     {
                      if(i)
                      {
                      status = access_model_publish_address_set(m_clients[0].model_handle,publish_address_handle);
                      publish_address_handle_both = publish_address_handle;
                      publish_address_handle_true = publish_address_handle;
                      i=0;
                      }
                     else
                     {
                        status = access_model_publish_address_set(m_clients[0].model_handle,publish_address_handle_1);
                        publish_address_handle_both = publish_address_handle_1;
                        publish_address_handle_true = publish_address_handle_1;
                        i=!i;
                      }
                }
                else
                {
                      status = access_model_publish_address_set(m_clients[0].model_handle,publish_address_handle_true);
                }
                 
                 printf("publish_address_handle_both:%d \n",publish_address_handle_both);
    
                
                 (void)access_model_reliable_cancel(m_clients[0].model_handle);
                 status = generic_onoff_client_set(&m_clients[0], &set_params, &transition_params);
                 printf("generic onoff send set_params.on_off:%d -- %d \n",set_params.on_off,status);
                 hal_led_pin_set(BSP_LED_1, set_params.on_off);
                 break;
                }

Related