这个页面的 最新开发版本 可能比这个发布的 2.3-beta.2 版本新。

访问层

访问层是应用程序与 Bluetooth Mesh 网络的接口。访问层提供了将节点行为划分为元素和模型的机制,这些元素和模型由应用程序实现。

mesh 模型

网格节点的功能由模型表示。模型实现节点支持的单个行为,如灯光、传感器或节温器。网格模型被分组为 元素 ,每个元素都是分配了自己的单播地址,并且只能包含每种类型的模型。 通常,每个元素表示网格的单个方面节点行为。例如,包含传感器、两个灯和电源插座将此功能扩展到四个元素,每个元素元素实例化的单个方面所需的所有模型支持的行为。

节点的元素和模型结构在节点组合数据中指定,该数据在初始化期间传递给 bt_mesh_init() 。蓝牙 SIG 定义了一组基础模型(请参见 Mesh 模型)以及一组用于实现公共中的行为 Bluetooth Mesh Model Specification ABluetooth SIG 未指定的所有型号都是供应商型号,并且必须绑定到公司 ID。

网格模型具有多个参数,可以通过网格堆栈的初始化或使用 配置服务器:

操作码列表

操作码列表包含模型可以接收的所有消息操作码,以及可接受的最小有效负载长度和将它们传递到的回调。模型可以支持任何数量的操作码,但每个操作码只能由每个元素中的一个模型列出。

完整的操作码列表必须传递给组合数据中的模型结构,并且不能在运行时更改。操作码列表的末尾由特殊的 BT_MESH_MODEL_OP_end 条目确定。此条目必须始终存在于操作码列表中,除非列表为空。在这种情况下,应使用 BT_MESH_MODEL_NO_OPS 来代替正确的操作码列表定义。

AppKey 列表

AppKey 列表包含模型可以接收的所有应用程序密钥上的消息。只有使用 AppKey 列表中的应用程序密钥加密的消息才会传递给模型。

每个型号可以持有的最大支持应用程序密钥数是通过 CONFIG_BT_MESH_model_KEY_COUNT 配置选项配置的。AppKey 列表的内容由管理 配置服务器.

订阅列表

模型将处理寻址到其元素的单播地址的所有消息(假定所使用的应用程序密钥存在于 AppKey 列表中)。此外,该模型将处理寻址到其订阅列表中的任何组或虚拟地址的数据包。这允许节点使用单个消息寻址整个网状网络中的多个节点。

每个型号可以容纳的订阅列表中支持的最大地址数是用 CONFIG_BT_MESH_model_GROUP_COUNT 配置的配置选项。订阅列表的内容由管理 配置服务器.

模型发布

模型可以通过两种方式发送信息:

  • 通过在 bt_mesh_msg_ctx 中指定一组消息参数,并调用 bt_mesh_model_send()

  • 通过设置 bt_mesh_model_pub 结构并调用 bt_mesh_model_publish()

使用 bt_mesh_model_publish() 发布消息时,模型将使用由配置的发布参数 配置服务器 。这是发送未经提示的模型消息的推荐方式,因为它将选择消息参数的责任传递给网络管理员,网络管理员可能比单个节点更了解网状网络。

为了使用发布参数支持发布,模型必须为发布分配数据包缓冲区,并将其传递给 bt_mesh_model_pub.msg 。配置服务器也可以设置周期发布消息的发布。 为了支持这一点,模型必须填充 bt_mesh_model_pub.update 回调。 bt_mesh_model_pub.update 回调将在 消息被发布,允许模型改变有效载荷以反映其当前状态。

通过将 bt_mesh_model_pub.retr_update 设置为1, 该模型可以配置每次重新传输时触发的 btmeshmodelpub.update 回调。 例如,这可以由以下模型使用: 使用Delay参数,该参数可以针对每次重新传输进行调整。 bt_mesh_model_pub_is_retransmission() 函数可以是用于区分首次发布和重新传输。 BT_MESH_PUB_MSG_OTALBT_MESCH_PUB_MSG_NUM 宏可用于返回一个发布间隔内的传输总数和重传次数。

