English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Tuya Zigbee Device Authorization

Last Updated on : 2022-03-02 03:55:20download

This topic describes the production test SDK, including the main features, API methods, and callbacks.

Overview

The Zigbee production test SDK is based on the Tuya private network communication protocol and the Bluetooth device firmware communication library. It is used to authorize Zigbee devices and implement custom development for production test software.

The Bluetooth production test SDK is based on the Tuya private network communication protocol and the Zigbee device firmware communication library. Tuya networking library is used in communications on the Tuya IoT cloud. It mainly includes functions such as account login, obtaining authorization code information, module authorization, authorization verification, and authorization log upload. The Zigbee device firmware communication library includes the module production test function based on the Tuya Zigbee device communication protocol, including the production test, authorization information reading and writing, key test, signal strength test, and other functions.

SDK download address

Library name

Network commuicationl library: TuyaCloudIfLib.dll
Zigbee device firmware communication library: Tuya.Module.ProtocolServer.dll
Add the following dependencies:

BouncyCastle.Crypto.dll
Newtonsoft.Json.dll
Tuya.Core.dll
Tuya.Module.BottomCommunication.dll

API methods of Tuya communication library

| Interfaces | Description |
|----|----|----|
| SetUrlSftVer | Set the environment of Tuya IoT Cloud |
| UserLogin | Account login |
| TokenAuth | Authorize |
| GetTokenInfo | Get token information |
| GetFirmwareSignFromServer | Get firmware signature |
| TokenAuthValidate | Verify an authorization with a token |
| AddAuthLog | Add authorization logs |

The method to encrypt Tuya Bluetooth SDK communication.

| Interfaces | Description |
|----|----|----|
| CommunicationServerBuilder.UseSerialPort | Set the Bluetooth communication service serial information. |
| CommunicationServerBuilder.UseTCPClient | Set Zigbee RF test |
| CommunicationServerBuilder.Builder | Create a Zigbee device |
| ZigbeeComServer.Start | Start the Zigbee device. |
| ZigbeeComServer.Stop | Stop the Zigbee device. |
| ZigbeeComServer.SwitchTestMode | Test mode |
| ZigbeeComServer.WriteAuthKey | Write firmware information |
| ZigbeeComServer.ReadAuthKey | Read the firmware authorization information. |
| ZigbeeComServer.ReadMAC | Read MAC address |
| ZigbeeComServer.WritePID | Write PID |
| ZigbeeComServer. ReadPID | Read PID |
| ZigbeeComServer.WriteFirmwareKey | Write firmware information |
| ZigbeeComServer.DownloadConfig | Write OEM configuration file |
| ZigbeeComServer.QueryConfig | Check configuration file |

Procedure

The content of this section is the main authorization test part of the relevant settings and interface calling process of the Tuya Product Testing Authorization SDK.

Test process

The protection test mainly includes account login, authorization code information acquisition, firmware update, connection creation, entering test mode, firmware version verification, and authorization. Before starting the test, make sure that the Tuya account and authorization code Token are correct.

Environment settings

Set Tuya IoT environment Set the work mode of Tuya IoT cloud and set the software version information.

Account login

Account login is a prerequisite for using Tuya IoT cloud authorization, and the account password must be registered with Tuya. Subscribe to a plan again to use Tuya IoT cloud development services.

Access to information

The authorization code information part is used to get the relevant information of the authorization code configuration according to the authorization code provided by Tuya, such as the firmware version information, and other related test configurations.

Upgrade firmware

The firmware update is an optional function. The Tuya IoT service provides firmware version control, and a third party provides firmware burning and writing tools. The update is completed during production testing.

Firmware comparison

Firmware version comparison The main function of this part is to ensure that the firmware version running in the firmware is consistent with the firmware information configured in the authorization code, and to ensure that the device batch or burning result is correct. The method is to call the firmware communication library interface to verify the obtained relevant information with the relevant information in the authorization code.

Procedure

