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

远程配置客户端

远程配置客户端模型是由 Bluetooth mesh 规范定义的基础模型。它通过 CONFIG_BT_MESH_RPR_CLI 选项启用。

远程配置客户端模型在 Bluetooth Mesh 协议规范版本1.1中引入。 该模型提供了将设备远程配置到网格网络中的功能, 并通过与支持 远程配置服务器 模型的网格节点进行交互来执行节点配置协议接口过程。

远程配置客户端模型使用包含目标远程配置服务器模型实例的节点的设备密钥与远程配置服务器模式进行通信。

如果存在,则必须在主元素上实例化远程配置客户端模型。

扫描

扫描过程用于扫描远程配置服务器附近的未配置设备。远程配置客户端通过使用 bt_mesh_rpr_scan_start 调用启动扫描过程:

static void rpr_scan_report(struct bt_mesh_rpr_cli *cli,
            const struct bt_mesh_rpr_node *srv,
            struct bt_mesh_rpr_unprov *unprov,
            struct net_buf_simple *adv_data)
{

}

struct bt_mesh_rpr_cli rpr_cli = {
   .scan_report = rpr_scan_report,
};

const struct bt_mesh_rpr_node srv = {
   .addr = 0x0004,
   .net_idx = 0,
   .ttl = BT_MESH_TTL_DEFAULT,
};

struct bt_mesh_rpr_scan_status status;
uint8_t *uuid = NULL;
uint8_t timeout = 10;
uint8_t max_devs = 3;

bt_mesh_rpr_scan_start(&rpr_cli, &srv, uuid, timeout, max_devs, &status);

上面的示例显示了用于在目标远程配置服务器节点上启动扫描过程的伪代码。 此过程将启动10秒钟的多设备扫描,其中生成的扫描报告最多包含三个未配置的设备。 如果指定了 UUID 参数,则相同的过程将仅扫描具有相应 UUID 的设备。过程完成后, 服务器发送将在客户端的 bt_mesh_rpr_cli.scan_report 回调中处理的扫描报告。

此外,远程配置客户端模型还支持使用 bt_mesh_rpr_scan_start_ext 调用进行扩展扫描。 扩展扫描通过允许远程配置服务器报告特定设备的其他数据来补充常规扫描。 远程配置服务器将使用活动扫描来请求来自未配置设备的扫描响应(如果未配置设备支持)。

预配置

远程配置客户端通过使用 bt_mesh_provision_Remote 调用启动配置过程:

struct bt_mesh_rpr_cli rpr_cli;

const struct bt_mesh_rpr_node srv = {
   .addr = 0x0004,
   .net_idx = 0,
   .ttl = BT_MESH_TTL_DEFAULT,
};

uint8_t uuid[16] = { 0xaa };
uint16_t addr = 0x0006;
uint16_t net_idx = 0;

bt_mesh_provision_remote(&rpr_cli, &srv, uuid, net_idx, addr);

上面的示例显示了通过远程配置服务器节点远程配置设备的伪代码。 此过程将尝试为设备提供相应的 UUID,并使用位于索引零的网络密钥将地址 0x0006 分配给其主要元素。

备注

在远程配置期间,将触发与普通配置相同的 bt_mesh_prov 回调。有关详细信息,请参阅节 预配置

重新配置

除了扫描和配置功能外,远程配置客户端还提供了在支持 远程配置服务器 模型。 这是通过节点配置协议接口(NPPI)提供的,该接口支持以下三个过程:

  • 设备密钥刷新过程:用于更改目标节点的设备密钥,而不需要重新配置节点。

  • 节点地址刷新过程:用于更改节点的设备密钥和单播地址。

  • 节点组成刷新过程:用于更改节点的设备密钥,以及添加或删除节点的模型或功能。

可以使用 bt_mesh_reprovision_remote 调用启动三个 NPPI 过程:

struct bt_mesh_rpr_cli rpr_cli;
struct bt_mesh_rpr_node srv = {
   .addr = 0x0006,
   .net_idx = 0,
   .ttl = BT_MESH_TTL_DEFAULT,
};

bool composition_changed = false;
uint16_t new_addr = 0x0009;

bt_mesh_reprovision_remote(&rpr_cli, &srv, new_addr, composition_changed);

上面的示例显示了用于在目标节点上触发节点地址刷新过程的伪代码。 具体程序不是直接选择的,而是通过输入的其他参数选择的。在该示例中, 我们可以看到 Target 的当前单播地址是 0x0006,而新地址被设置为 0x0009。 如果这两个地址相同,并且 composition_changed 标志设置为 true, 则该代码将触发节点合成刷新过程。如果这两个地址相同,并且 composition_changed 标志设置为 false, 则该代码将触发设备密钥刷新过程。

API 参考

group bt_mesh_rpr_cli

Defines

BT_MESH_RPR_SCAN_MAX_DEVS_ANY

Special value for the max_devs parameter of bt_mesh_rpr_scan_start.

Tells the Remote Provisioning Server not to put restrictions on the max number of devices reported to the Client.

BT_MESH_MODEL_RPR_CLI(_cli)

Remote Provisioning Client model composition data entry.

参数:

Functions

int bt_mesh_rpr_scan_caps_get(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, struct bt_mesh_rpr_caps *caps)

Get scanning capabilities of Remote Provisioning Server.