扩展型号

Bluetooth Mesh 规范允许网格模型彼此扩展。当一个模型扩展另一个模型时,它继承该模型的功能, 并且扩展可以用于从简单的模型中构造复杂的模型,利用现有的模型功能来避免定义新的操作码。 模型可以从任何元素扩展任何数量的模型。当一个模型在同一个元素中扩展另一个模型时, 这两个模型将共享订阅列表。网格堆栈通过将两个模型的订阅列表合并为一个列表来实现这一点, 并结合模型可以拥有的订阅总数。模型可以扩展扩展其他模型的模型,从而创建“扩展树”。 扩展树中的所有模型都为其跨越的每个元素共享一个订阅列表。

模型扩展是通过在 bt_mesh_model_extend() 初始化, 一个模型只能由另一个模型扩展,并且扩展不能是循环的。请注意,节点状态的绑定以及模型之间的其他关系必须由模型实现来定义。

模型扩展概念在访问层数据包处理中增加了一些开销,并且必须显式启用 CONFIG_BT_MESH_MODEL_EEXTENSIONS 是否有任何效果。

模型数据存储

网格模型可能具有与需要持久存储的每个模型实例相关联的数据,访问 API 提供了一种利用内部模型实例编码方案存储该数据的机制。 模型可以通过调用 bt_mesh_model_data_store() 。 下次设备重新启动时能够读取数据, 必须填充模型的 btmeshmodelcb.settingsset 回调。 当在持久存储中找到模型特定的数据时, 将调用该回调。 模型可以通过调用传递为的 read_cb 来检索数据回调的参数。有关详细信息,请参阅 settings_api 模块文档。

当模型数据频繁更改时,在每次更改时存储它可能会导致闪存磨损增加。为了减少磨损, 模型可以通过调用 bt_mesh_model_data_store_schedule() 来延迟数据存储。 堆栈将使用由 CONFIG_BT_MESH_STORE_TIMEOUT 选择。工作项正在运行时, 堆栈将调用 btmeshmodelcb.pending_store 请求存储数据的每个模型的回调,然后,模型可以调用 bt_mesh_model_data_store() 来存储数据。

如果启用了 CONFIG_BT_MESH_SETTINGS_WORKQ ,回调这个 bt_mesh_model_cb.pending_store 从专用的线程。这允许堆栈处理其他传入和传出消息 存储模型数据时。当需要存储大量数据时,建议使用此选项和 bt_mesh_model_data_store_schedule() 函数。

组成数据

合成数据提供关于网格设备的信息。 设备的组成数据保存关于设备、它支持的型号和其他功能。组成 数据被拆分为不同的页面,其中每个页面包含特定的功能有关设备的信息。为了访问此信息,用户 可以使用 配置服务器 模型或 大型组合数据服务器 模型。

成分数据页0

成分数据页面 0 提供关于设备的基本信息,对于所有网状设备都是必需的。它包含图元和模型组成、支持的功能和制造商信息。

成分数据第1页

成分数据页面 1 提供关于模型之间关系的信息,对于所有网状设备都是必需的。 模型可以扩展和/或对应于一个或多个模型。 模型可以通过调用 bt_mesh_model_extend() 来扩展另一个模型, 或通过调用 bt_mesh_model_communicate() 来对应于另一个模型。 CONFIG_BT_MESH_MODEL_EXTENSION_LIST_SIZE 指定设备上的组合中可以存储多少模型关系, 并且该数字应该反映 bt_mesh_model_extend()bt_mesh_model() 对应调用的数量。

成分数据第2页

成分数据页面 2 提供支持的网格轮廓的信息。Mesh 配置文件规范定义了希望支持特定蓝牙 SIG 定义的配置文件的设备的产品要求。当前支持的配置文件可以在中的第3.12节中找到 Bluetooth SIG Assigned Numbers. 成分数据页面 2 仅对于声称支持一个或多个网格配置文件的设备是必需的。

成分数据第128、129和130页