This section describes the detailed authorization process, including related interfaces of the cloud communication library and the Wi-Fi device firmware communication library.

The authorization part is for the device to register and authorize Tuya IoT cloud. Only after the authorization is passed can it be correctly connected with Tuya IoT cloud. This part involves the interfaces such as cloud communication library authorization and authorization verification. It involves the interfaces for writing device authorization information and reading device authorization information in the Bluetooth device firmware communication library. The authorization test ends after this part of the authorization passes. If the authorization fails, it may cause the production test of the whole machine to be inaccessible. In the authorization part, in addition to reading and writing authorization configuration information that can use its own communication protocol, the authorization interface call of the cloud communication library is indispensable and omitted, otherwise it may cause the subsequent process to fail.

Preparation

Before authorization starts, it is necessary to confirm whether the login process is successful, and the Token related information is obtained correctly. In addition, you need to create your own serial number SN for testing. The role of SN is to identify the identity of the authorized device, so as to facilitate the subsequent test of the whole machine to obtain the Mac. The SN requirement is independent and non-repetitive, and after each SN is used, the authorization cannot be repeated (including the case of authorization failure).

Create connection

Call the program and pass in the connection parameters to establish a communication server, and establish a connection with the device.

Enter production test mode

First enter the production test mode, the firmware returns the relevant information that needs to be written in the version of the firmware, including whether to write PID, firmware signature, OEM config file, and AuthKey.

Read MAC address

Read the MAC address of the slave firmware.

Authorize

Make authorization API requests The parameters are SN, authorization code, MAC address, and software version information. After the call is successful, the cloud will return the authorization interface and return the assigned mac, uuid, accessKey and other information. This information is used to write the firmware to set the firmware related parameters.

  • Note: If authorization is wrong, missing, or authorized SN is reused, the authorization interface will return an error message that cannot be authorized.

Write firmware information. If you use the Tuya Zigbee device firmware communication library here, you need to ensure that the Zigbee communication service is successfully turned on and the production test mode is successfully entered. There are four steps:

Step 1: Determine whether the returned mac from the authorization is the same as the mac obtained from the firmware. If they are not the same, rewrite the mac. **
Step 2**: Determine whether to write the PID according to the firmware information returned from the production test and the interface that calls the cloud to obtain the authorization code information. **
Step 3**: Determine whether to write the firmware signature according to the firmware information returned from entering the production test and calling the interface to obtain the firmware signature. **
Step 4**: Determine whether to write the OEM config file according to the interface for obtaining the authorization code information from the cloud. If the authorization code supports writing the configuration file and downloading the configuration file, if the url of the configuration file is empty, an error will be reported. After the download is completed, determine whether the downloaded file is a standard json file. If it is a standard json file, the file needs to be compressed, if not, directly write the file into the file of the same name with the suffix of .bin. Call the interface for requesting the download parameter file, pass in the file length and check value, wait for the return, and then call the interface for transmitting the configuration file. Sub-package transmission is supported. Each package needs to wait for the return value, and then call the interface for ending the file transfer.

Read the firmware authorization information.

Reading the firmware authorization information is to read the authorization information written in the previous step. This method is used to verify whether the authorization information is written successfully.

Class of authorization verification result

After calling the authorization interface and verifying the firmware authorization information, it can be ensured that the firmware authorization information written is consistent with the authorization information. At this time, authorization verification is required to ensure that the authorization is successful. Parameters include Token, SN, uuid, mac, accessKey, software version information, etc.

Add authorization logs

Record current authorization information. Parameters include Token, SN, uuid, mac, timestamp, firmware information, and authorization status. A successful call of the authorization log API method indicates successful authorization.

Tuya communications classes

