- server文件结构:
使用SEGGER编译的话直接打开.emProject文件即可;img文件中包含程序运行过程图;include文件包含该例程下的头文件;
2. 具体操作:
在main.cpp文件中#define ONOFF_SERVER_0_LED (BSP_LED_0)下添加如下代码,前项声明另外一个元素用于控制开发板中第二个led灯
#define ONOFF_SERVER_1_LED (BSP_LED_1) //led灯
#define APP_ONOFF_ELEMENT_INDEX1 (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)//开关灯服务的前项声明
/* Callback for updating the hardware state */
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);
}
在nrf_mesh_config_app.h文件中修改 ACCESS_MODEL_COUNT 和ACCESS_ELEMENT_COUNT宏参数数目
#define ACCESS_MODEL_COUNT (4)
#define ACCESS_ELEMENT_COUNT (2)
3. 程序下载到板子中后在手机中使用nRF Mesh app配置node即可,便可发现多了有个元素
最后Mesh开发学习推荐SIG官方提供的Mesh开发学习指导v2.0 。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)