I am trying to sending data from custom bluetooth mesh sensor server to sensor client, but the sensor_cli_data_cb() function cannot get called.

I am trying to send data from icm20948 sensor from the sensor node to the observer node using ble mesh. Due to the data from icm20948 is too large (9 uint16_t, 18bytes) for the given sensor types from nordic sample, so I created a custom sensor server to send them. The sensor server structure looks like this:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static const struct bt_mesh_sensor_channel people_count_sensor_channels[] = { {
.format = &bt_mesh_sensor_format_count_16,
.name = "channel_1",
}, {
.format = &bt_mesh_sensor_format_count_16,
.name = "channel_2",
}, {
.format = &bt_mesh_sensor_format_count_16,
.name = "channel_3",
},
};
static const struct bt_mesh_sensor_type icm20948_sensor_type_accel = {
.id = BT_MESH_PROP_ID_CUSTOM_ICM20948_ACCEL,
.channel_count = 3,
.channels = people_count_sensor_channels,
};
static const struct bt_mesh_sensor_type icm20948_sensor_type_gyro = {
.id = BT_MESH_PROP_ID_CUSTOM_ICM20948_GYRO,
.channel_count = 3,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and it successfully sent 18 bytes data by putting them into 3 custom sensor instances each of which contains 3 sensor channels. I could then see data getting sent on nrf mesh mobile app by configuring the sensor server.

After that, I tried to get those data by sensor client sample on another board. I changed the sensor_client sample to read the PROP_ID I set for my custom sensor types, like this:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
/* ... ... */
case (5): {
err = bt_mesh_sensor_cli_get(&sensor_cli, NULL, &icm20948_sensor_type_accel, NULL);
if (err) {
printk("Error getting people count (%d)\n", err);
} else {
printk("Success getting people count data!\n");
}
break;
}
/* ... ... */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and the sensor_cli_data_cb() function like this:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
static void sensor_cli_data_cb(struct bt_mesh_sensor_cli *cli,
struct bt_mesh_msg_ctx *ctx,
const struct bt_mesh_sensor_type *sensor,
const struct bt_mesh_sensor_value *value)
{
enum bt_mesh_sensor_value_status status;
if (sensor->id == icm20948_sensor_type_accel.id) {
printk("ICM20948 accel data is %s\n", bt_mesh_sensor_ch_str(value));
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Then I built and flashed the board, configured the sensor server and sensor client on app, then I found that I can see data being sent from sensor server on the sensor node board, and get_data function of my sensor client run correctly, but the sensor_cli_data_cb() function cannot get called.

I tried to use the given sensor type from the sample (like people count sensor), the sensor_cli_data_cb() function can get called correctly after receiving message; but once I changed to my custom sensor server and sensor client, I cannot see the sensor_cli_data_cb() function getting called.