合成数据页128、129和130分别镜像合成数据页0、1和2。当固件更新后合成数据将更改时,它们用于表示镜像页面的新内容。 请参见 合成数据和模型元数据 以了解详细信息。

延迟消息

可延迟消息功能通过 Kconfig 选项启用 CONFIG_BT_MESH_ACCESS_DELAYABLE_MSG 。 这是一种可选功能,用于实现模型在对接收到的消息(也称为响应消息)的响应中传输的消息的规范建议。

响应消息的发送应具有以下随机延迟:

  • 如果接收的消息被发送到单播地址,则介于20到50毫秒之间。

  • 如果发送了接收的消息,则介于20到500毫秒之间到组或虚拟地址。

如果设置了 bt_mesh_msg_ctx.rnd_delay 标志,则会触发可延迟消息功能。可延迟消息功能将消息存储在本地存储器中,同时等待随机延迟到期。

如果传输层没有足够的内存在随机延迟到期时发送消息,则消息将再延迟10毫秒。如果传输层由于任何其他原因无法发送消息,可延迟消息功能将引发带有传输层错误代码的 bt_mesh_send_cb.start 回调。

如果可延迟消息功能找不到足够的可用内存来存储传入消息,则它将以接近到期的延迟发送消息以释放内存。

挂起或重置网格堆栈时,将删除尚未发送的消息,并引发 bt_mesh_send_cb.start 回调,并返回错误代码。

可延迟发布

在以下情况下,可延迟发布功能实现消息发布延迟的规范建议:

  • Bluetooth Mesh 堆栈启动时或由 bt_Mesh_model_publish 函数触发发布时,介于20到500毫秒之间。

  • 对于定期发布的消息,介于20到50毫秒之间。

此功能是可选的,并通过 CONFIG_BT_MESH_DELAYABLE_PUBLICATION Kconfig 选项启用。启用后,每个模型都可以通过将 bt_mesh_model_pub.delayable 位字段相应地设置为 10 来启用或禁用可延迟发布,该位字段可以随时更改。

API 参考

group bt_mesh_access

Access layer.

Group addresses

BT_MESH_ADDR_UNASSIGNED

unassigned

BT_MESH_ADDR_ALL_NODES

all-nodes

BT_MESH_ADDR_RELAYS

all-relays

BT_MESH_ADDR_FRIENDS

all-friends

BT_MESH_ADDR_PROXIES

all-proxies

BT_MESH_ADDR_DFW_NODES

all-directed-forwarding-nodes

BT_MESH_ADDR_IP_NODES

all-ipt-nodes

BT_MESH_ADDR_IP_BR_ROUTERS

all-ipt-border-routers

Predefined key indexes

BT_MESH_KEY_UNUSED

Key unused

BT_MESH_KEY_ANY

Any key index

BT_MESH_KEY_DEV

Device key

BT_MESH_KEY_DEV_LOCAL

Local device key

BT_MESH_KEY_DEV_REMOTE

Remote device key

BT_MESH_KEY_DEV_ANY

Any device key

Foundation Models

BT_MESH_MODEL_ID_CFG_SRV

Configuration Server

BT_MESH_MODEL_ID_CFG_CLI

Configuration Client

BT_MESH_MODEL_ID_HEALTH_SRV

Health Server

BT_MESH_MODEL_ID_HEALTH_CLI

Health Client

BT_MESH_MODEL_ID_REMOTE_PROV_SRV

Remote Provisioning Server

BT_MESH_MODEL_ID_REMOTE_PROV_CLI

Remote Provisioning Client

BT_MESH_MODEL_ID_PRIV_BEACON_SRV

Private Beacon Server

BT_MESH_MODEL_ID_PRIV_BEACON_CLI

Private Beacon Client

BT_MESH_MODEL_ID_SAR_CFG_SRV

SAR Configuration Server

BT_MESH_MODEL_ID_SAR_CFG_CLI

SAR Configuration Client

BT_MESH_MODEL_ID_OP_AGG_SRV

Opcodes Aggregator Server

BT_MESH_MODEL_ID_OP_AGG_CLI

Opcodes Aggregator Client

