blob: 1017e3184d93f012561ba5dc8076a08fba459bbd [file] [log] [blame]
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/sys/printk.h>
#include <stdlib.h>
#include <zephyr/zephyr.h>
#include <zephyr/shell/shell.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/mesh.h>
#include <zephyr/bluetooth/mesh/shell.h>
static struct bt_mesh_cfg_cli cfg_cli;
BT_MESH_SHELL_HEALTH_PUB_DEFINE(health_pub);
static struct bt_mesh_model root_models[] = {
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
BT_MESH_MODEL_HEALTH_SRV(&bt_mesh_shell_health_srv, &health_pub),
BT_MESH_MODEL_HEALTH_CLI(&bt_mesh_shell_health_cli),
};
static struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(0, root_models, BT_MESH_MODEL_NONE),
};
static const struct bt_mesh_comp comp = {
.cid = CONFIG_BT_COMPANY_ID,
.elem = elements,
.elem_count = ARRAY_SIZE(elements),
};
static void bt_ready(int err)
{
if (err && err != -EALREADY) {
printk("Bluetooth init failed (err %d)\n", err);
return;
}
printk("Bluetooth initialized\n");
err = bt_mesh_init(&bt_mesh_shell_prov, &comp);
if (err) {
printk("Initializing mesh failed (err %d)\n", err);
return;
}
if (IS_ENABLED(CONFIG_SETTINGS)) {
settings_load();
}
printk("Mesh initialized\n");
if (bt_mesh_is_provisioned()) {
printk("Mesh network restored from flash\n");
} else {
printk("Use \"pb-adv on\" or \"pb-gatt on\" to "
"enable advertising\n");
}
}
void main(void)
{
int err;
printk("Initializing...\n");
/* Initialize the Bluetooth Subsystem */
err = bt_enable(bt_ready);
if (err && err != -EALREADY) {
printk("Bluetooth init failed (err %d)\n", err);
}
printk("Press the <Tab> button for supported commands.\n");
printk("Before any Mesh commands you must run \"mesh init\"\n");
}