Dear all,
I try to self provision device by it self following steps below:
Step 1 : Bind key
void app_common_self_provision(access_model_handle_t handle, bool is_client, uint16_t unicast_addr, uint8_t * netkey, uint8_t * appkey) { dsm_handle_t netkey_handle, devkey_handle; dsm_local_unicast_address_t local_address; local_address.address_start = unicast_addr; local_address.count = ACCESS_ELEMENT_COUNT; uint32_t status; /* Store received provisioning data in the DSM */ status = dsm_local_unicast_addresses_set(&local_address); ERROR_CHECK(status); status = dsm_subnet_add(0, netkey, &netkey_handle); ERROR_CHECK(status); // NRF_MESH_ERROR_CHECK(net_state_iv_index_set(0, 0)); dsm_handle_t app_handle; dsm_handle_t network_handle = dsm_net_key_index_to_subnet_handle(0); status = dsm_appkey_add(0, network_handle, appkey, &app_handle); ERROR_CHECK(status); // ERROR_CHECK(dsm_devkey_add(unicast_addr, netkey_handle, m_provisioner.p_nw_data->self_devkey, &m_provisioner.p_dev_data->m_self_devkey_handle)); /* Bind config server to the device key */ if (!is_client) status = config_server_bind(devkey_handle); ERROR_CHECK(status); status = access_model_application_bind(handle, app_handle); ERROR_CHECK(status); __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "provision_by_my_self done\r\n"); ERROR_CHECK(access_default_ttl_set(NRF_MESH_TTL_MAX)); }
Step 2 : Subscribe to topic
void subscribe_default_topic() { __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Add default subscribe topic\r\n"); dsm_handle_t subscription_address_handle; uint32_t status; status = dsm_address_subscription_add(m_dev_info.info.topic_all, &subscription_address_handle); NRF_MESH_ERROR_CHECK(status); status = access_model_subscription_add(m_custom_server_0.server.model_handle, subscription_address_handle); NRF_MESH_ERROR_CHECK(status); status = dsm_address_subscription_add(m_dev_info.info.topic_control, &subscription_address_handle); NRF_MESH_ERROR_CHECK(status); status = access_model_subscription_add(m_custom_server_0.server.model_handle, subscription_address_handle); NRF_MESH_ERROR_CHECK(status); }
Step3 : Set publication topic
static void add_default_publication_topic(void) { __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Add default publication topic\r\n"); dsm_handle_t publish_address_handle; ERROR_CHECK(dsm_address_publish_add(m_dev_info.info.topic_report, &publish_address_handle)); ERROR_CHECK(access_model_publish_address_set(m_custom_server_0.server.model_handle, publish_address_handle)); ERROR_CHECK(access_model_publish_application_set(m_custom_server_0.server.model_handle, publish_address_handle)); }
Step 4 The main code to config device
#if 1 custom_application_server_t *p_server = &m_custom_server_0; app_common_self_provision(p_server->server.model_handle, false, m_dev_info.info.exchange_pair_addr, m_dev_info.info.key.netkey, m_dev_info.info.key.appkey); subscribe_default_topic(); add_default_publication_topic(); uint8_t id = PAIR_ID_PROCESS_DONE; mesh_central_data_t msg; msg.len = 1; msg.data = &id; mesh_device_central_send(&msg); #endif
The problem is, after self provisioned and reboot device, when message publish from client in other node always return error 5 (NRF_ERROR_NOT_FOUND)
But when i comment out function subscribe_default_topic, device publish message without error.
Could you please give me your suggestion?
Thank you