BLE Mesh: Multiple elements on a single device
Posted: Wed Feb 20, 2019 12:33 pm
Hi All
I have successfully used the bluetooth mesh node example to communicate from the nRf iOS provisioning app to my device.
I'm able to provision the device, and set on/off states from the iOS app.
In my device, I've the following elements :
0- read only element
1- read only element
2- get/set/setunack element
I'm trying to modify the node example to add two elements so the app can both read the status of elements 0/1 as well as get/set the state of element 2. I'm not able to add the above element so far.
What I've done is as follow :
Define two models, one is get only, another is get/set
///////////////////////////////////////////////////////////////////////////////////////////
static esp_ble_mesh_model_op_t onoff_op_get_only[] = { // JDS
{ ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET, 0, 0},
// Each model operation struct array must use this terminator
// as the end tag of the operation uint.
ESP_BLE_MESH_MODEL_OP_END,
};
///////////////////////////////////////////////////////////////////////////////////////////
static esp_ble_mesh_model_op_t onoff_op_get_set_setunack[] = {
{ ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET, 0, 0},
{ ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET, 2, 0},
{ ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK, 2, 0},
// Each model operation struct array must use this terminator
// as the end tag of the operation uint.
ESP_BLE_MESH_MODEL_OP_END,
};
reference all models
///////////////////////////////////////////////////////////////////////////////////////////
static esp_ble_mesh_model_t root_models[] = {
ESP_BLE_MESH_MODEL_CFG_SRV(&config_server),
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, onoff_op_get_only, &onoff_pub, &read_state[0]),
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, onoff_op_get_only, &onoff_pub, &read_state[1]),
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, onoff_op_get_set_setunack, &onoff_pub, &readSet_state[0]),
};
///////////////////////////////////////////////////////////////////////////////////////////
static esp_ble_mesh_elem_t elements[] = {
ESP_BLE_MESH_ELEMENT(0, root_models, ESP_BLE_MESH_MODEL_NONE),
};
What I do not understand is how I can add more elements that are using the same model ? In the node example, the macro ESP_BLE_MESH_ELEMENT is linked to root_models, not to a single model.
So by doing the above, I'm not defining multiple elements but multiple models instead.
By the way, when debugging the above code, the get / set callbacks are no longer called.
Any help in defining multiple elements using similar models would be greatly appreciated.
Thanks
I have successfully used the bluetooth mesh node example to communicate from the nRf iOS provisioning app to my device.
I'm able to provision the device, and set on/off states from the iOS app.
In my device, I've the following elements :
0- read only element
1- read only element
2- get/set/setunack element
I'm trying to modify the node example to add two elements so the app can both read the status of elements 0/1 as well as get/set the state of element 2. I'm not able to add the above element so far.
What I've done is as follow :
Define two models, one is get only, another is get/set
///////////////////////////////////////////////////////////////////////////////////////////
static esp_ble_mesh_model_op_t onoff_op_get_only[] = { // JDS
{ ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET, 0, 0},
// Each model operation struct array must use this terminator
// as the end tag of the operation uint.
ESP_BLE_MESH_MODEL_OP_END,
};
///////////////////////////////////////////////////////////////////////////////////////////
static esp_ble_mesh_model_op_t onoff_op_get_set_setunack[] = {
{ ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET, 0, 0},
{ ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET, 2, 0},
{ ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK, 2, 0},
// Each model operation struct array must use this terminator
// as the end tag of the operation uint.
ESP_BLE_MESH_MODEL_OP_END,
};
reference all models
///////////////////////////////////////////////////////////////////////////////////////////
static esp_ble_mesh_model_t root_models[] = {
ESP_BLE_MESH_MODEL_CFG_SRV(&config_server),
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, onoff_op_get_only, &onoff_pub, &read_state[0]),
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, onoff_op_get_only, &onoff_pub, &read_state[1]),
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, onoff_op_get_set_setunack, &onoff_pub, &readSet_state[0]),
};
///////////////////////////////////////////////////////////////////////////////////////////
static esp_ble_mesh_elem_t elements[] = {
ESP_BLE_MESH_ELEMENT(0, root_models, ESP_BLE_MESH_MODEL_NONE),
};
What I do not understand is how I can add more elements that are using the same model ? In the node example, the macro ESP_BLE_MESH_ELEMENT is linked to root_models, not to a single model.
So by doing the above, I'm not defining multiple elements but multiple models instead.
By the way, when debugging the above code, the get / set callbacks are no longer called.
Any help in defining multiple elements using similar models would be greatly appreciated.
Thanks