Set Tuya IoT environment SetUrlSftVer

  • Function:
    void SetUrlSftVer ( string sftVer, string sftIdentity, _LoginUrlType urlType = _LoginUrlType.Release )

  • Parameter:
    [in] sftVer The version number of the software that calls the SDK.
    [in] sftIdentity The name of the software that calls the SDK.
    [in] urlType The environment of the Tuya IoT Cloud. The online environment is specified by default.

  • Return Value: none

  • Note:

  • Select the environment of Tuya IoT cloud and set the name and version of the application that calls the SDK. Based on these settings, the parameters in the call of the Tuya IoT Cloud SDK automatically include the name and version of the application.

  • urlType must be set to _LoginUrlType.Release. Otherwise, the product authorization might be invalid.

UserLogin

  • Function:
    UserLoginRspParas UserLogin(UserLoginReqParas ReqParas, string apiVer = “1.0”)

  • Parameter:
    [in] ReqParas The parameters in the login request. This is the object of the UserLoginReqParas class.
    [in] apiVer The API version. Default value: 1.0.
    Return value. The object of the UserLoginRspParas class.

  • Note:
    Enable login with a Tuya IoT Cloud account and implement user authentication. Contact your project manager to get the username and password. You must apply for the username and password for each account. The permissions and application scope vary based on different accounts. Most API operations in the SDK are available only after login with your account.

TokenAuth

  • Function to TokenAuthRsp TokenAuth(TokenAuthReq ReqParas, string apiVer = “1.0”)
  • Parameter:
    [in] ReqParas The parameters in the authorization request.

[in] apiVer The API version. Default value: 1.0.

  • Return value: the object of the TokenAuthRsp class, including the successful response, the error message that is returned in a failed call, or authorization information.
  • Note: Upload information about a product to the cloud. The uploaded information can be the media access control address (MAC address), serial number (SN), and token. After the verification is passed, the authorization key and other information are returned to authorize the specified device. Unauthorized or failed devices might not be able to connect to the Tuya IoT Cloud.

GetTokenInfo

  • Function: GetTokenInfoRspParas GetTokenInfo(GetTokenInfoReqParas ReqParas, string apiVer = “1.0”)
  • Parameter:
    [in] GetTokenInfoReqParas Class of request parameters to get token information [
    in] apiVer The API version. Default value: 1.0.
  • Return value: The information about the token.
  • Note: Get information about a token.

TokenAuthValidate

  • Function: TokenAuthValidateRsp TokenAuthValidate(TokenAuthValidateReq
    ReqParas, string apiVer = “1.0”)
  • Parameter:
    [in] ReqParas The parameters in the authorization request. [
    in] apiVer The API version. Default value: 1.0.
  • Return value: The object of the TokenAuthValidateRsp class, including the verification of authorization.
  • Note: Verify the validity of an authorization. This verification must be passed before a device is authorized.

AddAuthLog

  • Function: AddAuthLogRspParas AddAuthLog(AddAuthLogReqParas ReqParas, string apiVer = “1.0”)
  • Parameter:
    [in]ReqParas The parameters in the request to add authorization logs.
    [in]apiVer The API version. Default value: 1.0.
  • Return value: The object of the AddAuthLogRspParas class.
  • Note: Upload authorization logs to the Tuya IoT Cloud after a device is authorized.

Methods for Tuya Bluetooth device firmware communication

CommunicationServerBuilder.UseSerialPort

  • Function: CommunicationServerBuilder UseSerialPort(ComPortParas paras)
  • Parameters: [in]paras Serial port board
  • Return value: Return the Linux communication service Builder object
  • Note: Used to set the Bluetooth communication service serial port and baud rate information.

CommunicationServerBuilder.UseTCPClient

  • Function: CommunicationServerBuilder.UseTCPClient (TCPClientParas paras)
  • Parameters: [in]paras TCP parameters
  • Return value: Return the Linux communication service Builder object
  • Note: Used to set the communication service TCP IP and port information.

CommunicationServerBuilde.BuildCreate Zigbee communication service object

  • Function: CommunicationServerBuilde.Build()

Methods for Tuya Zigbee device firmware communication

