Activation with QR Code

Last Updated on : 2023-02-13 06:26:32download

The SDK provides short URLs for activating devices. You can make a QR code out of the short URL to allow for device activation using QR code scanning.

API description

Get the activation URL

Function prototype typedef VOID (*ACTIVE_SHORTURL_CB)(OUT CONST CHAR_T *shorturl)
Function description Get the URL for device activation.
Parameter shorturl: The URL for device activation.
Return value VOID
Detailed description This API is a callback function, registered with active_shorturl in TY_IOT_CBS_S that is the first parameter in tuya_iot_gw_dev_init. The SDK calls this API when it gets the activation URL.

Example

static void active_shourturl_cb(char *shorturl)
{
    if (NULL == shorturl) {
        return;
    }

    PR_DEBUG("shorturl : %s", shorturl);

    return;
}

TY_GW_INFRA_CBS_S gw_cbs = {
    .gw_reset_cb       = __gw_reset_cb,
    .gw_upgrade_cb     = __gw_upgrade_cb,
    .gw_active_stat_cb = __gw_active_stat_cb,
    .gw_reboot_cb      = __gw_reboot_cb,
    .gw_active_url_cb  = active_shourturl_cb,
};

op_ret = user_svc_init(&gw_cbs);
if (op_ret != OPRT_OK) {
    PR_ERR("user_svc_init err: %d", op_ret);
    return op_ret;
}

Get the activation state

Function prototype BYTE_T tuya_iot_get_active_stat()
Function description Get the device activation state.
Parameter VOID
Return value BYTE_T:
  • 0: Unregistered
  • 1: Registered and activation started
  • 2: Activated
Detailed description -

Delete activation and registration

Function prototype OPERATE_RET tuya_iot_gw_reset(VOID)
Function description Perform a factory reset on a device, with its registration information in the cloud erased.
Parameter VOID
Return value OPERATE_RET:
  • 0: Success.
  • Other values: Failure. See the error code.
Detailed description Before the SDK calls this API, it should check the internet connection first. Do not call it when the internet is disconnected. Otherwise, the device is still registered in the cloud even though it is already removed locally.