BT_MESH_MODEL_ID_LARGE_COMP_DATA_SRV

Large Composition Data Server

BT_MESH_MODEL_ID_LARGE_COMP_DATA_CLI

Large Composition Data Client

BT_MESH_MODEL_ID_SOL_PDU_RPL_SRV

Solicitation PDU RPL Configuration Client

BT_MESH_MODEL_ID_SOL_PDU_RPL_CLI

Solicitation PDU RPL Configuration Server

BT_MESH_MODEL_ID_ON_DEMAND_PROXY_SRV

Private Proxy Server

BT_MESH_MODEL_ID_ON_DEMAND_PROXY_CLI

Private Proxy Client

Models from the Mesh Model Specification

BT_MESH_MODEL_ID_GEN_ONOFF_SRV

Generic OnOff Server

BT_MESH_MODEL_ID_GEN_ONOFF_CLI

Generic OnOff Client

BT_MESH_MODEL_ID_GEN_LEVEL_SRV

Generic Level Server

BT_MESH_MODEL_ID_GEN_LEVEL_CLI

Generic Level Client

BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV

Generic Default Transition Time Server

BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI

Generic Default Transition Time Client

BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV

Generic Power OnOff Server

BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV

Generic Power OnOff Setup Server

BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI

Generic Power OnOff Client

BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV

Generic Power Level Server

BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV

Generic Power Level Setup Server

BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI

Generic Power Level Client

BT_MESH_MODEL_ID_GEN_BATTERY_SRV

Generic Battery Server

BT_MESH_MODEL_ID_GEN_BATTERY_CLI

Generic Battery Client

BT_MESH_MODEL_ID_GEN_LOCATION_SRV

Generic Location Server

BT_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV

Generic Location Setup Server

BT_MESH_MODEL_ID_GEN_LOCATION_CLI

Generic Location Client

BT_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV

Generic Admin Property Server

BT_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV

Generic Manufacturer Property Server

BT_MESH_MODEL_ID_GEN_USER_PROP_SRV

Generic User Property Server

BT_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV

Generic Client Property Server

BT_MESH_MODEL_ID_GEN_PROP_CLI

Generic Property Client

BT_MESH_MODEL_ID_SENSOR_SRV

Sensor Server

BT_MESH_MODEL_ID_SENSOR_SETUP_SRV

Sensor Setup Server

BT_MESH_MODEL_ID_SENSOR_CLI

Sensor Client

BT_MESH_MODEL_ID_TIME_SRV

Time Server

BT_MESH_MODEL_ID_TIME_SETUP_SRV

Time Setup Server

BT_MESH_MODEL_ID_TIME_CLI

Time Client

BT_MESH_MODEL_ID_SCENE_SRV

Scene Server

BT_MESH_MODEL_ID_SCENE_SETUP_SRV

Scene Setup Server

BT_MESH_MODEL_ID_SCENE_CLI

Scene Client

BT_MESH_MODEL_ID_SCHEDULER_SRV

Scheduler Server

BT_MESH_MODEL_ID_SCHEDULER_SETUP_SRV

Scheduler Setup Server

BT_MESH_MODEL_ID_SCHEDULER_CLI

Scheduler Client

BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV

Light Lightness Server

BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV

Light Lightness Setup Server

BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI

Light Lightness Client

BT_MESH_MODEL_ID_LIGHT_CTL_SRV

Light CTL Server

BT_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV

Light CTL Setup Server

BT_MESH_MODEL_ID_LIGHT_CTL_CLI

Light CTL Client

BT_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV

Light CTL Temperature Server

BT_MESH_MODEL_ID_LIGHT_HSL_SRV

Light HSL Server

BT_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV

Light HSL Setup Server

BT_MESH_MODEL_ID_LIGHT_HSL_CLI

Light HSL Client

BT_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV

Light HSL Hue Server

BT_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV

Light HSL Saturation Server

BT_MESH_MODEL_ID_LIGHT_XYL_SRV

Light xyL Server

BT_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV

Light xyL Setup Server

BT_MESH_MODEL_ID_LIGHT_XYL_CLI

