Bluetooth Mesh Light CTL (color tuned light) sample

Is there a sample app that uses the Zephyr Light CTL Bluetooth Mesh model?  I've tried to add that model to the light_ctrl sample app, but get a crash during configuration so I must be doing something wrong. 

The onoff_level_lighting_vnd app claims to support that model but it doesn't seem to be using the Zephyr lighting models. 

Thanks

Parents
  • Hi Jack, 
    I think you are right. There isn't a sample for that model right now. Please let us know the issue you are seeing we can try to take a look. 
    We have limited capacity in the holidays period but will be back to full staff by beginning of the year. 

  • Thanks, here goes.

    I started with the VSCode plugin light_ctrl sample using version 2.8.0 of the toolchain and libraries. Build machines with Windows and Linux tried.  Target is nRF52840DK. 

    The unmodified sample builds, runs, and provisions and functions correctly with the nRF Mesh Android app. 

    After the modifications below, the code compiles and runs, but during initialization I get an assert showing on the console (see below), and an "Initial Configuration Failed" message from the app.  

    Note that the assert states that temp srv wasn't properly initialized.  On debugging, however, it appeared that the tmp srv model was properly initialized and the light CTL model was not, however I have a low degree of confidence in this assessment. 

    model_handler.c was modified from the sample as follows:

    Add headers

    #include <bluetooth/mesh/light_ctrl_srv.h>
    #include <bluetooth/mesh/light_ctl_srv.h>

    Add placeholder handlers

    static void temp_srv_set(struct bt_mesh_light_temp_srv *srv,
                             struct bt_mesh_msg_ctx *ctx,
                             const struct bt_mesh_light_temp_set *set,
                             struct bt_mesh_light_temp_status *status)
    {
        // Implement setting the temperature on your hardware
    }

    static void temp_srv_get(struct bt_mesh_light_temp_srv *srv,
                             struct bt_mesh_msg_ctx *ctx,
                             struct bt_mesh_light_temp_status *status)
    {
        // Implement reading the current temperature state from your hardware
    }

    static const struct bt_mesh_light_temp_srv_handlers temp_srv_handlers = {
        .set = temp_srv_set,
        .get = temp_srv_get,
    };

    static struct bt_mesh_light_temp_srv light_temp_srv =
        BT_MESH_LIGHT_TEMP_SRV_INIT(&temp_srv_handlers);

    static struct bt_mesh_light_ctl_srv light_ctl_srv =

        BT_MESH_LIGHT_CTL_SRV_INIT(&lightness_srv_handlers, &temp_srv_handlers);

    Add light ctl and light temp srv models:

    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_LIGHTNESS_SRV(&my_ctx.lightness_srv),
                         BT_MESH_MODEL_SCENE_SRV(&scene_srv),
                         BT_MESH_MODEL_SENSOR_SRV(&sensor_srv),
                         BT_MESH_MODEL_LIGHT_CTL_SRV(&light_ctl_srv)
                                        ),
                     BT_MESH_MODEL_NONE),
        BT_MESH_ELEM(2,
                     BT_MESH_MODEL_LIST(
                         BT_MESH_MODEL_LIGHT_TEMP_SRV(&light_ctl_srv.temp_srv)
                     ),
                     BT_MESH_MODEL_NONE),
        BT_MESH_ELEM(3,
                     BT_MESH_MODEL_LIST(
                         BT_MESH_MODEL_LIGHT_CTRL_SRV(&light_ctrl_srv)
                                       ),
                    BT_MESH_MODEL_NONE)
    };

    prj.conf changes


    CONFIG_BT_MESH_MODEL_EXTENSION_LIST_SIZE=33

    CONFIG_BT_MESH_LIGHT_CTL_SRV=y

    CONFIG_CORTEX_M_DEBUG_MONITOR_HOOK=y

    CONFIG_SEGGER_DEBUGMON=y

    Console output:

    *** Booting Mesh Light Fixture v2.8.0-c57f55d0686e ***
    *** Using nRF Connect SDK v2.8.0-a2386bfc8401 ***
    *** Using Zephyr OS v3.7.99-0bc3393fb112 ***
    Initializing...
    [00:00:00.008,941] <inf> fs_nvs: 8 Sectors of 4096 bytes
    [00:00:00.008,972] <inf> fs_nvs: alloc wra: 0, fb0
    [00:00:00.008,972] <inf> fs_nvs: data wra: 0, 44
    [00:00:00.009,124] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision:
    fe 2c f9 6a 7f 36 22 2e a0 79 c0 40 be 2c 03 20 |.,.j.6". .y.@.,.
    40 c2 f3 32 |@..2
    [00:00:00.013,305] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.013,336] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:00.013,366] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 254.63788 Build 573996906
    [00:00:00.013,763] <inf> bt_hci_core: No ID address. App must call settings_load()
    Bluetooth initialized
    [00:00:00.439,453] <inf> bt_hci_core: Identity: EC:2C:E8:3F:5C:0E (random)
    [00:00:00.439,514] <inf> bt_hci_core: HCI: version 6.0 (0x0e) revision 0x104e, manufacturer 0x0059
    [00:00:00.439,544] <inf> bt_hci_core: LMP: version 6.0 (0x0e) subver 0x104e
    [00:00:00.442,474] <inf> bt_mesh_provisionee: Device UUID: 5c0b7b01-159d-4da6-a3f4-84feea62c259
    Mesh initialized
    Successfully enabled LC server
    [00:02:35.433,380] <inf> bt_mesh_main: Primary Element: 0x0020
    New light transition-> Lvl: 0, Time: 0, Delay: 0
    [00:02:35.443,359] <err> bt_mesh_light_ctl_srv: Light CTL srv[32]: Temp. srv not properly initialized
    ASSERTION FAIL @ WEST_TOPDIR/zephyr/kernel/work.c:687
    [00:02:35.443,878] <err> os: r0/a1: 0x00000004 r1/a2: 0x000002af r2/a3: 0x00000003
    [00:02:35.443,908] <err> os: r3/a4: 0x00000004 r12/ip: 0x0001b4a4 r14/lr: 0x0004443b
    [00:02:35.443,908] <err> os: xpsr: 0x01000000
    [00:02:35.443,939] <err> os: s[ 0]: 0x00000000 s[ 1]: 0x0004c9d3 s[ 2]: 0x00000000 s[ 3]: 0x00000000
    [00:02:35.443,969] <err> os: s[ 4]: 0x0005e348 s[ 5]: 0x2000dd34 s[ 6]: 0x00000000 s[ 7]: 0x0004bc3d
    [00:02:35.443,969] <err> os: s[ 8]: 0x20006ea8 s[ 9]: 0x0004bc7f s[10]: 0xffffffff s[11]: 0x2000dd34
    [00:02:35.444,030] <err> os: s[12]: 0x00000000 s[13]: 0x00044431 s[14]: 0x0005e348 s[15]: 0x00066cdc
    [00:02:35.444,030] <err> os: fpscr: 0x000002af
    [00:02:35.444,030] <err> os: Faulting instruction address (r15/pc): 0x0004bc6a
    [00:02:35.444,091] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
    [00:02:35.444,122] <err> os: Current thread: 0x20006ea8 (sysworkq)
    [00:00:00.000,427] <err> qspi_nor: JEDEC id [ff ff ff] expect [c2 28 17]

  • I don't see the problem with the default sample app light control.

  • I see.

    Could you try debugging and figure out where it fails, and exactly what is returning  bt_mesh_adv_ext: Advertising failed: err -12?

    Regards,

    Elfving

  • Call stack when the error occurs:

    [The error occurs due to a message received at this level.  The debugger didn't help me trace it further] 

    bt_hci_cmd_send_sync(uint16_t opcode, struct net_buf * buf, struct net_buf ** rsp) (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/host/hci_core.c:440)
    bt_le_adv_set_enable_ext(struct bt_le_ext_adv * adv, _Bool enable, const struct bt_le_ext_adv_start_param * param) (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/host/adv.c:371)
    [this is where the error is printed]
    bt_le_ext_adv_start(struct bt_le_ext_adv * adv, const struct bt_le_ext_adv_start_param * param) (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/host/adv.c:1656)
    adv_start(struct bt_mesh_ext_adv * ext_adv, const struct bt_le_adv_param * param, struct bt_le_ext_adv_start_param * start, const struct bt_data * ad, size_t ad_len, const struct bt_data * sd, size_t sd_len) (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/mesh/adv_ext.c:203)
    bt_mesh_adv_gatt_start(const struct bt_le_adv_param * param, int32_t duration, const struct bt_data * ad, size_t ad_len, const struct bt_data * sd, size_t sd_len) (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/mesh/adv_ext.c:603)
    bt_mesh_pb_gatt_srv_adv_start() (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/mesh/pb_gatt_srv.c:308)
    bt_mesh_adv_gatt_send() (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/mesh/adv.c:301)
    send_pending_adv(struct k_work * work) (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/mesh/adv_ext.c:359)
    work_queue_main(void * workq_ptr, void * p2, void * p3) (/home/user/ncs/v2.8.0/zephyr/kernel/work.c:688)
    z_thread_entry(k_thread_entry_t entry, void * p1, void * p2, void * p3) (/home/user/ncs/v2.8.0/zephyr/lib/os/thread_entry.c:48)
    z_thread_entry(k_thread_entry_t entry, void * p1, void * p2, void * p3) (/home/user/ncs/v2.8.0/zephyr/lib/os/thread_entry.c:48)
    [Unknown code] (Unknown Source:0)



    The error seems to arise here:
    In bt_hci_cmd_send_sync()
    (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/host/hci_core.c:440)

    ...

    case BT_HCI_ERR_INSUFFICIENT_RESOURCES:
    return -ENOMEM; (-12)

    When there a command
    This error code gets returned back up the chain to:

    In bt_le_ext_adv_start()
    (/home/user/ncs/v2.8.0/zephyr/subsys/bluetooth/host/adv.c:1657)
    The error is printed:
    ...
    err = bt_le_adv_set_enable_ext(adv, true, param);
    if (err) {
    LOG_ERR("Failed to start advertiser");
    if (IS_ENABLED(CONFIG_BT_PERIPHERAL) && conn) {
    bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
    bt_conn_unref(conn);
    }

    return err;
    }

    I guess it's something down in the Bluetooth controller.

    I tried to turn on some logging and am getting

    [00:08:20.424,499] <wrn> bt_hci_core: opcode 0x2039 status 0x0d
    [00:08:20.424,560] <err> bt_adv: Failed to start advertiser
    [00:08:20.424,591] <err> bt_mesh_adv_ext: Advertising failed: err -12

    I think status 0x0d is BT_HCI_ERR_INSUFFICIENT_RESOURCES above, so that's at least consistent.
  • Could you send me the .config file you get generated for the build?

    Regards,

    Elfving

  • By the way, I previously said the error wasn't catastrophic, however, today when I try the issue again, it does sometimes crash after several seconds.

    There was one .config in project\build\zephyr and one in project\build\project\, both are included.

    .config light_ctrl_sample-build-light_ctrl_sample-zephyr.zip

Reply Children
No Data
Related