参数:
  • cli – Remote Provisioning Client.

  • srv – Remote Provisioning Server.

  • caps – Capabilities response buffer.

返回:

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

int bt_mesh_rpr_scan_get(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, struct bt_mesh_rpr_scan_status *status)

Get current scanning state of Remote Provisioning Server.

参数:
  • cli – Remote Provisioning Client.

  • srv – Remote Provisioning Server.

  • status – Scan status response buffer.

返回:

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

int bt_mesh_rpr_scan_start(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, const uint8_t uuid[16], uint8_t timeout, uint8_t max_devs, struct bt_mesh_rpr_scan_status *status)

Start scanning for unprovisioned devices.

Tells the Remote Provisioning Server to start scanning for unprovisioned devices. The Server will report back the results through the bt_mesh_rpr_cli::scan_report callback.

Use the uuid parameter to scan for a specific device, or leave it as NULL to report all unprovisioned devices.

The Server will ignore duplicates, and report up to max_devs number of devices. Requesting a max_devs number that’s higher than the Server’s capability will result in an error.

参数:
  • cli – Remote Provisioning Client.

  • srv – Remote Provisioning Server.

  • uuid – Device UUID to scan for, or NULL to report all devices.

  • timeout – Scan timeout in seconds. Must be at least 1 second.

  • max_devs – Max number of devices to report, or 0 to report as many as possible.

  • status – Scan status response buffer.

返回:

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

int bt_mesh_rpr_scan_start_ext(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, const uint8_t uuid[16], uint8_t timeout, const uint8_t *ad_types, size_t ad_count)

Start extended scanning for unprovisioned devices.

Extended scanning supplements regular unprovisioned scanning, by allowing the Server to report additional data for a specific device. The Remote Provisioning Server will use active scanning to request a scan response from the unprovisioned device, if supported. If no UUID is provided, the Server will report a scan on its own OOB information and advertising data.

Use the ad_types array to specify which AD types to include in the scan report. Some AD types invoke special behavior:

  • BT_DATA_NAME_COMPLETE Will report both the complete and the shortened name.

  • BT_DATA_URI If the unprovisioned beacon contains a URI hash, the Server will extend the scanning to include packets other than the scan response, to look for URIs matching the URI hash. Only matching URIs will be reported.

The following AD types should not be used:

  • BT_DATA_NAME_SHORTENED

  • BT_DATA_UUID16_SOME

  • BT_DATA_UUID32_SOME

  • BT_DATA_UUID128_SOME

Additionally, each AD type should only occur once.

参数:
  • cli – Remote Provisioning Client.

  • srv – Remote Provisioning Server.

  • uuid – Device UUID to start extended scanning for, or NULL to scan the remote server.

  • timeout – Scan timeout in seconds. Valid values from BT_MESH_RPR_EXT_SCAN_TIME_MIN to BT_MESH_RPR_EXT_SCAN_TIME_MAX. Ignored if UUID is NULL.

  • ad_types – List of AD types to include in the scan report. Must contain 1 to CONFIG_BT_MESH_RPR_AD_TYPES_MAX entries.

  • ad_count – Number of AD types in ad_types.

返回:

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

int bt_mesh_rpr_scan_stop(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, struct bt_mesh_rpr_scan_status *status)

Stop any ongoing scanning on the Remote Provisioning Server.

参数:
  • cli – Remote Provisioning Client.

  • srv – Remote Provisioning Server.

  • status – Scan status response buffer.

返回:

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

Get the current link status of the Remote Provisioning Server.

参数:
  • cli – Remote Provisioning Client.

  • srv – Remote Provisioning Server.

  • rsp – Link status response buffer.

返回:

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

Close any open link on the Remote Provisioning Server.

参数:
  • cli – Remote Provisioning Client.

  • srv – Remote Provisioning Server.

  • rsp – Link status response buffer.

返回:

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

int32_t bt_mesh_rpr_cli_timeout_get(void)

Get the current transmission timeout value.

返回:

The configured transmission timeout in milliseconds.

void bt_mesh_rpr_cli_timeout_set(int32_t timeout)

Set the transmission timeout value.

The transmission timeout controls the amount of time the Remote Provisioning Client models will wait for a response from the Server.

参数:

timeout – The new transmission timeout.

struct bt_mesh_rpr_scan_status

Scan status response

Public Members

enum bt_mesh_rpr_status status

Current scan status

enum bt_mesh_rpr_scan scan

Current scan state

uint8_t max_devs

Max number of devices to report in current scan.

uint8_t timeout

Seconds remaining of the scan.

struct bt_mesh_rpr_caps

Remote Provisioning Server scanning capabilities

Public Members

uint8_t max_devs

Max number of scannable devices

bool active_scan

Supports active scan

struct bt_mesh_rpr_cli

Remote Provisioning Client model instance.

Public Members

void (*scan_report)(struct bt_mesh_rpr_cli *cli, const struct bt_mesh_rpr_node *srv, struct bt_mesh_rpr_unprov *unprov, struct net_buf_simple *adv_data)

Scan report callback.

Param cli:

Remote Provisioning Client.

Param srv:

Remote Provisioning Server.

Param unprov:

Unprovisioned device.

Param adv_data:

Advertisement data for the unprovisioned device, or NULL if extended scanning hasn’t been enabled. An empty buffer indicates that the extended scanning finished without collecting additional information.