Light xyL Client

BT_MESH_MODEL_ID_LIGHT_LC_SRV

Light LC Server

BT_MESH_MODEL_ID_LIGHT_LC_SETUPSRV

Light LC Setup Server

BT_MESH_MODEL_ID_LIGHT_LC_CLI

Light LC Client

Models from the Mesh Binary Large Object Transfer Model Specification

BT_MESH_MODEL_ID_BLOB_SRV

BLOB Transfer Server

BT_MESH_MODEL_ID_BLOB_CLI

BLOB Transfer Client

Models from the Mesh Device Firmware Update Model Specification

BT_MESH_MODEL_ID_DFU_SRV

Firmware Update Server

BT_MESH_MODEL_ID_DFU_CLI

Firmware Update Client

BT_MESH_MODEL_ID_DFD_SRV

Firmware Distribution Server

BT_MESH_MODEL_ID_DFD_CLI

Firmware Distribution Client

Defines

BT_MESH_ADDR_IS_UNICAST(addr)

Check if a Bluetooth Mesh address is a unicast address.

BT_MESH_ADDR_IS_GROUP(addr)

Check if a Bluetooth Mesh address is a group address.

BT_MESH_ADDR_IS_FIXED_GROUP(addr)

Check if a Bluetooth Mesh address is a fixed group address.

BT_MESH_ADDR_IS_VIRTUAL(addr)

Check if a Bluetooth Mesh address is a virtual address.

BT_MESH_ADDR_IS_RFU(addr)

Check if a Bluetooth Mesh address is an RFU address.

BT_MESH_IS_DEV_KEY(key)

Check if a Bluetooth Mesh key is a device key.

BT_MESH_APP_SEG_SDU_MAX

Maximum size of an access message segment (in octets).

BT_MESH_APP_UNSEG_SDU_MAX

Maximum payload size of an unsegmented access message (in octets).

BT_MESH_RX_SEG_MAX

Maximum number of segments supported for incoming messages.

BT_MESH_TX_SEG_MAX

Maximum number of segments supported for outgoing messages.

BT_MESH_TX_SDU_MAX

Maximum possible payload size of an outgoing access message (in octets).

BT_MESH_RX_SDU_MAX

Maximum possible payload size of an incoming access message (in octets).

BT_MESH_ELEM(_loc, _mods, _vnd_mods)

Helper to define a mesh element within an array.

In case the element has no SIG or Vendor models the helper macro BT_MESH_MODEL_NONE can be given instead.

参数:
  • _loc – Location Descriptor.

  • _mods – Array of models.

  • _vnd_mods – Array of vendor models.

BT_MESH_MODEL_OP_1(b0)
BT_MESH_MODEL_OP_2(b0, b1)
BT_MESH_MODEL_OP_3(b0, cid)
BT_MESH_LEN_EXACT(len)

Macro for encoding exact message length for fixed-length messages.

BT_MESH_LEN_MIN(len)

Macro for encoding minimum message length for variable-length messages.

BT_MESH_MODEL_OP_END

End of the opcode list. Must always be present.

BT_MESH_MODEL_NO_OPS

Helper to define an empty opcode list.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

BT_MESH_MODEL_NONE

Helper to define an empty model array.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

BT_MESH_MODEL_CNT_CB(_id, _op, _pub, _user_data, _keys, _grps, _cb)

Composition data SIG model entry with callback functions with specific number of keys & groups.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

参数:
  • _id – Model ID.

  • _op – Array of model opcode handlers.

  • _pub – Model publish parameters.

  • _user_data – User data for the model.

  • _keys – Number of keys that can be bound to the model. Shall not exceed CONFIG_BT_MESH_MODEL_KEY_COUNT.

  • _grps – Number of addresses that the model can be subscribed to. Shall not exceed CONFIG_BT_MESH_MODEL_GROUP_COUNT.

  • _cb – Callback structure, or NULL to keep no callbacks.

BT_MESH_MODEL_CNT_VND_CB(_company, _id, _op, _pub, _user_data, _keys, _grps, _cb)

