Hi all,
Currently our team is trying to implement a bluetooth mesh sensor network. We have started testing and experimenting with the mesh interface by trying to follow the nrf mesh sensor server sample, however after changing the model_handler.c code so that there is a dummy value displayed when get is called on the nrf mesh app, our device only goes into a hard fault (see debug output below). Is there a step that has been missed in initialising the mesh model ?
- Operating System Used: Windows 11
- nrfConnect for VsCode
- SDK version = v2.6.1
Desired | Actual |
1. Mesh Sensor Advertise and provision through mobile app | 1. Mesh Sensor Advertise and provision through mobile app |
2. Bind Application Key to health server, sensor configuration and sensor server nrf Mesh App | 2. Bind Application Key to health server, sensor configuration and sensor server nrf Mesh App |
3. Press Get Value and Receive the People Count as Value 1 | 3. Press Get Value, never finishes reading, device goes into hardfault and restarts |
New Model_Handler.c
/* * Copyright (c) 2020 Nordic Semiconductor ASA * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <zephyr/bluetooth/bluetooth.h> #include <zephyr/drivers/sensor.h> #include <bluetooth/mesh/models.h> #include <bluetooth/mesh/sensor_types.h> #include <dk_buttons_and_leds.h> #include <float.h> #include "model_handler.h" //LOG_MODULE_REGISTER(UARTBTLEDEMO,LOG_LEVEL_DBG); /* * Copyright (c) 2020 Nordic Semiconductor ASA * * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <zephyr/bluetooth/bluetooth.h> #include <zephyr/drivers/sensor.h> #include <bluetooth/mesh/models.h> #include <bluetooth/mesh/sensor_types.h> #include <dk_buttons_and_leds.h> #include <float.h> #include "bluetooth/mesh/sensor.h" #include "model_handler.h" //LOG_MODULE_REGISTER(UARTBTLEDEMO,LOG_LEVEL_DBG); static int bt_mesh_parking_occupancy_sensor_get(struct bt_mesh_sensor_srv *srv,struct bt_mesh_sensor *sensor, struct bt_mesh_sensor_setting *setting, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_sensor_value *value){ int err; struct sensor_value val = { .val1 = 1, }; printk("Parking Occupancy Sensor Get\n"); return bt_mesh_sensor_value_from_sensor_value(sensor->type->channels[0].format, &val, value); } /* Create Mesh Sensor Models*/ //Parking Occupancy// static struct bt_mesh_sensor bt_mesh_parking_occupancy_sensor = { .type = &bt_mesh_sensor_people_count, .get = bt_mesh_parking_occupancy_sensor_get, }; static bool attention; static struct bt_mesh_sensor *const occupancy_sensor[] = { &bt_mesh_parking_occupancy_sensor, }; static struct bt_mesh_sensor_srv occupancy_sensor_srv = BT_MESH_SENSOR_SRV_INIT(occupancy_sensor, ARRAY_SIZE(occupancy_sensor)); /* static struct bt_mesh_sensor_setting bt_mesh_parking_occupancy_sensor_setting[] = {{ .type = &bt_mesh_parking_occupancy_sensor, .get = , .set = , }}; Left for future implementation */ static void attention_on(struct bt_mesh_model *mod) { attention = true; } static void attention_off(struct bt_mesh_model *mod) { /* Will stop rescheduling blink timer */ attention = false; } /*Adjust For Our Sensors*/ static const struct bt_mesh_health_srv_cb health_srv_cb = { .attn_on = attention_on, .attn_off = attention_off, }; static struct bt_mesh_health_srv health_srv = { .cb = &health_srv_cb, }; BT_MESH_HEALTH_PUB_DEFINE(health_pub, 0); /*Elements*/ /* - Element1: --> Health Server --> Configuration Server - Element2: --> Sensor Server (Parking Occupancy) --> Sensor Setup Server */ 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_NONE), BT_MESH_ELEM(2,BT_MESH_MODEL_LIST(BT_MESH_MODEL_SENSOR_SRV(&occupancy_sensor_srv)),BT_MESH_MODEL_NONE), //BT_MESH_ELEM(3,BT_MESH_MODEL_LIST(BT_MESH_MODEL_SENSOR_SRV(&traffic_congestion_sensor_srv)),BT_MESH_MODEL_NONE), }; static const struct bt_mesh_comp comp = { .cid = CONFIG_BT_COMPANY_ID, .elem = elements, .elem_count = ARRAY_SIZE(elements), }; //Adjust based on model parameters const struct bt_mesh_comp *model_handler_init(void) { int err; return ∁ }
Output When Calling Get on Mesh App:
*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***g system Initializing... [00:00:00.007,171] <inf> fs_nvs: 8 Sectors of 4096 bytes [00:00:00.007,202] <inf> fs_nvs: alloc wra: 0, ee0 [00:00:00.007,202] <inf> fs_nvs: data wra: 0, 168 [00:00:00.007,385] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 36 f0 e5 0e 87 68 48 fb 02 fd 9f 82 cc 32 e5 7b |6....hH. .....2.{ 91 b1 5c ed |..\. [00:00:00.011,077] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002) [00:00:00.011,108] <inf> bt_hci_core: HW Variant: nRF52x (0x0002) [00:00:00.011,138] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870 [00:00:00.011,596] <inf> bt_hci_core: No ID address. App must call settings_load() Bluetooth initialized [00:00:00.011,779] <wrn> bt_mesh_access: Unused space in relation list: 4 [00:00:00.282,958] <inf> bt_hci_core: Identity: C1:02:A8:C6:5C:8C (random) [00:00:00.282,989] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059 [00:00:00.283,020] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x118f Mesh initialized Parking Occupancy Sensor Get [00:00:02.569,152] <err> os: ***** BUS FAULT ***** [00:00:02.569,152] <err> os: Instruction bus error [00:00:02.569,183] <err> os: r0/a1: 0x20000b94 r1/a2: 0x20000b8c r2/a3: 0x00000000 [00:00:02.569,213] <err> os: r3/a4: 0x61000000 r12/ip: 0x00000000 r14/lr: 0x0004a27f [00:00:02.569,213] <err> os: xpsr: 0x60000000 [00:00:02.569,244] <err> os: s[ 0]: 0x00000000 s[ 1]: 0x20000b58 s[ 2]: 0x20009ab0 s[ 3]: 0x20009cd4 [00:00:02.569,244] <err> os: s[ 4]: 0x00000000 s[ 5]: 0x00039403 s[ 6]: 0x20000408 s[ 7]: 0x20000b58 [00:00:02.569,274] <err> os: s[ 8]: 0x20009afc s[ 9]: 0x20000b58 s[10]: 0x20000408 s[11]: 0x00039883 [00:00:02.569,305] <err> os: s[12]: 0x2000efa4 s[13]: 0x00045a81 s[14]: 0x00000000 s[15]: 0x00000000 [00:00:02.569,305] <err> os: fpscr: 0x00000000 [00:00:02.569,335] <err> os: Faulting instruction address (r15/pc): 0x61000000 [00:00:02.569,366] <err> os: >>> ZEPHYR FATAL ERROR 27: Unknown error on CPU 0 [00:00:02.569,396] <err> os: Current thread: 0x200032c8 (unknown) *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***g system Initializing... [00:00:00.007,171] <inf> fs_nvs: 8 Sectors of 4096 bytes [00:00:00.007,171] <inf> fs_nvs: alloc wra: 0, ed0 [00:00:00.007,202] <inf> fs_nvs: data wra: 0, 188 [00:00:00.007,385] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 36 f0 e5 0e 87 68 48 fb 02 fd 9f 82 cc 32 e5 7b |6....hH. .....2.{ 91 b1 5c ed |..\. [00:00:00.011,077] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002) [00:00:00.011,108] <inf> bt_hci_core: HW Variant: nRF52x (0x0002) [00:00:00.011,138] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870 [00:00:00.011,596] <inf> bt_hci_core: No ID address. App must call settings_load() Bluetooth initialized [00:00:00.011,779] <wrn> bt_mesh_access: Unused space in relation list: 4 [00:00:00.283,416] <inf> bt_hci_core: Identity: C1:02:A8:C6:5C:8C (random) [00:00:00.283,447] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059 [00:00:00.283,477] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x118f Mesh initialized Parking Occupancy Sensor Get [00:00:07.016,754] <err> os: ***** BUS FAULT ***** [00:00:07.016,784] <err> os: Instruction bus error [00:00:07.016,815] <err> os: r0/a1: 0x20000b94 r1/a2: 0x20000b8c r2/a3: 0x00000000 [00:00:07.016,815] <err> os: r3/a4: 0x61000000 r12/ip: 0x00000000 r14/lr: 0x0004a27f [00:00:07.016,845] <err> os: xpsr: 0x60000000 [00:00:07.016,845] <err> os: s[ 0]: 0x00000000 s[ 1]: 0x20000b58 s[ 2]: 0x20009ab0 s[ 3]: 0x20009cd4 [00:00:07.016,876] <err> os: s[ 4]: 0x00000000 s[ 5]: 0x00039403 s[ 6]: 0x20000408 s[ 7]: 0x20000b58 [00:00:07.016,876] <err> os: s[ 8]: 0x20009afc s[ 9]: 0x20000b58 s[10]: 0x20000408 s[11]: 0x00039883 [00:00:07.016,906] <err> os: s[12]: 0x2000efa4 s[13]: 0x00045a81 s[14]: 0x00000000 s[15]: 0x00000000 [00:00:07.016,937] <err> os: fpscr: 0x00000000 [00:00:07.016,937] <err> os: Faulting instruction address (r15/pc): 0x61000000 [00:00:07.016,998] <err> os: >>> ZEPHYR FATAL ERROR 27: Unknown error on CPU 0 [00:00:07.017,028] <err> os: Current thread: 0x200032c8 (unknown) *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***g system Initializing... [00:00:00.007,110] <inf> fs_nvs: 8 Sectors of 4096 bytes [00:00:00.007,141] <inf> fs_nvs: alloc wra: 0, ec0 [00:00:00.007,141] <inf> fs_nvs: data wra: 0, 1a8 [00:00:00.007,324] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision: 36 f0 e5 0e 87 68 48 fb 02 fd 9f 82 cc 32 e5 7b |6....hH. .....2.{ 91 b1 5c ed |..\. [00:00:00.011,016] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002) [00:00:00.011,047] <inf> bt_hci_core: HW Variant: nRF52x (0x0002) [00:00:00.011,077] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870 [00:00:00.011,535] <inf> bt_hci_core: No ID address. App must call settings_load() Bluetooth initialized [00:00:00.011,718] <wrn> bt_mesh_access: Unused space in relation list: 4 [00:00:00.283,569] <inf> bt_hci_core: Identity: C1:02:A8:C6:5C:8C (random) [00:00:00.283,599] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059 [00:00:00.283,630] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x118f Mesh initialized