Pairing Plug-In

Last Updated on : 2023-10-09 01:57:19download

You can integrate the device pairing feature into your WeChat mini program as a plug-in without additional development. You can also configure a group of theme colors with this plug-in. You only need to pass in parameters to integrate device pairing into your WeChat mini program.

Pairing methods

Currently, the pairing plug-in supports Bluetooth 2.0 and later, hotspot pairing (access point or AP pairing) with Wi-Fi devices that blink slowly, pairing with QR code, and wireless pairing with Zigbee devices.

Overview of pairing:

  • By default, start pairing by auto discovery. The following types of devices are supported: Bluetooth Low Energy (LE) devices, beacon devices, Zigbee wireless gateways and sub-devices, and combo devices.
  • Manual pairing supports Wi-Fi hotspot or AP pairing and IP camera (IPC) pairing with QR code.
  • Tap the Scan icon in the top right corner of the WeChat mini program to start pairing with QR code. Narrowband Internet of Things (NB-IoT) devices are supported.

Integrate with pairing plug-in

Step 1: Create WeChat Mini Program Project

Follow the instructions in Plug-In to create an IoT WeChat mini program and request permissions to use the Pairing plug-in.

Step 2: Configure plug-in

Add plug-in settings to app.json of your project.

    plugins: {
      'tuya-ap-plugin': {
        version: '4.4.4', // The firmware version. The latest one is recommended.
        provider: 'wxd2aa51ffacc3ff86', // The appid of the plug-in. No need to modify the value.
      },
    },

Step 3: Access the plug-in

Use the development preview code to debug hotspot pairing with a real device.

Add the JavaScript code block for navigation to the plug-in:

  • Hotspot pairing: The plug-in page guides users to finish pairing through four steps.

    wx.navigateTo({
        url: `plugin://tuya-ap-plugin/step1?clientId=${clientId}&gid=${homeId}&ticket=${ticket}&self_env=inner`,
    });
    
  • Pairing with QR code: Open the plug-in page and scan a QR code to start pairing.

    wx.navigateTo({
        url: `plugin://tuya-ap-plugin/virtual?clientId=${clientId}&ticket=${ticket}&gid=${homeId}&self_env=inner`,
    });
    
  • Pairing by auto discovery: Open the plug-in page and start pairing with Bluetooth devices, Zigbee gateways, and respective sub-devices.

    wx.navigateTo({
        url: `plugin://tuya-ap-plugin/auto?clientId=${clientId}&ticket=${ticket}&gid=${homeId}&self_env=inner`,
    });
    

    The navigation path includes the following parameters:

    Parameter name Type Required Pairing method Description
    clientId String Yes Hotspot pairing, pairing with QR code, and pairing by auto discovery The third-party unique identifier. It matches the value of AccessID for the WeChat Mini Program SDK on the Tuya IoT Development Platform.
    ticket String Yes Hotspot pairing, pairing with QR code, and pairing by auto discovery The pairing token. For more information about how to get the token, see User Management.
    gid String Yes Pairing with QR code and by auto discovery The home ID. A device must be bound with a home. For more information about how to get the home ID, see Home Management (currently in Chinese only).
    duration String No Pairing with QR code The maximum testing duration for pairing. Unit: ms. Default value: 6000.
    uiMode String No Hotspot pairing and pairing by auto discovery Configure theme colors
    wifiName String No Hotspot pairing If the Wi-Fi name is modified in hotspot pairing mode, pass in the new Wi-Fi name in this parameter. Default value: SmartLife.
    wifiRecommed String No Hotspot pairing To customize a pairing instruction, pass in the URL of the instruction image. Otherwise, use the default image (image size: 303 pixels in width and 228 pixels in height).
    textArray JSON.stringify(Array) No Hotspot pairing The description of the pairing instruction. Example: [1. Power off the device, wait for 10 seconds, and then power on the device again. 2. Find the Reset button and press and hold it until the indicator starts to blink slowly. 3. Check whether the list of Wi-Fi networks includes a Wi-Fi name starting with SmartLife.]

Step 4: Get device information after successful pairing

Hotspot pairing getNetworkConnect()

Example

const plugin = requirePlugin(‘tuya-ap-plugin’)
const res = plugin.getNetworkConnect()

Return parameters

Parameter name Type Description
success boolean Indicates whether the device is paired successfully.
deviceInfo String The device ID.
uid String The user ID.

Pairing with QR code getVirtualConnect()

Example

const plugin = requirePlugin(‘tuya-ap-plugin’)
const res = plugin.getVirtualConnect()

Return parameters

Parameter name Type Description
success boolean Indicates whether the device is paired successfully.
deviceInfo String The device ID.
uid String The user ID.

Configure theme colors

The plug-in supports 13 built-in theme colors. You can set the parameter uiMode to switch between theme colors. Default value: orange.

Pairing Plug-In

Technical support

After reading the documents, if you still have questions and require technical support, or if you have suggestions on, complaints about, requirements for WeChat mini program development, submit a ticket or request customer services to get support.