Composition data vendor model entry with callback functions with specific number of keys & groups.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

参数:
  • _company – Company ID.

  • _id – Model ID.

  • _op – Array of model opcode handlers.

  • _pub – Model publish parameters.

  • _user_data – User data for the model.

  • _keys – Number of keys that can be bound to the model. Shall not exceed CONFIG_BT_MESH_MODEL_KEY_COUNT.

  • _grps – Number of addresses that the model can be subscribed to. Shall not exceed CONFIG_BT_MESH_MODEL_GROUP_COUNT.

  • _cb – Callback structure, or NULL to keep no callbacks.

BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb)

Composition data SIG model entry with callback functions.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

参数:
  • _id – Model ID.

  • _op – Array of model opcode handlers.

  • _pub – Model publish parameters.

  • _user_data – User data for the model.

  • _cb – Callback structure, or NULL to keep no callbacks.

BT_MESH_MODEL_METADATA_CB(_id, _op, _pub, _user_data, _cb, _metadata)

Composition data SIG model entry with callback functions and metadata.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

参数:
  • _id – Model ID.

  • _op – Array of model opcode handlers.

  • _pub – Model publish parameters.

  • _user_data – User data for the model.

  • _cb – Callback structure, or NULL to keep no callbacks.

  • _metadata – Metadata structure.

BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb)

Composition data vendor model entry with callback functions.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

参数:
  • _company – Company ID.

  • _id – Model ID.

  • _op – Array of model opcode handlers.

  • _pub – Model publish parameters.

  • _user_data – User data for the model.

  • _cb – Callback structure, or NULL to keep no callbacks.

BT_MESH_MODEL_VND_METADATA_CB(_company, _id, _op, _pub, _user_data, _cb, _metadata)

Composition data vendor model entry with callback functions and metadata.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

参数:
  • _company – Company ID.

  • _id – Model ID.

  • _op – Array of model opcode handlers.

  • _pub – Model publish parameters.

  • _user_data – User data for the model.

  • _cb – Callback structure, or NULL to keep no callbacks.

  • _metadata – Metadata structure.

BT_MESH_MODEL(_id, _op, _pub, _user_data)

Composition data SIG model entry.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

参数:
  • _id – Model ID.

  • _op – Array of model opcode handlers.

  • _pub – Model publish parameters.

  • _user_data – User data for the model.

BT_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data)

Composition data vendor model entry.

This macro uses compound literal feature of C99 standard and thus is available only from C, not C++.

参数:
  • _company – Company ID.

  • _id – Model ID.

  • _op – Array of model opcode handlers.

  • _pub – Model publish parameters.

  • _user_data – User data for the model.

BT_MESH_TRANSMIT(count, int_ms)

Encode transmission count & interval steps.

参数:
  • count – Number of retransmissions (first transmission is excluded).

  • int_ms – Interval steps in milliseconds. Must be greater than 0, less than or equal to 320, and a multiple of 10.

返回:

Mesh transmit value that can be used e.g. for the default values of the configuration model data.

BT_MESH_TRANSMIT_COUNT(transmit)

Decode transmit count from a transmit value.

参数:
  • transmit – Encoded transmit count & interval value.

返回:

Transmission count (actual transmissions is N + 1).

BT_MESH_TRANSMIT_INT(transmit)

Decode transmit interval from a transmit value.

参数:
  • transmit – Encoded transmit count & interval value.

返回:

Transmission interval in milliseconds.

BT_MESH_PUB_TRANSMIT(count, int_ms)

Encode Publish Retransmit count & interval steps.

参数:
  • count – Number of retransmissions (first transmission is excluded).

  • int_ms – Interval steps in milliseconds. Must be greater than 0 and a multiple of 50.

返回:

Mesh transmit value that can be used e.g. for the default values of the configuration model data.

BT_MESH_PUB_TRANSMIT_COUNT(transmit)

Decode Publish Retransmit count from a given value.

参数:
  • transmit – Encoded Publish Retransmit count & interval value.

返回:

Retransmission count (actual transmissions is N + 1).

