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 ?