Device Pairing

Last Updated on : 2024-02-23 07:27:40download

This topic describes Bluetooth mesh device pairing and how to use the APIs.

Pairing modes

Mesh provisioning

The mesh provisioning protocol, defined by Bluetooth SIG to add a device to a Bluetooth mesh network, supports PB-GATT and PB-ADV.

Device Pairing

The above diagram shows the mesh provisioning process. For more information, see Bluetooth mesh specification.

After mesh provisioning is completed, the process proceeds to the configuration stage. In this stage, device information is obtained and the app_key is sent to the device and bound with the corresponding model. The pairing process is only complete once the configuration stage is finished.

Pairing stages Message exchange Notes
Mesh provisioning 1. Configure unicast_addr.
2. Exchange security keys.
3. Generate device_key.
Elliptic Curve Diffie–Hellman (ECDH) is used to encrypt the communication between the mobile app or the gateway and the device.
Configuration 1. Send the app_key to the device.
2. Bind the model with the app_key.
3. Get the device composition data.
After the device is paired, communication is encrypted using the network_key and device_key.

Tuya fast provisioning

Tuya fast provisioning is Tuya’s proprietary pairing solution, supporting bulk pairing and PB-GATT and PB-ADV for faster speed and improved efficiency.

Provisioning bearer

Two provisioning bearers are defined in the Mesh Profile 1.0.1 chapter 5.2.

  • PB-ADV: A provisioning bearer used to provision a device over the Bluetooth advertising channels. PB-ADV is typically a gateway. It performs passive scanning with a duty cycle as close to 100% as possible to avoid missing any incoming advertising packets.

  • PB-GATT: A provisioning bearer used to provision a device over a GATT connection. PB-GATT is typically a mobile app. The mobile app cannot continuously scan for packets and directly receive messages from the mesh network. It communicates with a device through the GATT connection.

API description

Enable Tuya fast provisioning

VOID tal_mesh_fast_prov_enable(UCHAR_T enable);

Tuya fast provisioning is enabled by default. You can use this API to disable it and use mesh provisioning only.

Get pairing state

UCHAR_T tal_get_if_prov_success(VOID);

Return value:

  • 0: The device is not paired.

  • Other values: The device has been paired.

Configure device information

Configure the device information to the SDK during initialization. In the pairing process, the SDK sends this information to either the mobile app or gateway.

Note: Only authorized devices can be paired. Unauthorized devices will fail to authenticate with the cloud for registration.

VOID tal_firmware_infor_set(UINT8_T is_key, UINT8_T *product_id, UINT8_T *product_key, UINT16_T version, UINT16_T mesh_category, UINT8_T need_publish_addr);
VOID tal_mesh_factory_firmware_info_set(UINT8_T *firmname, UINT8_T *version);
VOID tal_mesh_gatt_ota_version_set(UINT16_T version);

Things to note

Mesh provisioning timeout

If the configuration stage is not completed within 30 seconds after provisioning, pairing will time out.

Tuya fast provisioning timeout

If the configuration stage is not completed within 90 seconds after the mobile app or gateway initiates pairing and sends unicast_addr to the device, pairing will time out.

Because Tuya fast provisioning is intended for bulk pairing, the timeout is longer than that for standard mesh provisioning. In real-world scenarios, if pairing fails, users can reset the device locally and try again.