Core API

The Bluetooth Mesh Core API provides functionality for managing the general Bluetooth Mesh state.

Low Power Node

The Low Power Node (LPN) role allows battery powered devices to participate in a mesh network as a leaf node. An LPN interacts with the mesh network through a Friend node, which is responsible for relaying any messages directed to the LPN. The LPN saves power by keeping its radio turned off, and only wakes up to either send messages or poll the Friend node for any incoming messages.

The radio control and polling is managed automatically by the mesh stack, but the LPN API allows the application to trigger the polling at any time through bt_mesh_lpn_poll(). The LPN operation parameters, including poll interval, poll event timing and Friend requirements is controlled through the CONFIG_BT_MESH_LOW_POWER option and related configuration options.

API reference

group bt_mesh

Bluetooth Mesh.

Defines

BT_MESH_NET_PRIMARY
BT_MESH_FEAT_RELAY

Relay feature

BT_MESH_FEAT_PROXY

GATT Proxy feature

BT_MESH_FEAT_FRIEND

Friend feature

BT_MESH_FEAT_LOW_POWER

Low Power Node feature

BT_MESH_FEAT_SUPPORTED
BT_MESH_LPN_CB_DEFINE(_name)

Register a callback structure for Friendship events.

Parameters
  • _name: Name of callback structure.

BT_MESH_FRIEND_CB_DEFINE(_name)

Register a callback structure for Friendship events.

Registers a callback structure that will be called whenever Friendship gets established or terminated.

Parameters
  • _name: Name of callback structure.

Functions

int bt_mesh_init(const struct bt_mesh_prov *prov, const struct bt_mesh_comp *comp)

Initialize Mesh support.

After calling this API, the node will not automatically advertise as unprovisioned, rather the bt_mesh_prov_enable() API needs to be called to enable unprovisioned advertising on one or more provisioning bearers.

Return

Zero on success or (negative) error code otherwise.

Parameters
  • prov: Node provisioning information.

  • comp: Node Composition.

void bt_mesh_reset(void)

Reset the state of the local Mesh node.

Resets the state of the node, which means that it needs to be reprovisioned to become an active node in a Mesh network again.

After calling this API, the node will not automatically advertise as unprovisioned, rather the bt_mesh_prov_enable() API needs to be called to enable unprovisioned advertising on one or more provisioning bearers.

int bt_mesh_suspend(void)

Suspend the Mesh network temporarily.

This API can be used for power saving purposes, but the user should be aware that leaving the local node suspended for a long period of time may cause it to become permanently disconnected from the Mesh network. If at all possible, the Friendship feature should be used instead, to make the node into a Low Power Node.

Return

0 on success, or (negative) error code on failure.

int bt_mesh_resume(void)

Resume a suspended Mesh network.

This API resumes the local node, after it has been suspended using the bt_mesh_suspend() API.

Return

0 on success, or (negative) error code on failure.

void bt_mesh_iv_update_test(bool enable)

Toggle the IV Update test mode.

This API is only available if the IV Update test mode has been enabled in Kconfig. It is needed for passing most of the IV Update qualification test cases.

Parameters
  • enable: true to enable IV Update test mode, false to disable it.

bool bt_mesh_iv_update(void)

Toggle the IV Update state.

This API is only available if the IV Update test mode has been enabled in Kconfig. It is needed for passing most of the IV Update qualification test cases.

Return

true if IV Update In Progress state was entered, false otherwise.

int bt_mesh_lpn_set(bool enable)

Toggle the Low Power feature of the local device.

Enables or disables the Low Power feature of the local device. This is exposed as a run-time feature, since the device might want to change this e.g. based on being plugged into a stable power source or running from a battery power source.

Return

Zero on success or (negative) error code otherwise.

Parameters
  • enable: true to enable LPN functionality, false to disable it.

int bt_mesh_lpn_poll(void)

Send out a Friend Poll message.

Send a Friend Poll message to the Friend of this node. If there is no established Friendship the function will return an error.

Return

Zero on success or (negative) error code otherwise.

int bt_mesh_friend_terminate(uint16_t lpn_addr)

Terminate Friendship.

Terminated Friendship for given LPN.

Return

Zero on success or (negative) error code otherwise.

Parameters
  • lpn_addr: Low Power Node address.

struct bt_mesh_lpn_cb
#include <main.h>

Low Power Node callback functions.

Public Members

void (*established)(uint16_t net_idx, uint16_t friend_addr, uint8_t queue_size, uint8_t recv_window)

Friendship established.

This callback notifies the application that friendship has been successfully established.

Parameters
  • net_idx: NetKeyIndex used during friendship establishment.

  • friend_addr: Friend address.

  • queue_size: Friend queue size.

  • recv_window: Low Power Node’s listens duration for Friend response.

void (*terminated)(uint16_t net_idx, uint16_t friend_addr)

Friendship terminated.

This callback notifies the application that friendship has been terminated.

Parameters
  • net_idx: NetKeyIndex used during friendship establishment.

  • friend_addr: Friend address.

void (*polled)(uint16_t net_idx, uint16_t friend_addr, bool retry)

Local Poll Request.

This callback notifies the application that the local node has polled the friend node.

This callback will be called before bt_mesh_lpn_cb::established when attempting to establish a friendship.

Parameters
  • net_idx: NetKeyIndex used during friendship establishment.

  • friend_addr: Friend address.

  • retry: Retry or first poll request for each transaction.

struct bt_mesh_friend_cb
#include <main.h>

Friend Node callback functions.

Public Members

void (*established)(uint16_t net_idx, uint16_t lpn_addr, uint8_t recv_delay, uint32_t polltimeout)

Friendship established.

This callback notifies the application that friendship has been successfully established.

Parameters
  • net_idx: NetKeyIndex used during friendship establishment.

  • lpn_addr: Low Power Node address.

  • recv_delay: Receive Delay in units of 1 millisecond.

  • polltimeout: PollTimeout in units of 1 millisecond.

void (*terminated)(uint16_t net_idx, uint16_t lpn_addr)

Friendship terminated.

This callback notifies the application that friendship has been terminated.

Parameters
  • net_idx: NetKeyIndex used during friendship establishment.

  • lpn_addr: Low Power Node address.