BT_MESH_PUB_TRANSMIT_INT(transmit)

Decode Publish Retransmit interval from a given value.

参数:
  • transmit – Encoded Publish Retransmit count & interval value.

返回:

Transmission interval in milliseconds.

BT_MESH_PUB_MSG_TOTAL(pub)

Get total number of messages within one publication interval including initial publication.

参数:
  • pub – Model publication context.

返回:

total number of messages.

BT_MESH_PUB_MSG_NUM(pub)

Get message number within one publication interval.

Meant to be used inside bt_mesh_model_pub::update.

参数:
  • pub – Model publication context.

返回:

message number starting from 1.

BT_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len)

Define a model publication context.

参数:
  • _name – Variable name given to the context.

  • _update – Optional message update callback (may be NULL).

  • _msg_len – Length of the publication message.

BT_MESH_MODELS_METADATA_ENTRY(_len, _id, _data)

Initialize a Models Metadata entry structure in a list.

参数:
  • _len – Length of the metadata entry.

  • _id – ID of the Models Metadata entry.

  • _data – Pointer to a contiguous memory that contains the metadata.

BT_MESH_MODELS_METADATA_NONE

Helper to define an empty Models metadata array

BT_MESH_MODELS_METADATA_END

End of the Models Metadata list. Must always be present.

BT_MESH_TTL_DEFAULT

Special TTL value to request using configured default TTL

BT_MESH_TTL_MAX

Maximum allowed TTL value

Functions

int bt_mesh_model_send(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *msg, const struct bt_mesh_send_cb *cb, void *cb_data)

Send an Access Layer message.

参数:
  • model – Mesh (client) Model that the message belongs to.

  • ctx – Message context, includes keys, TTL, etc.

  • msg – Access Layer payload (the actual message to be sent).

  • cb – Optional “message sent” callback.

  • cb_data – User data to be passed to the callback.

返回:

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

int bt_mesh_model_publish(struct bt_mesh_model *model)

Send a model publication message.

Before calling this function, the user needs to ensure that the model publication message (bt_mesh_model_pub::msg) contains a valid message to be sent. Note that this API is only to be used for non-period publishing. For periodic publishing the app only needs to make sure that bt_mesh_model_pub::msg contains a valid message whenever the bt_mesh_model_pub::update callback is called.

参数:

model – Mesh (client) Model that’s publishing the message.

返回:

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

static inline bool bt_mesh_model_pub_is_retransmission(const struct bt_mesh_model *model)

Check if a message is being retransmitted.

Meant to be used inside the bt_mesh_model_pub::update callback.

参数:

model – Mesh Model that supports publication.

返回:

true if this is a retransmission, false if this is a first publication.

struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod)

Get the element that a model belongs to.

参数:

mod – Mesh model.

返回:

Pointer to the element that the given model belongs to.

struct bt_mesh_model *bt_mesh_model_find(const struct bt_mesh_elem *elem, uint16_t id)

Find a SIG model.

参数:
  • elem – Element to search for the model in.

  • id – Model ID of the model.

返回:

A pointer to the Mesh model matching the given parameters, or NULL if no SIG model with the given ID exists in the given element.

struct bt_mesh_model *bt_mesh_model_find_vnd(const struct bt_mesh_elem *elem, uint16_t company, uint16_t id)

Find a vendor model.

参数:
  • elem – Element to search for the model in.

  • company – Company ID of the model.

  • id – Model ID of the model.

返回:

A pointer to the Mesh model matching the given parameters, or NULL if no vendor model with the given ID exists in the given element.

static inline bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod)

Get whether the model is in the primary element of the device.

参数:

mod – Mesh model.

返回:

true if the model is on the primary element, false otherwise.

int bt_mesh_model_data_store(struct bt_mesh_model *mod, bool vnd, const char *name, const void *data, size_t data_len)

Immediately store the model’s user data in persistent storage.

参数:
  • mod – Mesh model.

  • vnd – This is a vendor model.

  • name – Name/key of the settings item. Only SETTINGS_MAX_DIR_DEPTH bytes will be used at most.

  • data – Model data to store, or NULL to delete any model data.

  • data_len – Length of the model data.