CommunicationServerBuilder.UseSerialPort

  • Function: CommunicationServerBuilder UseSerialPort(ComPortParas paras)
  • Parameter:
    [in]paras Serial port board
  • Return value: Return the Zigbee communication service Builder object
  • Note: Used to set the Zigbee communication service serial port and baud rate information.

CommunicationServerBuilder.UseTCPClient

  • Function:
    CommunicationServerBuilder.UseTCPClient (TCPClientParas paras)
  • Parameter:
    [in]paras TCP parameters
  • Return value: Return the Zigbee communication service Builder object
  • Note: Used to set the Zigbee communication TCP IP and port information.

CommunicationServerBuilde.BuildCreate Zigbee communication service object

  • Function:
    CommunicationServerBuilde.Build()
  • Parameter: None.
  • Return value: Zigbee device object
  • Note: Tuya networking library is used in communications on the Tuya IoT cloud.

ZigbeeComServer.Start

  • Function: bool CommunicationServer.Start()
  • Return parameter: None.
  • Return value: true: succeeded false: failed
  • Note: Enable device SDK services.

Zigbee residential lock pro and Zigbee residential lock.

  • bool CommunicationServer.Stop()
  • Parameter: None.
  • Return value: true: succeeded false: failed
  • Note: The Bluetooth communication key for a standard Bluetooth mesh device.

ZigbeeComServer.SwitchTestMode enters the test mode

Function
bool SwitchMode(out EnterTestModeRsp rsp, int sendRetryTimes = 1, int receiveRetryTimes = 50, int retryInterval = 100)

  • Parameter:
    [out]rsp Test mode
    [in]sendRestryTimes The max retries to send serial commands.
    [in]receiveRetryTimes Reached to the max retries
    [in]retryInterval The retrial interval. Unit: milliseconds. Default value: 100.
  • Return value: true: succeeded false: failed
  • Note: Enter production test and reset test

ZigbeeComServer.WriteAuthKey write firmware authorization code

  • Function:
    bool WriteAuthKey(WriteAuthKeyReq req, out BaseRsp rsp, int sendRetryTimes = 1, int receiveRetryTimes = 20, int receiveRetryInterval = 1000)
  • Parameter:
    [in]req Write the firmware authorization code
    [out]rsp Result of writing the firmware authorization code
    [int]sendRestryTimes The max retries to send serial commands. Default value: 1
    [int]receiveRetryTimes The max retries to receive serial commands.
    [in]retryInterval The timeout value. Unit: milliseconds. Default value: 1,000
  • Return value: true: succeeded false: failed
  • Note: Click the host to run and write the authorization information.

ZigbeeComServer.ReadAuthKey reads the firmware authorization code

  • Function:
    bool ReadAuthKey (out ReadAuthKeyRsp rsp, int sendRetryTimes = 1, int
    receiveRetryTimes = 6, int receiveRetryInterval = 1000)
  • Parameter:
    [out]rsp Read the master firmware version information.
    [int]sendRestryTimes The max retries to send serial commands. Default value: 1
    [int]receiveRetryTimes The max retries to receive serial commands. Default value: 6
    [in]retryInterval The timeout value. Unit: milliseconds. Default value: 1,000
  • Return value: true: succeeded false: failed
  • Note: Read the master firmware version information.

ZigbeeComServer.ReadMAC read MAC

  • Function: bool ReadMac(out MACRsp rsp, int sendRetryTimes = 1, int receiveRetryTimes = 6, int receiveRetryInterval = 1000)
  • Parameter:
    [out]rsp Read MAC address
    [int]sendRestryTimes The max retries to send serial commands. Default value: 1
    [int]receiveRetryTimes The max retries to receive serial commands. Default value: 6
    [in]retryInterval The timeout value. Unit: milliseconds. Default value: 1,000
  • Return value: true: succeeded false: failed
  • Note: Async Server upload session information

