Hello,
I am trying to establish a mesh network with two nodes(self provisioned) simulating the Light and Light_switch examples without the provisioner. My plan is to play around with this network and eventually use a provisioner in the future.
I am primarily using the Mesh-demo sample which is self provisioning. Since I wanted to use my DK, I am adding the Model_handler portion of light_switch sample to create the Gen_OnOff models. I have just commented out the Heartbeat functionality that comes with the Mesh-Demo sample.
After setting the publish address to the model by calling the bt_mesh_cfg_mod_pub_set(net_idx, 0x000e, 0x000e, BT_MESH_MODEL_ID_GEN_ONOFF_CLI, &pub, NULL) , when I press the button, the button_handler() returns an error as there is no Model->pub->addr. I checked using the debugger and it is indeed set to 0x00
Now, do both the server and the client node need to be already on the mesh network before I call the pub_set() function? I only have the client node on when I am performing this operation.
If not, what am I missing? here are my publish parameters
struct bt_mesh_cfg_mod_pub pub = {
.addr = 0x000d, // server node address
.app_idx = app_idx,
.ttl = 1,
.period = BT_MESH_PUB_PERIOD_SEC(3),
};
Here my client node address is 0x000e and the server I'd like to publish to has the Unicast address 0x000d
Here is my Mesh element structure with just one element
static struct bt_mesh_elem elements[] = {
#if DT_NODE_EXISTS(DT_ALIAS(sw0))
BT_MESH_ELEM(1,
BT_MESH_MODEL_LIST(
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
BT_MESH_MODEL_ONOFF_CLI(&buttons[0].client)),
BT_MESH_MODEL_NONE),
#endif
function call sequence shown below
dk_leds_init();
dk_buttons_init(NULL);
bt_mesh_init(&prov, model_handler_init());
.
.
bt_mesh_provision(net_key, net_idx, flags, iv_index, addr, dev_key);
.
.
bt_mesh_cfg_app_key_add(net_idx, 0x000e, net_idx, app_idx, app_key, NULL);
bt_mesh_cfg_mod_app_bind(net_idx, 0x000e, 0x000e, app_idx, BT_MESH_MODEL_ID_HEALTH_SRV, NULL);
bt_mesh_cfg_mod_app_bind(net_idx, 0x000e, 0x000e, app_idx, BT_MESH_MODEL_ID_GEN_ONOFF_CLI, NULL);
bt_mesh_cfg_mod_pub_set(net_idx, 0x000e, 0x000e, BT_MESH_MODEL_ID_GEN_ONOFF_CLI, &pub, NULL);
Finally here is my Proj.conf
CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_HWINFO=y
CONFIG_BT=y
CONFIG_BT_ECC=y
CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y
CONFIG_BT_SETTINGS=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_MESH=y
CONFIG_BT_MESH_RELAY=y
CONFIG_BT_MESH_SUBNET_COUNT=1
CONFIG_BT_MESH_APP_KEY_COUNT=1
CONFIG_BT_MESH_MODEL_GROUP_COUNT=2
CONFIG_BT_MESH_ADV_BUF_COUNT=64
CONFIG_BT_MESH_LABEL_COUNT=0
CONFIG_BT_MESH_PB_ADV=n
CONFIG_BT_MESH_CFG_CLI=y
CONFIG_BT_MESH_LOOPBACK_BUFS=8
CONFIG_BT_MESH_TX_SEG_MAX=32
CONFIG_BT_MESH_TX_SEG_MSG_COUNT=3
CONFIG_BT_MESH_RX_SEG_MSG_COUNT=3
CONFIG_BT_MESH_DK_PROV=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600
CONFIG_DK_LIBRARY=y
CONFIG_BT_MESH_DK_PROV=y
CONFIG_BT_MESH_ONOFF_CLI=y
CONFIG_BT_MESH_ONOFF_SRV=n
CONFIG_BT_DEBUG_NONE=n
Where does the Model->pub->address get set? from my understanding it should be set during the pub_set() function
UPDATE: I noticed that the cfg_cli.c sets the app_idx to 'BT_MESH_KEY_DEV_REMOTE' where as my publish parameters were setting it to '0'. However I am still seeing the same result. Still no keys or address is assigned to my gen_onoff_cli model.
UPDATE: I have manually added keys to my models following the 'Mesh' sample.
err = bt_mesh_app_key_add(0, 0, app_key);
models[2].keys[0] = 0;
models[3].keys[0] = 0;
This solved my problem. But, my initial function call sequence should allocate address and keys to the models which is still my question.