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:
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,
.channels = people_count_sensor_channels,
};
static const struct bt_mesh_sensor_type icm20948_sensor_type_mag = {
.id = BT_MESH_PROP_ID_CUSTOM_ICM20948_MAG,
.channel_count = 3,
.channels = people_count_sensor_channels,
};
/* ... ... other codes ... ... */
static struct bt_mesh_sensor icm20948_sensor_accel = { // 人数传感器定义
.type = &icm20948_sensor_type_accel, // 自定义sensor_type类型
.get = icm20948_data_get,
};
static struct bt_mesh_sensor icm20948_sensor_gyro = { // 人数传感器定义
.type = &icm20948_sensor_type_gyro, // 自定义sensor_type类型
.get = icm20948_data_get,
};
static struct bt_mesh_sensor icm20948_sensor_mag = { // 人数传感器定义
.type = &icm20948_sensor_type_mag, // 自定义sensor_type类型
.get = icm20948_data_get,
};
static struct bt_mesh_sensor *const people_count_sensor_data[] = {
&icm20948_sensor_accel,
&icm20948_sensor_gyro,
&icm20948_sensor_mag,
}; // icm20948传感器传输数据指针定义,包含了三个自定义的传感器实例
static struct bt_mesh_sensor_srv people_count_sensor_srv =
BT_MESH_SENSOR_SRV_INIT(people_count_sensor_data, ARRAY_SIZE(people_count_sensor_data)); // 人数传感器服务器定义与初始化
static struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(1,
BT_MESH_MODEL_LIST(BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_HEALTH_SRV(&health_srv,
&health_pub),
BT_MESH_MODEL_SENSOR_SRV(&people_count_sensor_srv)),
BT_MESH_MODEL_NONE),
};
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:
/* ... ... */
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;
}
/* ... ... */
and the sensor_cli_data_cb() function like this:
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));
}
}
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.