ZigbeeComServer.WritePID write PID

  • Function:
    bool WritePID (PIDReq req, out BaseRsp rsp , int sendRetryTimes = 1, int
    receiveRetryTimes = 6, int receiveRetryInterval = 1000)
  • Parameter:
    [in]req Write the firmware authorization code
    [out]rsp Result of writing the firmware authorization code
    [int]sendRestryTimes The max retries to send serial commands. Default value: 1
    [int]receiveRetryTimes The max retries to receive serial commands.
    [in]retryInterval The timeout value. Unit: milliseconds. Default value: 1,000
  • Return value: true: succeeded false: failed
  • Note: Async Server upload session information

ZigbeeComServer.ReadPID read PID

  • Function:
    bool ReadPID(out PIDRsp rsp, int sendRetryTimes = 1, int
    receiveRetryTimes = 6, int receiveRetryInterval = 1000)
  • Parameter:
    [out]rsp Return value of the command
    [int]sendRestryTimes The max retries to send serial commands. Default value: 1
    [int]receiveRetryTimes The max retries to receive serial commands. Default value: 6
    [in]retryInterval The timeout value. Unit: milliseconds. Default value: 1,000
  • Return value: true: succeeded false: failed
  • Note: Async Server upload session information

ZigbeeComServer.WriteFirmwareKey write firmware signature

  • Function:
    bool WriteFirmwareKey (WriteFirmwareKeyReq req, out BaseRsp rsp , int sendRetryTimes = 1, int receiveRetryTimes = 6, int receiveRetryInterval = 1000)
  • Parameter:
    [in]req Write the firmware authorization code
    [out]rsp Result of writing the firmware authorization code
    [int]sendRestryTimes The max retries to send serial commands. Default value: 1
    [int]receiveRetryTimes The max retries to receive serial commands.
    [in]retryInterval The timeout value. Unit: milliseconds. Default value: 1,000
  • Return value: true: succeeded false: failed
  • Note: Read the master firmware version information.

ZigbeeComServer.DownloadConfig write OEM configuration file

  • Function:
    bool DownloadConfig (byte[] req, out ConfigRsp rsp , int sendRetryTimes = 1, int
    receiveRetryTimes = 6, int receiveRetryInterval = 1000)
  • Parameter:
    [in]req Write byte data to OEM configuration file
    [out]rsp Result of writing the firmware authorization code
    [int]sendRestryTimes The max retries to send serial commands. Default value: 1
    [int]receiveRetryTimes The max retries to receive serial commands.
    [in]retryInterval The timeout value. Unit: milliseconds. Default value: 1,000
  • Return value: true: succeeded false: failed
  • Note: Async Server profiles

ZigbeeComServer.QueryConfig queries OEM configuration file information

  • Function:
    bool ReadConfigInfo(out GetModuleInformationRsp rsp, int sendRetryTimes = 1, int
    receiveRetryTimes = 6, int receiveRetryInterval = 1000)
  • Parameter:
    [out]rsp Get information about the token.
    [int]sendRestryTimes The max retries to send serial commands. Default value: 1
    [int]receiveRetryTimes The max retries to receive serial commands.
    [in]retryInterval The timeout value. Unit: milliseconds. Default value: 1,000
  • Return value: true: succeeded false: failed
  • Note: Async Server profiles

Tuya IoT Cloud SDK classes

enum _LoginUrlType

enum _LoginUrlType
{
	Release = 0,  // The online environment is specified by default.
	Preview = 1,  // The preview environment.
	Daily = 2     // The daily environment.
}

The parameters in the login request. This is the object of the UserLoginReqParas class.

public class UserLoginReqParas
{
	public string username;  // The username, required.
	public string password;  // The password, required.
	public string token;     // The token, optional.
}

Login permissions

public class PermissionsData
{
	public string permissionCode;  // The login permission code.
	public string permissionName;  // The login permission name.
}

Login result

public class UserLoginResult
{
	public string sessionId;                 // The login session ID.
	public List<PermissionsData> permissions; // The list of login permissions.
}

