最近学习Mesh组网,基于SDK15.3。
在跑通例程后,想在server上多添加一个 Generic OnOff Model,于是添加以下代码。

#define ONOFF_SERVER_1_LED          (BSP_LED_1)
static void app_onoff_server_set_cb1(const app_onoff_server_t * p_server, bool onoff);
static void app_onoff_server_get_cb1(const app_onoff_server_t * p_server, bool * p_present_onoff);

APP_ONOFF_SERVER_DEF(m_onoff_server_1,
                     APP_CONFIG_FORCE_SEGMENTATION,
                     APP_CONFIG_MIC_SIZE,
                     app_onoff_server_set_cb1,
                     app_onoff_server_get_cb1)
                     
static void app_onoff_server_set_cb1(const app_onoff_server_t * p_server, bool onoff)
{
    /* Resolve the server instance here if required, this example uses only 1 instance. */

    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setting GPIO value: %d\n", onoff)

    hal_led_pin_set(ONOFF_SERVER_1_LED, onoff);
}

/* Callback for reading the hardware state */
static void app_onoff_server_get_cb1(const app_onoff_server_t * p_server, bool * p_present_onoff)
{
    /* Resolve the server instance here if required, this example uses only 1 instance. */

    *p_present_onoff = hal_led_pin_get(ONOFF_SERVER_1_LED);
}

static void app_model_init(void)
{
    /* Instantiate onoff server on element index APP_ONOFF_ELEMENT_INDEX */
    ERROR_CHECK(app_onoff_init(&m_onoff_server_0, APP_ONOFF_ELEMENT_INDEX));
    ERROR_CHECK(app_onoff_init(&m_onoff_server_1, APP_ONOFF_ELEMENT_INDEX));
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "App OnOff Model Handle: %d\n", m_onoff_server_0.server.model_handle);
}

创建model后绑定在第一个element上,在nrf_mesh_config_app.h 里修改宏
#define ACCESS_MODEL_COUNT (4)
编译下载后出现错误

请问这样增加model有什么错误吗?

  • Wireless-Tech 找到原因了,是因为在设置了模型和元素之后没有设置ACCESS_SUBSCRIPTION_LIST_COUNT,导致内存报错,错误代码mesh error 4,在nrf_error.h中对应的NRF_ERROR_NO_MEM,只要把ACCESS_SUBSCRIPTION_LIST_COUNT改为2就可以了

A-Noob-Coder 将标题更改为 “关于在light_switch例程添加model的问题”。

    同一个元素不能同时存在两个相同的Model

    Wireless-Tech 了解,感谢👌

      2 年后

      Wireless-Tech

      你好,更换了element之后还是出现了错误,请问是哪里出现了问题

        WULAIDEHOUZI

        能否将返回值打印出来?新增了元素之后,能否全擦之后再尝试一下?

          Wireless-Tech 找到原因了,是因为在设置了模型和元素之后没有设置ACCESS_SUBSCRIPTION_LIST_COUNT,导致内存报错,错误代码mesh error 4,在nrf_error.h中对应的NRF_ERROR_NO_MEM,只要把ACCESS_SUBSCRIPTION_LIST_COUNT改为2就可以了

            撰写回复...