I am trying to create a custom mesh sensor-sever for my icm20948 sensor. Can I transfer 9 16-bit floating point data at a time and how?

I am trying to transferring 9 16-bit floating point data(acceleratometer, gyro, magnetometer * x, y, z) fetched from icm20948 sensor by BLE Mesh, using nrf54l15dk. I changed the sensor server struct based on the "sample/bluetooth/meth/sensor_server" sample. It gives 5 elements for 5 kinds of sensors, and I changed the bt_mesh_sensor_type "people count", by adding more bt_mesh_sensor_channel channels. Then I built it and flashed it to my nrf54l15dk and tried to fetch data on nrf mesh mobile app, then I got the kernel panic error.

My code:

static const struct bt_mesh_sensor_unit people_count_sensor_unit = {
	.name = "people_count_sensor_data",
	.symbol = "none",
};

static const struct bt_mesh_sensor_format people_count_sensor_format = {
	.size = 2,
	.unit = &people_count_sensor_unit,
};

static const struct bt_mesh_sensor_channel people_count_sensor_channels[] = { {
		.format = &people_count_sensor_format,
		.name = "channel_1",
	}, {
		.format = &people_count_sensor_format,
		.name = "channel_2",
	},
};

static const struct bt_mesh_sensor_type people_count_sensor_type_new = {
	.id = BT_MESH_PROP_ID_CUSTOM_ICM20948,
	.channel_count = 2,
	.channels = people_count_sensor_channels,
};

static const struct bt_mesh_sensor_value people_count_sensor_value_new = {
	.format = &people_count_sensor_format,
};

// 人数传感器数据获取函数
static int people_count_get(struct bt_mesh_sensor_srv *srv,
				 struct bt_mesh_sensor *sensor,
				 struct bt_mesh_msg_ctx *ctx,
				 struct bt_mesh_sensor_value *rsp)
{
	int err;
	err = bt_mesh_sensor_value_from_micro(sensor->type->channels[0].format, BASE_UNITS_TO_MICRO(dummy_people_count_value_1), &rsp[0]);
	err = bt_mesh_sensor_value_from_micro(sensor->type->channels[1].format, BASE_UNITS_TO_MICRO(dummy_people_count_value_2), &rsp[1]);
	// 将虚拟数据dummy(整数)转换为sensor_value结构体
	if (err && err != -ERANGE) {
		printk("Error encoding people count (%d)", err);
		return err;
	}
	return 0;
};

static struct bt_mesh_sensor people_count_sensor = { // 人数传感器定义
	.type = &people_count_sensor_type_new, // 工具包自带人数传感器数据类型
	.get = people_count_get,
};

Error occurred:

<err> os: r0/a1:  0x00000004  r1/a2:  0x00000458  r2/a3:  0x20005ac0
[00:02:23.457,039] <err> os: r3/a4:  0x00000004 r12/ip:  0x20000e68 r14/lr:  0x0001c02b
[00:02:23.457,047] <err> os:  xpsr:  0x01100000
[00:02:23.457,055] <err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x0004000b
[00:02:23.457,064] <err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x0004c2e9  s[ 7]:  0x2000ab74
[00:02:23.457,073] <err> os: s[ 8]:  0x00000000  s[ 9]:  0x0003f3eb  s[10]:  0x0004c2e9  s[11]:  0x2000ab74
[00:02:23.457,081] <err> os: s[12]:  0x00000458  s[13]:  0x0001c021  s[14]:  0x0004c2e9  s[15]:  0x0004cca6
[00:02:23.457,087] <err> os: fpscr:  0x00000458
[00:02:23.457,092] <err> os: Faulting instruction address (r15/pc): 0x0003f3d8
[00:02:23.457,124] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:02:23.457,140] <err> os: Current thread: 0x20005ac0 (unknown)
*** Booting Mesh Sensor v2.9.0-687260cfb136 *** system

In the code I shown above I simply add one more channel in bt_mesh_sensor_channel structure. Can I transfer more data using this way? If not, what else method should I use?

Thank you!

Parents
  • Hi Li Boyan, 
    I don't fully understand your modification. Are you planning to put your data into people_count_sensor ? 
    9 16-bit data is 18 bytes. As you figured you can transfer that using 2 segmented messages. The process of segmenting long message into multiple segmented message is automatically done in the mesh stack. So you don't have to anything. 

    For debugging your issue I would suggest to take a look here  How to know which instruction is in a Faulting instruction address 

    You need to figure out what code is at 0x0003f3d8. 


  • thank you for your reply!

    I wondered whether I could create a custom sensor server struct (for icm20948 data sending) so I tried to put one more bt_mesh_sensor_channel struct in the people_count_sensor_channels to see if I can use this method to enlarge the payload of the people_count_sensor_server. It turned out that this didn't work.

    it seems that I need to use segmented message to send data, so can I find any samples of creating custom sensor model using segmented message?

    thanks!

  • Hi, 
    As I said you don't have to worry about segmented message as it's done automatically. Whenever the access layer see the message is longer than 11 bytes, it will segment the message into multiple segmented message. 
    Your job is to find where the assertion come and try to debug that. 

  • I see, thank you for your reply! I found that as long as I used my custom bt_mesh_sensor_type (instead of the given ones in sensor_types.h file), I had a kernel panic fault. Do you have any advice how to create a custom sensor server for sending 18-bytes-data?

    Thank you for your patience!

  • Hi Li, 
    It's important to know how to debug. Have you tried to follow the link I posted ?   How to know which instruction is in a Faulting instruction address You need to find which exact function causing the issue. 

    My suggestion is to try modify one thing at a time, try to make small modification first to see if you have the issue. 

    In theory you can send whatever you want on Mesh. If you take a look at the mesh/chat  sample you can find that we make the chat client model with default max length of 90 bytes. 

    config BT_MESH_CHAT_CLI_MESSAGE_LENGTH
    	int "Max length of the message to be sent over mesh"
    	default 90
    	range 0 255
    	help
    	  Impacts on memory size occupied by the buffer of a message to be
    	  published. This does not include null terminator. The message must also
    	  fit into the application SDU. Adjust BT_MESH_TX_SEG_MAX and
    	  BT_MESH_RX_SEG_MAX to be able to receive the longest messages.
Reply
  • Hi Li, 
    It's important to know how to debug. Have you tried to follow the link I posted ?   How to know which instruction is in a Faulting instruction address You need to find which exact function causing the issue. 

    My suggestion is to try modify one thing at a time, try to make small modification first to see if you have the issue. 

    In theory you can send whatever you want on Mesh. If you take a look at the mesh/chat  sample you can find that we make the chat client model with default max length of 90 bytes. 

    config BT_MESH_CHAT_CLI_MESSAGE_LENGTH
    	int "Max length of the message to be sent over mesh"
    	default 90
    	range 0 255
    	help
    	  Impacts on memory size occupied by the buffer of a message to be
    	  published. This does not include null terminator. The message must also
    	  fit into the application SDU. Adjust BT_MESH_TX_SEG_MAX and
    	  BT_MESH_RX_SEG_MAX to be able to receive the longest messages.
Children
Related