Device Authorization

Last Updated on : 2024-03-01 08:05:55download

This topic describes how to get the license and write it to the device.

License

The license is an encryption certificate issued by Tuya to allow a device to connect to the Tuya IoT operating system. Each device must be assigned a unique license for authentication. A license grants permission for a single device to connect to and access the cloud.

Get the license

You can request a free license or purchase one.

Write license to device

You can write the license to the device in two ways:

  • During module testing, write the license to the device using Tuya’s production tool or a tool developed with Tuya’s SDK. For more information, see Module Testing.
  • Get the license list, which includes UUID and Authkey. You can write the license to the device using the API. This section describes how to write the license to the device using the API.

Development guide

Reference the header

  • tuya_ws_db.h

  • tuya_iot_wifi_api.h

How-to

  1. Get the license list.

  2. Format Tuya’s key-value database.

  3. Write the license to the device.

    Typically, steps 2 and 3 only need to be executed once. Make sure to manage the entry point for writing the license properly to prevent it from being written each time the device is powered on.

API description

Initialize key-value database

Key-value database is initialized during product testing, and you do not need to handle it. However, if you do not use Tuya’s testing tool, you must manually initialize or format the key-value database.

/**
* @brief Tuya key-value database initialization in mf
*
* @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
*
* @note Users don't need to care about this function, it will be called during production test initialization.
*
*/
OPERATE_RET ws_db_init_mf(VOID);

Write authorization information

/**
* Definition of Wi-Fi product info
*/
typedef struct {
    CHAR_T *uuid;       // strlen(uuid) ≤ 16, it must not be null
    CHAR_T *auth_key;   // strlen(auth_key) ≤ 32, it must not be null
    CHAR_T *ap_ssid;    // strlen(ap_ssid) ≤ 16, if ap_ssid is null, then the default ssid is Smartlife_xxxx
                        // The name of the access point (AP) emitted by the device during pairing in AP mode.
    CHAR_T *ap_passwd; // strlen(ap_passwd) ≤ 16, default null
} WF_GW_PROD_INFO_S;

/**
* @brief tuya_iot_set_wf_gw_prod_info
*
* @param[in] wf_prod_info: device product info
*
* @return OPERATE_RET
*/
OPERATE_RET tuya_iot_set_wf_gw_prod_info(IN CONST WF_GW_PROD_INFO_S *wf_prod_info)

Example

See the tuyaos_demo_quickstart project described in Download and Debugging.