The parameters in the login request. This is the object of the UserLoginReqParas class.

public class UserLoginRspParas{
	public bool success;        // The result of the call. Valid values: `true`: indicates a successful call. `false`: indicates a failed call.
	public string errorMsg;      // The error message that is returned in a failed call.
	public string errorCode;     // The error code.
	public string status;         // The operation status, including the specific error message or status.
	public long t;              // The timestamp when the API operation is called.
	public UserLoginResult result; // The result of the call.
}

public class TokenAuthReq

public class TokenAuthReq    
{
        public string sn ;      // The product SN.
        public string tokenId ;  // The license.
        public string sftVersion ;// The software version number.
        public string muid ;    // The value of `muid` for the Espressif chipset. A null string is returned for other chipsets.
        public string mac ;     // The MAC address of a product.
        public string chipId ;   // The ID of an encrypted chip. A null string is returned for unencrypted chips.
}

TokenAuthResult

public class TokenAuthResult
{
	public string uuid;       // The value of `uuid` of a module.
	public string mac;       // The authorized MAC address.
	public string accessKey;  // The authorization key.
}

TokenAuthRsp

public class TokenAuthRsp{
    	public bool success; // The result of the call. Valid values: `true`: indicates a successful call. `false`: indicates a failed call.
    	public string errorMsg; // The error message that is returned in a failed call.
	public string errorCode; // The error code.
	public string status;    // The operation status.
	public long t; // The timestamp when the API operation is called.
    	public ProdTokenAuthResult result; // The authorization result is valid only when the serial port running result is `true`.
}

GetTokenInfoReqParas

public class GetTokenInfoReqParas
{
	public string tokenId; // The license.
	public string type;   // The type of authorization. Set the value to `Wi-Fi`.
	public string sftVersion; // The software version number.
	public string softwareName; // The software name.
}

Token information class TokenInfo

public class TokenInfo
{
	public int amount; // The total number of devices that can be authorized with a token.
	public string firmwareConfigMd5; // The MD5 hash value of a configuration file.
	public string firmwareConfigUrl; // The URL of a configuration file.
	public string snPrefix; // The prefix of an SN.
	public string firmwareChip; // The firmware chipset.
	public string firmwareProtocolType; // The type of firmware protocol.
	public string productionFirmwareMd5; // The MD5 hash value of production firmware.
	public string productionFirmwareUrl; // The URL of production firmware.
	public bool supportFirmwareConfig; // Specifies whether to support original equipment manufacturer (OEM) configurations.
	public string productionSubFirmwareUrl; // The URL of sub-firmware.
	public string moduleModelChip; // The chipset of a module.
	public string productId; // The product ID.
	public string type; // The type of license.
	public string firmwareKey; // The firmware key.
	public string macRule; // Specifies whether a MAC address is assigned by the cloud. Valid values: `0`: MAC address not assigned. `1`: MAC address assigned.
	public bool oem; // Specifies whether OEM firmware is used.
	public string countryCode; // The country code.
	public string productionSubFirmwareMd5; // The MD5 hash value of sub-firmware.
	public string userareaFirmwareUrl; // The URL of user area firmware.
	public string userareaFirmwareMd5; // The MD5 hash value of user area firmware.
	public bool refreshUserarea; // Specifies whether to refresh user area firmware.
	public long effectiveTime; // The time when the license takes effect.
	public int expires; // The validity of the license.
	public string id; // The license.
	public string productionId; // The production batch number.
	public bool test; // Specifies whether a production test is performed.
	public int usedAmount; // The number of licenses.
	public string wifiHotspotName; // The name of a hotspot.
	public string wifiPassword; // The password of a hotspot.
	public string desc; // The description of the license.
	public string manufacturer; // The manufacturer.
	public string productKey; // Reserved.
	public string fingerprint; // The name of firmware.
	public string firmwareVersion; // The version of firmware.
	public int firmwareType; // Reserved.
	public bool gpioTest; // Reserved.
	public bool wifiTest; // Reserved.
	public string baselineVersion; // Reserved.
	public string flashRunSize; //The size of flash memory. Unit: Mbit/s.
}

