Custom Pairing

Last Updated on : 2024-06-25 03:50:09download

Pairing is a process where a device capable of network provisioning (provisioner) connects a new Wi-Fi device to the internet. This topic describes how to build a custom pairing process with the TuyaOS development framework.

Pairing process

  • Standard process:

    The provisioner sends the specified router’s Wi-Fi credentials (SSID and password) and the pairing token generated on the Tuya Developer Platform to an unpaired device. Then, the unpaired device can connect to the specified router’s Wi-Fi network, obtain the server endpoint via Tuya’s IoT DNS service, activate itself with atop service, and connect to the Tuya IoT Development platform for exchanging data with cloud-based applications.

  • Custom process:

    You can develop a custom pairing process on top of the TuyaOS development framework. After the unpaired device receives the router’s Wi-Fi credentials (SSID and password) and the token via the custom data channel, you can call APIs to proceed to connect to the Wi-Fi network and the Tuya Developer Platform for activation. As shown in the following figure:

    DeviceRouterStart the custom pairing process.Call API to set pairing parameters (router's Wi-Fi SSID, password, and token)Connect to router's Wi-Fi.DeviceRouter

Development guide

Header reference

  • tuya_iot_wifi_api.h

How to

After a device ready for pairing receives the parameters for pairing, such as the router’s Wi-Fi credentials and token, you can call APIs to specify these parameters.

API description

Set user-defined pairing parameters

This API is used to set the user-defined pairing parameters including the router’s Wi-Fi SSID and password as well as the pairing token.

/**
 * @brief tuya_iot_gw_wf_user_cfg
 *
 * @param[in] ssid: user config router ap ssid
 * @param[in] passwd: user config router ap passwd
 * @param[in] token: the token of tuya cloud
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 *
 * @note device will scan and connect to the router ap, and try to active on tuya cloud use the token
 */
OPERATE_RET tuya_iot_gw_wf_user_cfg(IN CONST CHAR_T *ssid, IN CONST CHAR_T *passwd, IN CONST CHAR_T *token);