返回:

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

void bt_mesh_model_data_store_schedule(struct bt_mesh_model *mod)

Schedule the model’s user data store in persistent storage.

This function triggers the bt_mesh_model_cb::pending_store callback for the corresponding model after delay defined by CONFIG_BT_MESH_STORE_TIMEOUT.

The delay is global for all models. Once scheduled, the callback can not be re-scheduled until previous schedule completes.

参数:

mod – Mesh model.

int bt_mesh_model_extend(struct bt_mesh_model *extending_mod, struct bt_mesh_model *base_mod)

Let a model extend another.

Mesh models may be extended to reuse their functionality, forming a more complex model. A Mesh model may extend any number of models, in any element. The extensions may also be nested, ie a model that extends another may itself be extended.

A set of models that extend each other form a model extension list.

All models in an extension list share one subscription list per element. The access layer will utilize the combined subscription list of all models in an extension list and element, giving the models extended subscription list capacity.

参数:
  • extending_mod – Mesh model that is extending the base model.

  • base_mod – The model being extended.

返回值:

0 – Successfully extended the base_mod model.

int bt_mesh_model_correspond(struct bt_mesh_model *corresponding_mod, struct bt_mesh_model *base_mod)

Let a model correspond to another.

Mesh models may correspond to each other, which means that if one is present, other must be present too. A Mesh model may correspond to any number of models, in any element. All models connected together via correspondence form single Correspondence Group, which has it’s unique Correspondence ID. Information about Correspondence is used to construct Composition Data Page 1.

This function must be called on already initialized base_mod. Because this function is designed to be called in corresponding_mod initializer, this means that base_mod shall be initialized before corresponding_mod is.

参数:
  • corresponding_mod – Mesh model that is corresponding to the base model.

  • base_mod – The model being corresponded to.

返回值:
  • 0 – Successfully saved correspondence to the base_mod model.

  • -ENOMEM – There is no more space to save this relation.

  • -ENOTSUP – Composition Data Page 1 is not supported.

bool bt_mesh_model_is_extended(struct bt_mesh_model *model)

Check if model is extended by another model.

参数:

model – The model to check.

返回值:

true – If model is extended by another model, otherwise false

int bt_mesh_comp_change_prepare(void)

Indicate that the composition data will change on next bootup.

Tell the config server that the composition data is expected to change on the next bootup, and the current composition data should be backed up.

返回:

Zero on success or (negative) error code otherwise.

int bt_mesh_models_metadata_change_prepare(void)

Indicate that the metadata will change on next bootup.

Tell the config server that the models metadata is expected to change on the next bootup, and the current models metadata should be backed up.

返回:

Zero on success or (negative) error code otherwise.

int bt_mesh_comp2_register(const struct bt_mesh_comp2 *comp2)

Register composition data page 2 of the device.

Register Mesh Profiles information (Ref section 3.12 in Bluetooth SIG Assigned Numbers) for composition data page 2 of the device.

备注

There must be at least one record present in comp2

参数:

comp2 – Pointer to composition data page 2.

返回:

Zero on success or (negative) error code otherwise.

struct bt_mesh_elem

Abstraction that describes a Mesh Element

struct bt_mesh_model_op

Model opcode handler.

struct bt_mesh_model_pub

Model publication context.

The context should primarily be created using the BT_MESH_MODEL_PUB_DEFINE macro.

struct bt_mesh_models_metadata_entry

Models Metadata Entry struct

The struct should primarily be created using the BT_MESH_MODELS_METADATA_ENTRY macro.

struct bt_mesh_model_cb

Model callback functions.

struct bt_mesh_mod_id_vnd

Vendor model ID

struct bt_mesh_model

Abstraction that describes a Mesh Model instance

struct bt_mesh_send_cb

Callback structure for monitoring model message sending

struct bt_mesh_comp

Node Composition

struct bt_mesh_comp2_record

Composition data page 2 record.

struct bt_mesh_comp2

Node Composition data page 2