Demo功能
1、基于我司的现场Nordic52840的PCBA构建的蓝牙mesh中所有节点为同一类型,任一节点都可以控制网络中所有设备
2、任一节点的加入及去除不影响整个网络的工作。
3、在节点中通过一个节点publish一个切换当前light状态的指令,当订阅的设备收到此信息后直接trigger一下light的状态
需要设备
1、需要5个我司的5个PCBA
2、需要手机按照mesh的APP后代配网用
实现方法
基于light_switch的example来实现,在client的demo中移植server部分的功能,并将server中light中的功能按照新的PCBA重新配置GPIO
同时需要注意原来demo中关于GPIO配置驱动有着局限性问题(只能配置为P0,且LED的多个GPIO需要是连续的,需要重新修改驱动)
具体步骤
(1)移植server部分代码
/* Generic OnOff server structure definition and initialization */
APP_ONOFF_SERVER_DEF(m_onoff_server_0,
APP_CONFIG_FORCE_SEGMENTATION,
APP_CONFIG_MIC_SIZE,
app_onoff_server_set_cb,
app_onoff_server_get_cb)
/* Callback for updating the hardware state */
static void app_onoff_server_set_cb(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(BSP_LED_GREEN, onoff);
LED_Toggle();
}
/* Callback for reading the hardware state */
static void app_onoff_server_get_cb(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(BSP_LED_GREEN);
}
static void models_init_cb(void)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
for (uint32_t i = 0; i < CLIENT_MODEL_INSTANCE_COUNT; ++i)
{
m_clients[i].settings.p_callbacks = &client_cbs;
m_clients[i].settings.timeout = 0;
m_clients[i].settings.force_segmented = APP_CONFIG_FORCE_SEGMENTATION;
m_clients[i].settings.transmic_size = APP_CONFIG_MIC_SIZE;
ERROR_CHECK(generic_onoff_client_init(&m_clients[i], i + 1));
}
app_model_init();
}
(2)手机配置过程
每个设备有三个,element包含client和server
client的配置如下,所有节点的client的publish的组地址定为0xc000
server的配置如下,所有节点的server的订阅的组地址client的publish地址一致,为0xC000
(3)功能测试
实现了预想功能,仍一节点按下按键后,剩余所有节点切换light开发状态