- 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 。