Authorization result class

public class TokenAuthRsp
{
   	public bool success; // The result of the call. Valid values: `true`: indicates a successful call. `false`: indicates a failed call.
	public string errorMsg; // The error message that is returned in a failed call.
	public string errorCode; // The error code.
	public string status; // The operation status, including the specific error message or status.
	public long t; // The timestamp when the API operation is called.
	public ProdTokenAuthResult result; // The result of the call.
}

Authorization verification request parameters of TokenAuthValidateReq

public class TokenAuthValidateResult
	public string tokenId ; // The license.
	public string sn; // The product SN.
	public string mac ; // The MAC address of a product.
	public string uuid ; // The value of `uuid` of an authorized product.
	public string muid ; // The ID of a product chip.
	public string accessKey ; // The authorization key.
	public string wifiHotspotName ; // The name of a hotspot.
	public string wifiPassword ; // The password of a hotspot.
	public string chipId ; // The ID of an encrypted chip.
	public string sftVersion ; // The software version number.
}

Authorization verification result returned by TokenAuthValidateResult

public class TokenAuthValidateResult
{
	public bool result; // The result of authorization verification.
	public string failureDepict; // The description of a failure reason.
}

The object of the TokenAuthValidateRsp class.

public class TokenAuthValidateRsp : BaseResponse
{
   	public bool success; // The result of authorization verification.
	public string errorMsg; // The error message that is returned in a failed call.
	public string errorCode; // The error code.
	public string status; // The operation status, including the specific error message or status.
	public long t; // The timestamp when the API operation is called.
	public ProdTokenAuthValidateResult result;  // The result of the call.
}

Class of authorization logs

public class AuthLog
{
	public string hid; // The value is a MAC address in the authorization of Wi-Fi type.
	public string uuid; // The value of `uuid` for an authorization.
	public string tokenId; // The license.
	public string sn; // The product SN.
	public string activeTime; // The timestamp when the authorization takes effect.
	public string firmwareInfo; // The firmware fingerprint, including the name and version of the firmware.
	public string gpio; // The result of a general-purpose input/output (GPIO) pin test. The result can be successful or failed.
	public string rssi; // The result of a Wi-Fi signal strength test.
	public int authStatus; // The authorization status. Valid values: `1`: indicates a successful authorization. `0`: failed.
	public string authDepict; // The description of authorization status. The authorization can be successful or failed.
	public string countryCode; // The country code.
 }

Response parameters to add authorization logs

public class AddAuthLogReqParas
{
   	public AuthLog log; // The data set of authorization logs.
}

Response parameters to add authorization logs

public class AddAuthLogRspParas{
    	public bool success; // The result of the call.
	public string errorMsg; // The error message that is returned in a failed call.
	public string errorCode; // The error code.
	public string status; // The operation status, including the specific error message or status.
	public long t; // The timestamp when the API operation is called.
}

Tuya Zigbee device firmware communications classes

Serial port information setting parameters ComPortParas

public class MyHmac
{
	public string PortName; // The serial number, such as `COM3`.
	public int BaudRate ; // The baud rate.
	public int DataBits ; // The data bit rate.
	public Parity Parity ; // parity check
	public StopBits StopBits ; // The number of stop bits.
	public int ReadBufferSize ; // The size of read buffer.
	public int WriteBufferSize ; // The size of write buffer.
	public int ReadTimeout ; // The read timeout value. Unit: milliseconds.
}

Serial port information setting parameters ComPortParas

public class TCAppientParas
{
   public string HostName { get; set; }// The target IP address.
   public int Port { get; set; }// The target port.
   public int?  ReceiveBufferSize { get; set; }// The size of sending buffer.
   public int?  SendBufferSize { get; set; }// The size of reception buffer.
   public int?  ReceiveTimeout { get; set; }// The timeout value.
}

