Hi all,
I am using nRF SDK for Mesh v1.0.1 and I want to implement following as in picture:
I am publishing to group address (group address because in the future I want to use more nodes with simple OnOff server model). I send the message from the OnOff client to the OnOff server, the light switch turns on. But I am not receiving message after publishing to that group address (I didnt change code for switch server and from the simple_on_off_server.c I can see that after receiving SIMPLE_ON_OFF_OPCODE_SET_UNRELIABLE the callback function responds with publish_state() to the address set as publish address for that simple OnOff server model - and that is set by provisioner). In nrf connect app I can see, that the message is sent from the OnOff server model, but not received by simple OnOff client model. First I thought that I set the bad Publish address for OnOff server model (set to PROVISIONER ADDRESS + 1 - in nrf_mesh_config_app.h set the right count of models[3] and elements[2 for light switch client example]) but I dont think that this is the issue. I enclose key parts of code:
SERVER_COUNT set to 1, because I provision only 1 element
key functions from main.c:
SERVER_COUNT set to 1 because I want to provision only one element
access_setu() function and all the necessary configuring for OnOff client model:
static void access_setup(void) { __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setting up access layer and models\n"); dsm_init(); access_init(); m_netkey_handle = DSM_HANDLE_INVALID; m_appkey_handle = DSM_HANDLE_INVALID; for (uint32_t i = 0; i < SERVER_COUNT; ++i) { m_devkey_handles[i] = DSM_HANDLE_INVALID; m_server_handles[i] = DSM_HANDLE_INVALID; } m_group_handle = DSM_HANDLE_INVALID; /* Initialize and enable all the models before calling ***_flash_config_load. */ ERROR_CHECK(config_client_init(config_client_event_cb)); ERROR_CHECK(health_client_init(&m_health_client, 0, health_event_cb)); for (uint32_t i = 0; i < 1; ++i) { m_clients[i].status_cb = client_status_cb; ERROR_CHECK(simple_on_off_client_init(&m_clients[i], i+1));//i+1 because i dont want to have together //in element0 OnOff model with control model and health model } if (dsm_flash_config_load()) { m_provisioned_devices = provisioned_device_handles_load(); } else { /* Set and add local addresses and keys, if flash recovery fails. */ dsm_local_unicast_address_t local_address = {PROVISIONER_ADDRESS, 2}; ERROR_CHECK(dsm_local_unicast_addresses_set(&local_address)); ERROR_CHECK(dsm_address_publish_add(GROUP_ADDRESS, &m_group_handle)); ERROR_CHECK(dsm_subnet_add(0, m_netkey, &m_netkey_handle)); ERROR_CHECK(dsm_appkey_add(0, m_netkey_handle, m_appkey, &m_appkey_handle)); } if (access_flash_config_load()) { m_configured_devices = configured_devices_count_get(); } else { /* Bind the keys to the health client. */ ERROR_CHECK(access_model_application_bind(m_health_client.model_handle, m_appkey_handle)); ERROR_CHECK(access_model_publish_application_set(m_health_client.model_handle, m_appkey_handle)); ERROR_CHECK(access_model_application_bind(m_clients[0].model_handle, m_appkey_handle)); ERROR_CHECK(access_model_publish_application_set(m_clients[0].model_handle, m_appkey_handle)); ERROR_CHECK(access_model_publish_address_set(m_clients[0].model_handle, m_group_handle)); access_flash_config_store(); } provisioner_init(); if (m_configured_devices < m_provisioned_devices)//tu sa jedna o pocty serverov nie clientov { provisioner_configure(UNPROV_START_ADDRESS + m_configured_devices); } else if (m_provisioned_devices < SERVER_COUNT) { provisioner_wait_for_unprov(UNPROV_START_ADDRESS + m_provisioned_devices); } }
void provisioner_prov_complete_cb(const nrf_mesh_prov_evt_complete_t * p_prov_data) { /* We should not get here if all servers are provisioned. */ NRF_MESH_ASSERT(m_configured_devices < SERVER_COUNT); __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning complete. Adding address 0x%04x.\n", p_prov_data->address); ERROR_CHECK(dsm_address_publish_add(p_prov_data->address, &m_server_handles[m_provisioned_devices])); ERROR_CHECK(dsm_devkey_add(p_prov_data->address, m_netkey_handle, p_prov_data->p_devkey, &m_devkey_handles[m_provisioned_devices])); ERROR_CHECK(config_client_server_bind(m_devkey_handles[m_provisioned_devices])); ERROR_CHECK(config_client_server_set(m_devkey_handles[m_provisioned_devices], m_server_handles[m_provisioned_devices])); m_provisioned_devices++; /* Move on to the configuration step. */ provisioner_configure(UNPROV_START_ADDRESS + m_configured_devices); }
void provisioner_config_successful_cb(void) { __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u successful\n", m_configured_devices); hal_led_pin_set(BSP_LED_0 + m_configured_devices, false); m_configured_devices++; if (m_configured_devices < SERVER_COUNT) { provisioner_wait_for_unprov(UNPROV_START_ADDRESS + m_provisioned_devices); hal_led_pin_set(BSP_LED_0 + m_configured_devices, true); } else { __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "All servers provisioned\n"); hal_led_blink_ms(LEDS_MASK, 100, 4); } }
from provisioner.c:
the handler prov_evt_handler() completed fine
I went through this steps by incrementing ->
static const config_steps_t server_config[]=
{
PROV_STATE_CONFIG_COMPOSITION_GET,
PROV_STATE_CONFIG_APPKEY_ADD,
PROV_STATE_CONFIG_APPKEY_BIND_HEALTH,
PROV_STATE_CONFIG_APPKEY_BIND_ONOFF,
PROV_STATE_CONFIG_PUBLICATION_HEALTH,
PROV_STATE_CONFIG_PUBLICATION_ONOFF,
PROV_STATE_CONFIG_SUBSCRIPTION,
};
i include where i have doubts:
/* Configure the publication parameters for the On/Off server: */ case PROV_STATE_CONFIG_PUBLICATION_ONOFF: { config_publication_state_t pubstate = {0}; pubstate.element_address = m_target_address; pubstate.publish_address.type = NRF_MESH_ADDRESS_TYPE_UNICAST; pubstate.publish_address.value = PROVISIONER_ADDRESS + 1; pubstate.appkey_index = 0; pubstate.frendship_credential_flag = false; pubstate.publish_ttl = SERVER_COUNT; pubstate.publish_period.step_num = 0; pubstate.publish_period.step_res = ACCESS_PUBLISH_RESOLUTION_100MS; pubstate.retransmit_count = 1; pubstate.retransmit_interval = 0; pubstate.model_id.company_id = ACCESS_COMPANY_ID_NORDIC; pubstate.model_id.model_id = SIMPLE_ON_OFF_SERVER_MODEL_ID; __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setting publication address for the On/Off server to 0x%04x\n", pubstate.publish_address.value); ERROR_CHECK(config_client_model_publication_set(&pubstate)); break; }
What am I missing? Something to change in mesh_config_app.h or what? Thankful for each one answer.
Patrik