Write device firmware information WriteConfigInfoReq

public class WriteConfigInfoReq
{
	public string Auzkey;  // The authorization key.
	public string UUID; // The value of `uuid` for an authorization.
	public bool PID; // The product ID.
	public bool IsProductionTest; // Specifies whether a production test is performed.
	public string ApSSID; // The name of the authorized hotspot.
	public string ApPWD; // The password of a hotspot.
}

固件请求返回信息 BaseRsp

public class BaseRsp
{
	public bool Ret; // The result of the call. Valid values: `true`: indicates a successful call. `false`: indicates a failed call.
}

Result of writing the firmware authorization code

public class GetModuleInformationRsp
{
	public string AuthKey;  // The authorization key.
	public string UUID; // The value of `uuid` for an authorization.
	public string pid { get; set; }/// The PID.
	public bool IsProductionTest; // Specifies whether a production test is performed.
	public string ApSSID; // The name of the authorized hotspot.
	public string ApPWD; // The password of a hotspot.
}

Get authorization code (C#)

This code only demonstrates part of the content of obtaining authorization information from Tuya IoT cloud and completing authorization verification. Exclude the features such as writing MAC address and writing authorization information.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TuyaCloudIfLib;
using Newtonsoft.Json;
//1. Login
UserLoginReqParas loginReq= new UserLoginReqParas();
loginReq.username = "******";
loginReq.password = "######";
UserLoginRspParas loginRsp= TuyaCloudIf.UserLogin(loginReq);
if (loginRsp.success == false)
	MessageBox.Show(loginRsp.errorMsg);
else
	MessageBox.Show("Login successfully !" );

//2. Get token information
GetTokenInfoReqParas GetTokenReq = new GetTokenInfoReqParas();
GetTokenReq.tokenId= "XRVAygmzpvRZNxYN";
GetTokenInfoRspParas GetTokenRsp = TuyaCloudIf.GetTokenInfo(GetTokenReq);
if(GetTokenRsp.success == false)
	return false;
//3. Get firmware signs
 var req = new TuyaCloudIfLib.GetModuleSignReqParas
 {
        mac = mac,
        tokenId = tokenId,
        firmwareName = "tuya_zigbee"
  };
  var rsp = TuyaCloudIfLib.TuyaCloudIf.GetModuleSign(req);
  if (rsp.success == false)
  {
         errMsg += rsp.errorMsg;
         return false;
  }
   else
  {
         sign = rsp.result.sign;
         return true;
    }
//4. Auth
TokenAuthReq AuthReq = new TokenAuthReq();
AuthReq.sn = "sn0000000002";
AuthReq.mac = "ecfabc9a86f0";//mac read from module
AuthReq.sftVersion = "test_app";
AuthReq.muid = "";// muid read from module
AuthReq.chipId = "";
AuthReq.tokenId = "*****************";//tokenId
TokenAuthRsp AuthRsp= TuyaCloudIf.TokenAuth(AuthReq);
If(AuthRsp.success== false)
	Return false;
//5. Auth validate
TokenAuthValidateReq ValidateReq = new TokenAuthValidateReq();
ValidateReq.accessKey = AuthRsp.result.accessKey;
ValidateReq.muid = "";//read
ValidateReq.sn = "sn0000000002";
ValidateReq.mac = AuthRsp.result.mac;
ValidateReq.tokenId = "*****************";
ValidateReq.uuid = AuthRsp.result.uuid;
ValidateReq.chipId = "";
ValidateReq.wifiHotspotName = "";
ValidateReq.wifiPassword = "";
ValidateReq.sftVersion = "test_app";
TokenAuthValidateRsp ValidateRsp= TuyaCloudIf.TokenAuthValidate(ValidateReq);
if (! ValidateRsp.success)
	MessageBox.Show("Validate fail !" );
else
	MessageBox.Show("Validate successfully!" );