Link SDK Access

Version History

Overview

Tuya Gateway Networking SDK is a software middleware. It can directly establish communication links with Tuya Cloud and Tuya APP by means of the networking capabilities of the device, and carry out Tuya standard data interaction. Users use this SDK to develop gateway products connected to Tuya Cloud.

  • Gateway products

The gateway networking SDK and different protocol controllers are used to make the product into a physical gateway product, and the gateway is connected to various products with different communication protocols, such as: Zigbee, BLE, ZWAVE, etc. For example: common control centers and smart hosts in smart homes. The gateway provides gateway firmware, gateway controller, and firmware upgrade capabilities for sub-terminal devices.

  • Gateway and equipment products

In addition to the control of gateway devices for sub-devices, it also serves as a device product to define the function points of the device and realize the control of the gateway device.

Prerequisites

Before development, users need to register Tuya IoT platform account to obtain the necessary information in the device development stage, including product ID, authorization code, etc.specific operation instructions, please refer toDocument Center.If you have any questions, please contact Tuya Business.

Hardware Requirements

  • Flash: SDK code takes up about 2MB. And there is a readable and writable area.

  • RAM: After the SDK runs, the memory occupies 5MB. The user should increase the memory according to the functional complexity of the developed product.

Software Requirements

  • Support LINUX or ANDROID system.

  • Support TCP / IP protocol stack.

SDK Acquisition

Tuya Gateway Distribution Network SDK is provided to users in the form of C language dynamic link library (.so) or static library (.a). Therefore, users need to provide their system's cross-compilation tool chain to package SDK.

At the same time,Tuya Gateway Distribution Network SDK will also be regularly uploaded to GitHub.If the compiled product already contains the user's cross-compilation tool chain, you can download it directly.

Directory Structure

.
├── build_app.sh
├── CHANGELOG.md
├── demos
├── platforms
└── sdk
    ├── include
    └── lib
        ├── libtuya_iot.a

For the directory structure and usage, please refer to the README.md file in the product package.

SDK Initialization

Equipment Certification

  • The device's identity authentication adopts the one-machine-one-password method to program the device's unique uuid & authkey on the device. This method requires certain modifications to the device's production line tools. uuid & authkey.

  • uuid & authkey appear in pairs, each device must have its own uuid & authkey, and unique, please apply to the Tuya project manager for several groups for debugging.

  • Device authentication message is set via interface tuya_iot_set_gw_prod_info .

Note: The PID in the demo, uuid & authkey are only used for testing, not for actual products, otherwise the subsequent products will be unavailable. PID requires users to apply from the Tuya Developer Platform. Each device must have its own uuid & authkey and be unique.

Initialize The Interface Explanation

tuya_iot_init

OPERATE_RET tuya_iot_init(IN CONST CHAR_T *fs_storge_path)

Features Explanation( Summary )

For the initialization of the tuya iot system, it must be called first.

Parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_get_sdk_info

CHAR_T *tuya_iot_get_sdk_info(VOID);

FeaturesExplanation( Summary )

Obtain the TUYA networke SDK version information.

Parameter Explanation( Parameters )

Return Value(Return Values)

TY_IoT_CBS_S

typedef struct {
    GW_STATUS_CHANGED_CB gw_status_cb;
    GW_UG_INFORM_CB gw_ug_cb;
    GW_RESET_IFM_CB gw_reset_cb;
    DEV_OBJ_DP_CMD_CB dev_obj_dp_cb;
    DEV_RAW_DP_CMD_CB dev_raw_dp_cb;
    DEV_DP_QUERY_CB dev_dp_query_cb;
    DEV_UG_INFORM_CB dev_ug_cb;
    DEV_RESET_IFM_CB dev_reset_cb;
#if defined(TUYA_GW_OPERATOR) && (TUYA_GW_OPERATOR==1)
    OPE_HTTPC_GET_CHCODE_CB ope_get_chcode_cb;
#endif
#if defined(ENABLE_ALARM) && (ENABLE_ALARM==1)
    GW_OFFLINE_DP_SAVE gw_offline_dp_save_cb;
#endif
} TY_IoT_CBS_S;

Features Explanation(Summary)

SDK user callback interface

Member Explanation

Wi-Fi Configuration device interface,Reference "tuya_iot_Wi-Fi_api.h"

WF_GW_PROD_INFO_S

typedef struct {
    CHAR_T *uuid; 
    CHAR_T *auth_key;
    CHAR_T *ap_ssid;
    CHAR_T *ap_passwd;
} WF_GW_PROD_INFO_S;

Features Explanation( Summary )

Wi-Fi product information.

Member Explanation

tuya_iot_set_wf_gw_prod_info

OPERATE_RET tuya_iot_set_wf_gw_prod_info(IN CONST WF_GW_PROD_INFO_S *wf_prod_info);

Features Explanation( Summary )

Set the authorization information of the configuration Wi-Fi device. The authorization information needs to be obtained through TUYA, otherwise the device cannot be used normally.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_wf_gw_init

OPERATE_RET tuya_iot_wf_gw_init(IN CONST GW_WF_CFG_MTHD_SEL cfg,
                                IN CONST GW_WF_START_MODE start_mode, 
                                IN CONST TY_IoT_CBS_S *cbs, 
                                IN CONST TY_IoT_GW_CBS_S *gw_cbs, 
                                IN CONST CHAR_T *product_key, 
                                IN CONST CHAR_T *wf_sw_ver, 
                                IN CONST GW_ATTACH_ATTR_T *attr, 
                                IN CONST UINT_T attr_num);

FeaturesExplanation( Summary )

Wi-Fi gateway initialization interface.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_wf_gw_dev_init

OPERATE_RET tuya_iot_wf_gw_dev_init(IN CONST GW_WF_CFG_MTHD_SEL cfg, 
                                    IN CONST GW_WF_START_MODE start_mode, 
                                    IN CONST TY_IoT_CBS_S *cbs, 
                                    IN CONST TY_IoT_GW_CBS_S *gw_cbs, 
                                    IN CONST CHAR_T *product_key, 
                                    IN CONST CHAR_T *wf_sw_ver, 
                                    IN CONST GW_ATTACH_ATTR_T *attr, 
                                    IN CONST UINT_T attr_num);

FeaturesExplanation( Summary )

Wi-Fi gateway plus device initialization interface, compared with A tuya_iot_wf_gw_init ,This function makes the gateway have the attributes of the device, and can set the features point, etc.

parameter Explanation( Parameters )

Refer to tuya_iot_wf_gw_init interface explanation.

Return Value(Return Values)

Refer to tuya_iot_wf_gw_init interface explanation.

tuya_iot_reg_get_wf_nw_stat_cb

OPERATE_RET tuya_iot_reg_get_wf_nw_stat_cb(IN CONST GET_WF_NW_STAT_CB nw_stat_cb);

FeaturesExplanation( Summary )

Get Wi-Fi status interface.

parameter Explanation( Parameters )

The callback function nw_stat_cb parameter is of type GW_WI-FI_NW_STAT_E and is defined as follows:

#define STAT_LOW_POWER          0   // idle status,use to external config network
#define STAT_UNPROVISION        1   // smart config status
#define STAT_AP_STA_UNCFG       2   // ap WI-FI config status
#define STAT_AP_STA_DISC        3   // ap WI-FI already config,station disconnect
#define STAT_AP_STA_CONN        4   // ap station mode,station connect
#define STAT_STA_DISC           5   // only station mode,disconnect
#define STAT_STA_CONN           6   // station mode connect
#define STAT_CLOUD_CONN         7   // cloud connect
#define STAT_AP_CLOUD_CONN      8   // cloud connect and ap start 

Return Value(Return Values)

Non-Wi-Fi configuration device interface,Reference "tuya_iot_base_api.h"

GW_PROD_INFO_S

typedef struct {
    CHAR_T *uuid; 
    CHAR_T *auth_key;
} GW_PROD_INFO_S;

FeaturesExplanation( Summary )

Gateway product information.

Member Explanation

tuya_iot_set_gw_prod_info

OPERATE_RET tuya_iot_set_gw_prod_info(IN CONST GW_PROD_INFO_S *prod_info);

Features Explanation( Summary )

Set the authorization information of the non-Wi-Fi configuration networking module. The authorization information needs to be obtained through TUYA, otherwise the device cannot be used normally.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_gw_init

OPERATE_RET tuya_iot_gw_init(IN CONST TY_IoT_CBS_S *cbs, 
                             IN CONST TY_IoT_GW_CBS_S *gw_cbs, 
                             IN CONST CHAR_T *product_key,
                             IN CONST CHAR_T *sw_ver, 
                             IN CONST GW_ATTACH_ATTR_T *attr, 
                             IN CONST UINT_T attr_num);

FeaturesExplanation( Summary )

Networking module gateway initialization interface.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_gw_dev_init

OPERATE_RET tuya_iot_gw_dev_init(IN CONST TY_IoT_CBS_S *cbs, 
                                 IN CONST TY_IoT_GW_CBS_S *gw_cbs, 
                                 IN CONST CHAR_T *product_key, 
                                 IN CONST CHAR_T *sw_ver, 
                                 IN CONST GW_ATTACH_ATTR_T *attr, 
                                 IN CONST UINT_T attr_num);

FeaturesExplanation

The networking module gateway plus the device initialization interface. Compared with A, this function makes the gateway have the attributes of the device, and you can set the features point.

parameter Explanation( Parameters )

Refer to tuya_iot_gw_init interface explanation

Return Value(Return Values)

Refer to tuya_iot_gw_init interface explanation

tuya_iot_reg_get_nw_stat_cb

OPERATE_RET tuya_iot_reg_get_nw_stat_cb(IN CONST GET_NW_STAT_CB nw_stat_cb);

FeaturesExplanation( Summary )

Register the network network status acquisition function.In the registered callback function,In the registered callback function, the user can obtain the current network status information.

parameter Explanation( Parameters )

In the registered callback function, the user knows the current network status according to the callback function parameter. The network status GW_BASE_NW_STAT_T is defined as follows:

/* offline in LAN.  user wired callback <hwl_bnw_station_conn> return <false> */
#define GB_STAT_LAN_UNCONN 0

/* online in LAN, offline in WAN.
   user wired callback <hwl_bnw_station_conn> return <true> but mqtt is offline
*/
#define GB_STAT_LAN_CONN 1

/* online in WAN.
   user wired callback <hwl_bnw_station_conn> return <true> and mqtt is online
*/
#define GB_STAT_CLOUD_CONN 2

Reference tuya_cloud_base_defs.h

Return Value(Return Values)

Wired and Wi-Fi configuration interface,reference "tuya_iot_wired_Wi-Fi_api.h"

tuya_iot_set_wired_Wi-Fi_gw_prod_info

tuya_iot_set_wired_Wi-Fi_gw_prod_info(IN CONST WF_GW_PROD_INFO_S *wf_prod_info);

Parameter explanation reference tuya_iot_set_wf_gw_prod_info function section.

tuya_iot_wired_Wi-Fi_gw_init

OPERATE_RET tuya_iot_wired_Wi-Fi_gw_init(IN CONST IoT_GW_NET_TYPE_T net_mode, 
                                        IN CONST GW_WF_CFG_MTHD_SEL cfg, 
                                        IN CONST GW_WF_START_MODE start_mode,
                                        IN CONST TY_IoT_CBS_S *cbs, 
                                        IN CONST TY_IoT_GW_CBS_S *gw_cbs,
                                        IN CONST CHAR_T *product_key, 
                                        IN CONST CHAR_T *wf_sw_ver,
                                        IN CONST GW_ATTACH_ATTR_T *attr, 
                                        IN CONST UINT_T attr_num);

FeaturesExplanation( Summary )

Wired + Wi-Fi gateway initialization interface.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_wired_Wi-Fi_gw_dev_init

OPERATE_RET tuya_iot_wired_Wi-Fi_gw_dev_init(IN CONST IoT_GW_NET_TYPE_T net_mode, 
                                            IN CONST GW_WF_CFG_MTHD_SEL cfg, 
                                            IN CONST GW_WF_START_MODE start_mode, 
                                            IN CONST TY_IoT_CBS_S *cbs, 
                                            IN CONST TY_IoT_GW_CBS_S *gw_cbs, 
                                            IN CONST CHAR_T *product_key, 
                                            IN CONST CHAR_T *wf_sw_ver, 
                                            IN CONST GW_ATTACH_ATTR_T *attr, 
                                            IN CONST UINT_T attr_num);

Features Explanation( Summary )

Wired + Wi-Fi gateway (the gateway also acts as a device) initializes the interface.

parameter Explanation( Parameters )

IoT_GW_NET_TYPE_T definition :

#define IoT_GW_NET_WIRED       0   //only support wried
#define IoT_GW_NET_WI-FI        1   //only support Wi-Fi
#define IoT_GW_NET_WIRED_WI-FI  2   //support wired and Wi-Fi

GW_WF_CFG_MTHD_SEL definition:

#define GWCM_OLD                0   // do not have low power mode
#define GWCM_LOW_POWER          1   // with low power mode
#define GWCM_SPCL_MODE          2   // special with low power mode
#define GWCM_OLD_PROD           3   // GWCM_OLD mode with product

In Linux / Android, select GWCM_OLD_PROD.

GW_WF_START_MODE definition:

#define WF_START_AP_ONLY        0   // only have ap-cfg mode
#define WF_START_SMART_ONLY     1   // only have smart-cfg mode
#define WF_START_AP_FIRST       2   // have both ap-cfg and smart-cfg. default is ap-cfg mode
#define WF_START_SMART_FIRST    3   // have both ap-cfg and smart-cfg. default is smart-cfg mode
#define WF_START_SMART_AP_CONCURRENT    4   //  ap-cfg and smart-cfg is concurrent

parameter attr the user sets the adapter that he supports.For example, the gateway supports zigbee, it can be set to:

GW_ATTACH_ATTR_T attr[] = {
    {GP_DEV_ZB,"1.0.0"},
};

Return Value(Return Values)

tuya_iot_reg_get_wired_Wi-Fi_nw_stat_cb

OPERATE_RET tuya_iot_reg_get_wired_Wi-Fi_nw_stat_cb(nw_stat_cb, wf_nw_stat_cb);

Features Explanation( Summary )

Register callback function for network status management.

parameter Explanation( Parameters )

Referance tuya_iot_reg_get_nw_stat_cb and tuya_iot_reg_get_wf_nw_stat_cb introduction of callback function.

Return Value(Return Values)

tuya_iot_gw_wired_Wi-Fi_set_net_name

VOID tuya_iot_gw_wired_Wi-Fi_set_net_name(IN CONST CHAR_T *wired_net_name, IN CONST CHAR_T *Wi-Fi_net_name);

Features Explanation

Set up wired and Wi-Fi network interfaces.

parameter Explanation( Parameters )

Return Value(Return Values)

Equipment Distribution Network

Explanation:tuya_SDK will enable multi-threading, and the entire process must be restarted to enter the distribution mode to take effect.

Because there are many platforms that TUYA SDK takes into account, it is impossible to take into account the hardware details of all networking modules.Therefore, for the inside of the SDK, a set of hardware interfaces related to networked devices needs to be abstracted.Divided into two categories according to product form: Wi-Fi configuration network interface, non-Wi-Fi configuration network interface, specific ExplanationReference demo code.

Wired Equipment Distribution Network

The device is connected to the Internet through a wire, without entering the hotspot name and password of the router, the device is connected to the external network; just obtain the activation token from the APP side, you can apply to activate the device in TUYA cloud.

Reset The Device (enter the network to be configured)

tuya_iot_gw_unactive

OPERATE_RET tuya_iot_gw_unactive(VOID);

FeaturesExplanation( Summary )

Reset the gateway and release the binding relationship between the gateway and APP, so that the gateway is in an inactive state (network to be configured).

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_wired_Wi-Fi_gw_unactive

OPERATE_RET tuya_iot_wired_Wi-Fi_gw_unactive(VOID)

Explanation refer tuya_iot_gw_unactive

Interactive Diagram of Distribution Process

  • As shown above, after resetting on the device, you need to restart the SDK process before you can enter the network configuration mode.

  • dev_reset_cb refer to common problem Explanation

User-implemented Interface

tuya_hal_wired_get_ip

OPERATE_RET tuya_hal_wired_get_ip(OUT NW_IP_S *ip)

FeaturesExplanation( Summary )

Obtain the IP address of the wired network card

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_wired_station_conn

BOOL_T tuya_hal_wired_station_conn(VOID);

FeaturesExplanation( Summary )

Get the status of the network connection to the external network.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_wired_get_mac

OPERATE_RET tuya_hal_wired_get_mac(OUT NW_MAC_S *mac)

FeaturesExplanation( Summary )

Get the MAC address of the wired network interface. Optional implementation.

parameter Explanation( Parameters )

Return Value(Return Values)

hwl_bnw_set_mac

OPERATE_RET tuya_hal_wired_set_mac(IN CONST NW_MAC_S *mac);

FeaturesExplanation( Summary )

Set the MAC address of the wired network card. There is currently no need for implementation.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_wired_Wi-Fi_set_station_connect

OPERATE_RET tuya_hal_wired_Wi-Fi_set_station_connect(IN CONST CHAR_T *ssid, 
                                                    IN CONST CHAR_T *passwd)

FeaturesExplanation( Summary )

When the product form is wired + wireless mode, users need to realize the function of Wi-Fi connection.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_wired_Wi-Fi_need_cfg

BOOL_T tuya_hal_wired_Wi-Fi_need_cfg(VOID);

FeaturesExplanation( Summary )

If the hardware form is Wi-Fi + wired mode, do users need to connect to external Wi-Fi configuration?

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_wired_Wi-Fi_station_get_conn_ap_rssi

OPERATE_RET tuya_hal_wired_Wi-Fi_station_get_conn_ap_rssi(OUT SCHAR_T *rssi)

FeaturesExplanation( Summary )

When the product form is wired + wireless, this interface is used to obtain the rssi value of Wi-Fi.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_wired_if_connect_internet

int tuya_hal_wired_if_connect_internet(bool *status);

FeaturesExplanation( Summary )

Get the network status.

parameter Explanation( Parameters )

Return Value(Return Values)

Wi-Fi Equipment Distribution Network

  • The user needs to determine the working mode supported by the Wi-Fi network card first, and then inform the SDK of the supported network configuration mode when the tuya_iot_wf_xx_init interface is initialized.Specific reference tuya_iot_wf_xx_dev_init interface like cfg parameter Explanation

  • The SDK supports EZ distribution network and AP distribution mode.EZ is also called fast network configuration. It means that the Wi-Fi of the device is in monitor mode to obtain the wireless air interface packets sent by the APP.The SDK will parse these messages, obtain configuration information from it, and switch to station mode for networking.The AP network configuration process is relatively complicated, which means that the device turns on the AP hotspot, the mobile phone is connected, and the configuration information is sent through the local area network. After the device obtains the configuration information, it switches to the station mode for networking.

Reset The Device (enter network configuration mode)

  • As shown above, after resetting the device locally, you need to restart the SDK process before you can enter the network distribution mode.

  • dev_reset_cb refer tocommon problem Explanation;

  • When the configuration supports both AP and EZ network configuration modes during initialization, calling this interface will switch the network distribution mode cyclically;

tuya_iot_wf_gw_unactive

OPERATE_RET tuya_iot_wf_gw_unactive(VOID);

FeaturesExplanation( Summary )

Reset the gateway to release the binding relationship between the gateway sub-devices, so that the gateway is in the inactive (network to be configured) state.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_wired_Wi-Fi_gw_unactive

OPERATE_RET tuya_iot_wired_Wi-Fi_gw_unactive(VOID);

FeaturesExplanation( Summary )

Wired + Wi-Fi reset. same as tuya_iot_wf_gw_unactive

tuya_iot_wf_fast_get_nc_type

OPERATE_RET tuya_iot_wf_fast_get_nc_type(GW_WF_NWC_FAST_STAT_T *nc_type)

FeaturesExplanation( Summary )

Get the current Wi-Fi configuration method.

parameter Explanation( Parameters )

GW_WF_NWC_FAST_STAT_T the definition is as follows:

#define GWNS_FAST_LOWPOWER           0   // current in low power mode
#define GWNS_FAST_UNCFG_SMC          1   // current in smart-cfg mode
#define GWNS_FAST_UNCFG_AP           2   // current in ap-cfg mode
#define GWNS_FAST_UNCFG_NORMAL       3   // current in normal mode

Return Value(Return Values)

tuya_iot_wired_Wi-Fi_fast_get_nc_type

OPERATE_RET tuya_iot_wired_Wi-Fi_fast_get_nc_type(GW_WF_NWC_FAST_STAT_T *nc_type);

FeaturesExplanation( Summary )

Get the current Wi-Fi configuration mode in wired + Wi-Fi mode. Parameter explanation same as tuya_iot_wf_fast_get_nc_type

tuya_iot_set_wf_cfg_err_code_cb

OPERATE_RET tuya_iot_set_wf_cfg_err_code_cb(IN CONST WF_NW_CFG_ERR_CODE_CB wf_nw_cfg_err_code_cb);

FeaturesExplanation( Summary )

Registration callback function --- used to get the error code generated by Wi-Fi distribution.

parameter Explanation( Parameters )

The parameter of the callback function is the error code generated by the Wi-Fi distribution network. The definition is as follows:

/*Initial state*/
#define NW_CFG_INIT      			0
/*Activation fails*/
#define NW_CFG_ACTIVE_FAILED 		1
/*ap not found*/
#define NW_CFG_AP_NOT_FOUND 		2
/*wrong password*/
#define NW_CFG_ERR_PASSWD 			3
/*ap can't connect*/
#define NW_CFG_CANT_CONN_AP 		4
/*dhcp error*/
#define NW_CFG_DHCP_FAILED 			5
/*Router connected successfully*/
#define NW_CFG_SUCC  				100

Return Value(Return Values)

AP distribution network

  1. Implement the interface that the user needs

  2. After the device is reset, make the SDK enter the network to be configured state

tuya_iot_set_user_def_ap_if

OPERATE_RET tuya_iot_set_user_def_ap_if(IN CONST CHAR_T *ssid,IN CONST CHAR_T *passwd)

FeaturesExplanation( Summary )

User-defined SSID prefix and password. If not set, the SSID prefix defaults to "SmartLife-", the password is blank, and the encryption method is open.

parameter Explanation( Parameters )

Return Value(Return Values)

WF_AP_CFG_IF_S

typedef struct {
    uint8_t ssid[WI-FI_SSID_LEN+1];       ///< ssid
    uint8_t s_len;                       ///< len of ssid
    uint8_t passwd[WI-FI_PASSWD_LEN+1];   ///< passwd
    uint8_t p_len;                       ///< len of passwd
    uint8_t chan;                        ///< channel. default:0
    WF_AP_AUTH_MODE_E md;                ///< encryption type
    uint8_t ssid_hidden;                 ///< ssid hidden  default:0
    uint8_t max_conn;                    ///< max sta connect nums default:0
    uint16_t ms_interval;                ///< broadcast interval default:0
} WF_AP_CFG_IF_S;

FeaturesExplanation(Summary)

AP configuration structure.

Member Explanation

User-implemented Interface

tuya_hal_Wi-Fi_get_ip

OPERATE_RET tuya_hal_Wi-Fi_get_ip(IN CONST WF_IF_E wf,OUT NW_IP_S *ip)

FeaturesExplanation( Summary )

Obtain the IP address of the Wi-Fi network card.

parameter Explanation( Parameters )

Type definition of WF_IF_E:

typedef enum
{
    WF_STATION = 0,     // station type; station type
    WF_AP,              // ap type; AP type
} WF_IF_E;

Return Value(Return Values)

tuya_hal_Wi-Fi_get_mac

OPERATE_RET tuya_hal_Wi-Fi_get_mac(IN CONST WF_IF_E wf,INOUT NW_MAC_S *mac)

FeaturesExplanation( Summary )

Get the MAC address of the Wi-Fi network card.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_set_mac

OPERATE_RET tuya_hal_Wi-Fi_set_mac(IN CONST WF_IF_E wf,IN CONST NW_MAC_S *mac)

FeaturesExplanation( Summary )

Set the MAC address of the Wi-Fi device. There is currently no need for implementation.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_set_work_mode

OPERATE_RET tuya_hal_Wi-Fi_set_work_mode(IN CONST WF_WK_MD_E mode)

FeaturesExplanation( Summary )

Set Wi-Fi working mode.

parameter Explanation( Parameters )

The working mode of Wi-Fi is defined as follows:

typedef enum
{
    WWM_LOWPOWER = 0,   ///< Wi-Fi work in lowpower mode. The LINUX system does not care about low power consumption and does not need to be dealt with.
    WWM_SNIFFER,        ///< Wi-Fi work in sniffer mode
    WWM_STATION,        ///< Wi-Fi work in station mode
    WWM_SOFTAP,         ///< Wi-Fi work in ap mode
    WWM_STATIONAP,      ///< Wi-Fi work in station+ap mode
}WF_WK_MD_E;

Need to deal with WWM_SNIFFER and WWM_STATION (or WWM_STATIONAP) in EZ distribution network。

Return Value(Return Values)

tuya_hal_Wi-Fi_get_work_mode

OPERATE_RET tuya_hal_Wi-Fi_get_work_mode(OUT WF_WK_MD_E *mode)

FeaturesExplanation( Summary )

Get Wi-Fi working mode.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_station_connect

OPERATE_RET tuya_hal_Wi-Fi_station_connect(IN CONST CHAR_T *ssid,IN CONST CHAR_T *passwd)

FeaturesExplanation( Summary )

Wi-Fi devices connect to the router based on ssid & password.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_station_disconnect

Function prototype

OPERATE_RET tuya_hal_Wi-Fi_station_disconnect(VOID)

FeaturesExplanation

Disconnect the Wi-Fi device and router.

parameter Explanation

Return Value

tuya_hal_Wi-Fi_station_get_conn_ap_rssi

OPERATE_RET tuya_hal_Wi-Fi_station_get_conn_ap_rssi(OUT SCHAR_T *rssi)

FeaturesExplanation( Summary )

Get the signal strength of the Wi-Fi device.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_station_get_status

OPERATE_RET tuya_hal_Wi-Fi_station_get_status(OUT WF_STATION_STAT_E *stat)

FeaturesExplanation( Summary )

Get the network status of the Wi-Fi device.

parameter Explanation( Parameters )

WF_STATION_STAT_E Explanation:

typedef enum {
    WSS_IDLE = 0,                       ///< not connected;  
    WSS_CONNECTING,                     ///< connecting Wi-Fi; 
    WSS_PASSWD_WRONG,                   ///< passwd not match; 
    WSS_NO_AP_FOUND,                    ///< ap is not found;
    WSS_CONN_FAIL,                      ///< connect fail; 
    WSS_CONN_SUCCESS,                   ///< connect Wi-Fi success; 
    WSS_GOT_IP,                         ///< get ip success;
} WF_STATION_STAT_E;

Return Value(Return Values)

tuya_hal_Wi-Fi_set_country_code

OPERATE_RET tuya_hal_Wi-Fi_set_country_code(IN CONST CHAR_T *p_country_code)

FeaturesExplanation( Summary )

Set the country code where the Wi-Fi device works.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_ap_start

OPERATE_RET tuya_hal_Wi-Fi_ap_start(IN CONST WF_AP_CFG_IF_S *cfg)

FeaturesExplanation( Summary )

Start the Wi-Fi AP hotspot.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_ap_stop

OPERATE_RET tuya_hal_Wi-Fi_ap_stop(VOID)

FeaturesExplanation( Summary )

Stop hotspots in AP configuration mode.

parameter Explanation( Parameters )

Return Value(Return Values)

EZ Distribution Network

The Interface that the User Needs to Implement (EZ distribution network)

tuya_hal_Wi-Fi_all_ap_scan

OPERATE_RET tuya_hal_Wi-Fi_all_ap_scan(OUT AP_IF_S **ap_ary,OUT UINT_T *num)

FeaturesExplanation( Summary )

Get AP list information in the current environment.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_assign_ap_scan

OPERATE_RET tuya_hal_Wi-Fi_assign_ap_scan(IN CONST CHAR_T *ssid,OUT AP_IF_S **ap)

FeaturesExplanation( Summary )

Get the AP information of the specified SSID.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_release_ap

OPERATE_RET tuya_hal_Wi-Fi_release_ap(IN AP_IF_S *ap)

FeaturesExplanation( Summary )

Release processing of allocated resources.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_set_cur_channel

OPERATE_RET tuya_hal_Wi-Fi_set_cur_channel(IN CONST BYTE_T chan)

FeaturesExplanation( Summary )

Set the Wi-Fi working channel.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_get_cur_channel

OPERATE_RET tuya_hal_Wi-Fi_get_cur_channel(OUT BYTE_T *chan)

FeaturesExplanation( Summary )

Get the current working channel.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_hal_Wi-Fi_sniffer_set

OPERATE_RET tuya_hal_Wi-Fi_sniffer_set(IN CONST bool en,IN CONST SNIFFER_CALLBACK cb)

FeaturesExplanation( Summary )

Set the packet capture status of the Wi-Fi device in sniffer mode.

parameter Explanation( Parameters )

Return Value(Return Values)

Other distribution methods

  • The user layer of such distribution equipment obtains the ssid, passwd and distribution token of the router through other methods, and directly calls the interface to apply for device activation.

  • Two-dimensional code distribution network, the device scans the two-dimensional code generated on the APP through the camera to obtain ssid / passwd / token information.

  • Bluetooth distribution network, the device obtains the ssid / passwd / token information through the QR code on the APP via Bluetooth.

  • Serial port, sonic distribution network, etc.

tuya_iot_gw_wf_user_cfg

OPERATE_RET tuya_iot_gw_wf_user_cfg(IN CONST CHAR_T *ssid, IN CONST CHAR_T *passwd,IN CONST CHAR_T *token);

FeaturesExplanation( Summary )

When the network is configured in other modes (not AP / EZ), such as the camera's QR code distribution network, acoustic wave distribution network, etc., call this interface for processing.

parameter Explanation( Parameters )

Return Value(Return Values)

Gateway Reset

APP Reset Geteway

The user can reset the gateway through the APP.

gw_reset_cb

VOID gw_reset_cb(GW_RESET_TYPE_E type);

FeaturesExplanation( Summary )

The user registers the callback function gw_reset_cb in [TY_IoT_CBS_S] (# TY_IoT_CBS_S) .

parameter Explanation( Parameters )

GW_RESET_TYPE_E definition:

typedef enum {
    GW_LOCAL_RESET_FACTORY = 0,
    GW_REMOTE_UNACTIVE,
    GW_LOCAL_UNACTIVE,
    GW_REMOTE_RESET_FACTORY,
    GW_RESET_DATA_FACTORY, //need clear local data when active
}GW_RESET_TYPE_E;

Currently, the GW_REMOTE_RESET_FACTORY and GW_RESET_DATA_FACTORY reset types need to be handled in the gateway callback. The gateway application needs to be restarted after reset.

Return Value(Return Values)

Local reset gateway

The SDK retains the ability to reset the gateway locally, and users can reset the gateway locally by pressing buttons.Reference tuya_iot_gw_unactive and tuya_iot_wf_gw_unactive .

Device firmware upgrade (OTA)

  • Firmware upgrade is mainly used to repair the device BUG and add new functions of the device. There are two main types of firmware upgrade, the first is device upgrade, and the second is MCU upgrade. The firmware upgrade of Wi-Fi devices here refers to the device upgrade.

  • The device upgrade process involves mobile APP, device, and TUYA cloud terminal.

    • Mobile APP: The display of the upgrade progress result or the initiator of the upgrade message.

    • TUYA cloud: The manager in the upgrade process is responsible for the storage of the upgraded firmware, the update of the device upgrade status, and the push of the upgrade copy.

    • Device: Responsible for receiving firmware. Performer of firmware upgrade.

Firmware package configuration instructions

  • After the network configuration of the gateway or sub-device is successful, obtain the virtual ID in the device information from the APP as a whitelist for firmware upgrade.

  • Compile the firmware to be upgraded, the firmware version is higher than the firmware version running in the device.

  • Log in to the developer platform https://iot.tuya.com/index , and upload the configuration firmware package to the corresponding created product.

  • Instructions:https://docs.tuya.com/cn/product/ota.html

How the upgrade begins

After the device firmware is uploaded to the cloud, the device will not immediately receive the upgrade message. Currently TUYA supports the following methods:

  • APP reminder upgrade: When users open the device panel for the first time, they will receive an upgrade reminder pop-up box, they can choose to upgrade or not to upgrade.

  • APP silent upgrade: That is, the device is silently upgraded. After the device is restarted, it will request the cloud to check whether there is a silent upgrade task, and if so, directly upgrade; if the user opens the device panel, a progress box will be displayed at this time. The device is inoperable at this time.

  • APP forced upgrade: When the user opens the device panel for the first time, he will receive an upgrade reminder pop-up box. Only the confirmation is optional, and the responsible device cannot be operated.

  • APP detection upgrade: APP users actively click on the panel of the corresponding device, then click on the upper right corner to enter the device information interface, detect the device firmware version, and actively update.

Data interaction diagram

  • Explanation:The upgrade progress reported in the following figure is reported by tuya_SDK, and can also be configured to be reported by the application layer through tuya_iot_upgrade_gw_notify.

Relevant interface and callback description

FW_UG_S

typedef struct {
    DEV_TYPE_T tp;
    UPGRADE_TYPE_T type;
    CHAR_T fw_url[FW_URL_LEN+1];
    CHAR_T sw_ver[SW_VER_LEN+1];
    UINT_T file_size;
    CHAR_T fw_hmac[FW_HMAC_LEN+1];
} FW_UG_S;

FeaturesExplanation(Summary)

Upgraded firmware information.

Member Explanation

gw_ug_cb

VOID gw_ug_cb(IN CONST FW_UG_S *fw)

FeaturesExplanation( Summary )

The user registers the callback function gw_ug_cb in [TY_IoT_CBS_S] (# TY_IoT_CBS_S). The gateway has a new firmware notification callback.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_upgrade_gw

OPERATE_RET tuya_iot_upgrade_gw_notify(IN CONST FW_UG_S *fw, 
                                       IN CONST GET_FILE_DATA_CB get_file_cb, 
                                       IN CONST UPGRADE_NOTIFY_CB upgrd_nofity_cb, 
                                       IN CONST PVOID_T pri_data, 
                                       BOOL_T notify, 
                                       UINT_T download_buf_size);

FeaturesExplanation( Summary )

Networking module firmware upgrade processing interface.

parameter Explanation( Parameters )

Return Value(Return Values)

The application layer reports the progress of the upgrade

When the progress of the application layer control upgrade is reported, please use tuya_iot_upgrade_gw_notify to close the tuya_SDK and report the upgrade progress.

tuya_iot_dev_upgd_progress_rept

OPERATE_RET tuya_iot_dev_upgd_progress_rept(IN CONST UINT_T percent, 
                                            IN CONST CHAR_T *devid, 
                                            IN CONST DEV_TYPE_T tp);

FeaturesExplanation( Summary )

Report the upgrade progress.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_dev_upgd_result_report

OPERATE_RET tuya_iot_dev_upgd_result_report(IN CONST CHAR_T *dev_id, 
                                            IN CONST DEV_TYPE_T type, 
                                            IN CONST INT_T result);

FeaturesExplanation( Summary )

Report device upgrade results.

parameter Explanation( Parameters )

TI_UPGRD_STAT_S definition:

#define TUS_RD 1         //Upgrade is ready
#define TUS_UPGRDING 2   // upgrading
#define TUS_UPGRD_FINI 3  // update completed
#define TUS_UPGRD_EXEC 4  // Leave after upgrade

Return Value(Return Values)

tuya_iot_refuse_upgrade

OPERATE_RET tuya_iot_refuse_upgrade(IN CONST FW_UG_S *fw, IN CONST CHAR_T *dev_id);

FeaturesExplanation( Summary )

Stop the upgrade during the upgrade process.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_gw_version_update

OPERATE_RET tuya_iot_gw_version_update(IN GW_PERMIT_DEV_TP_T type, IN CONST CHAR_T *ver);

FeaturesExplanation( Summary )

After the upgrade is complete, update the gateway or gateway adapter firmware version number.

parameter Explanation( Parameters )

GW_PERMIT_DEV_TP_T definition:

#define GP_DEV_ZB DEV_ZB_SNGL    // zigbee 
#define GP_DEV_OTHER DEV_OTHER_SNGL // other
#define GP_DEV_BLE DEV_BLE_SNGL     // Bluetooth
#define GP_DEV_INFRARED DEV_INFRARED_SNGL //Infrared
#define GP_DEV_MCU  DEV_NM_NOT_ATH_SNGL // MCU

Return Value(Return Values)

Device function points (dp point)

Tuya provides an MQTT-based network application protocol to implement device control and status reporting. MQTT Yes is a lightweight publish-subscribe mode message transmission protocol, specifically designed for IoT applications in low-bandwidth and unstable network environments.

tuya_SDK encapsulates the implementation of the MQTT protocol layer and is presented in the form of function points (hereinafter referred to as dp points). It supports numeric, Boolean, enumerated, String, fault, and RAW data, as simple as defining C variables.

Developers need to create corresponding function points on Tuya Developer Platform according to the device functions, and create a new dp point Description: https://docs.tuya.com/cn/product/function.html

Features

1.Currently supports the creation of a maximum of 35 dp per product. Please use RAW data to implement complex functions; 2.Obj type: bool type, value type, string type, enum type, fault type (bitmap), tuya_SDK will filter the continuously reported values, the same will not be allowed Upload.

DP Structure

TY_RECV_OBJ_DP_S

typedef struct {
    DP_CMD_TYPE_E cmd_tp;
    DP_TRANS_TYPE_T dtt_tp;
    CHAR_T *cid;
    CHAR_T *mb_id;
    UINT_T dps_cnt;
    TY_OBJ_DP_S dps[0];
} TY_RECV_OBJ_DP_S;

FeaturesExplanation(Summary)

OBJ function point information command callback.

Member Explanation

TY_RECV_RAW_DP_S

typedef struct {
    DP_CMD_TYPE_E cmd_tp;
    DP_TRANS_TYPE_T dtt_tp;
    CHAR_T *cid;
    BYTE_T dpid;
    CHAR_T *mb_id;
    UINT_T len;
    BYTE_T data[0];
} TY_RECV_RAW_DP_S;

FeaturesExplanation(Summary)

DP point data structure of RAW type.

Member Explanation

TY_DP_QUERY_S

typedef struct {
    CHAR_T *cid;
    UINT_T cnt;
    BYTE_T dpid[0];
} TY_DP_QUERY_S;

FeaturesExplanation(Summary)

Query DP point information.

Member Explanation

Device command to issue callback

dev_obj_dp_cb

VOID dev_obj_dp_cb(IN CONST TY_RECV_OBJ_DP_S *dp);

FeaturesExplanation( Summary )

The user registers the callback function dev_obj_dp_cb in [TY_IoT_CBS_S] (# TY_IoT_CBS_S) . OBJ function point callback.

parameter Explanation( Parameters )

Return Value(Return Values)

dev_raw_dp_cb

VOID dev_raw_dp_cb(IN CONST TY_RECV_RAW_DP_S *dp);

FeaturesExplanation( Summary )

The user registers the callback function dev_raw_dp_cb in TY_IoT_CBS_S .Callback for transparent function points.

parameter Explanation( Parameters )

Return Value(Return Values)

dev_dp_query_cb

VOID dev_dp_query_cb(IN CONST TY_DP_QUERY_S *dp_qry);

FeaturesExplanation( Summary )

The user registers the callback function dev_dp_query_cb in TY_IoT_CBS_S .Device specific data query entry callback.

parameter Explanation( Parameters )

Return Value(Return Values)

Device status report

dev_report_dp_json_async

OPERATE_RET dev_report_dp_json_async(IN CONST CHAR_T *dev_id, 
                                     IN CONST TY_OBJ_DP_S *dp_data,
                                     IN CONST UINT_T cnt);

FeaturesExplanation( Summary )

Asynchronous way, report function point information.

parameter Explanation( Parameters )

Return Value(Return Values)

dev_report_dp_raw_sync

OPERATE_RET dev_report_dp_raw_sync (IN CONST CHAR_T *dev_id, 
                                    IN CONST BYTE_T dpid, 
                                    IN CONST BYTE_T *data,
                                    IN CONST UINT_T len, 
                                    IN CONST UINT_T timeout);

FeaturesExplanation( Summary )

The device transparently transmits data to the reporting interface synchronously. The caller guarantees the reliability of data reporting.

parameter Explanation( Parameters )

Return Value(Return Values)

dev_report_dp_stat_sync

#define dev_report_dp_stat_sync(dev_id, dp_data, cnt, timeout) \
    dev_report_dp_stat_sync_extend(dev_id, dp_data, cnt, timeout, TRUE)
OPERATE_RET dev_report_dp_stat_sync_extend(IN CONST CHAR_T *dev_id,
                                           IN CONST TY_OBJ_DP_S *dp_data,
                                           IN CONST UINT_T cnt,
                                           IN CONST UINT_T timeout, 
                                           IN CONST BOOL_T enable_auto_retrans);

FeaturesExplanation( Summary )

Device structured data synchronous reporting interface. The caller guarantees the reliability of data reporting. It is usually used for reporting statistical data.

parameter Explanation( Parameters )

Return Value(Return Values)

Sub-device management

Sub-device distribution network

Data interaction diagram

  • This picture is to add a sub-device from the APP side of the mobile phone.

  • The gateway can also call tuya_iot_gw_bind_dev to bind directly.

  • The communication protocol between the sub-device and the gateway is implemented by the user.

Interface & callback description

TY_IoT_GW_CBS_S

typedef struct {
    GW_PERMIT_ADD_DEV_CB gw_add_dev_cb;
    GW_DEV_DEL_CB gw_del_cb;
    GW_DEV_GRP_INFM_CB gw_dev_grp_cb;
    GW_DEV_SCENE_INFM_CB gw_dev_scene_cb;
    GW_BIND_DEV_INFORM_CB gw_ifm_cb;
} TY_IoT_GW_CBS_S;

FeaturesExplanation(Summary)

The gateway enables the addition of sub-devices. This callback function is used to notify the scene, group and sub-device binding of deleting the sub-device.

Member Explanation

gw_add_dev_cb

BOOL_T gw_add_dev_cb(IN CONST GW_PERMIT_DEV_TP_T tp, 
                     IN CONST BOOL_T permit, 
                     IN CONST UINT_T timeout);

FeaturesExplanation( Summary )

The user registers the callback function gw_add_dev_cb in TY_IoT_GW_CBS_S . When adding a sub-device, the function of enabling device access to the network is implemented in this callback.

parameter Explanation( Parameters )

Return Value(Return Values)

gw_del_cb

VOID gw_del_cb(IN CONST CHAR_T *dev_id);

FeaturesExplanation( Summary )

The user registers the callback function gw_del_cb in TY_IoT_GW_CBS_S .When the sub-device is deleted, the user is notified via this callback.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_gw_bind_dev

OPERATE_RET tuya_iot_gw_bind_dev(IN CONST GW_PERMIT_DEV_TP_T tp, 
                                 IN CONST USER_DEV_DTL_DEF_T uddd, 
                                 IN CONST CHAR_T *id,
                                 IN CONST CHAR_T *pk, 
                                 IN CONST CHAR_T *ver);

FeaturesExplanation( Summary )

Sub-device interface bound to the gateway. When TUYA APP enables the gateway to add sub-devices, call this interface to bind the discovered sub-devices.

parameter Explanation( Parameters )

Return Value(Return Values)

gw_bind_ifm_cb

VOID gw_bind_ifm_cb(IN CONST CHAR_T *dev_id, IN CONST OPERATE_RET op_ret);

FeaturesExplanation( Summary )

The user registers the callback function gw_bind_ifm_cb in TY_IoT_GW_CBS_S. When the sub-device is bound, the user is notified of the binding result through this callback.

parameter Explanation( Parameters )

Return Value(Return Values)

Unbind the subdevice

Interface & callback description

tuya_iot_gw_unbind_dev

OPERATE_RET tuya_iot_gw_unbind_dev(IN CONST CHAR_T *id);

FeaturesExplanation(Summary)

Unbind the subdevice

parameter Explanation( Parameters )

Return Value(Return Values)

Sub-device firmware upgrade (OTA)

Data interaction diagram

  • The communication between the sub-device and the gateway device layer is implemented by the customer. Here only briefly.

  • The upgrade progress report can be controlled by the user. Only when the gateway sends the firmware package to the sub-device, it will update the report progress.

  • TUYA Smart APP has a 60s timeout mechanism for firmware upgrade:It will update the message and retime. When receiving the progress of a package of the device each time; the application layer can report the upgrade progress by controlling the upgrade progress to prolong the APP timeout.

Interface & callback description

dev_ug_inform_cb

VOID dev_ug_cb(IN CONST CHAR_T *dev_id, IN CONST FW_UG_S *fw)

FeaturesExplanation( Summary )

The user registers the callback function dev_ug_cb in TY_IoT_CBS_S . Notification of OTA firmware upgrade of the child device. It indicates that there is an updateable sub-device firmware.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_upgrade_dev

OPERATE_RET tuya_iot_upgrade_dev_notify(IN CONST CHAR_T *devid, 
                                        IN CONST FW_UG_S *fw,
                                        IN CONST GET_FILE_DATA_CB get_file_cb,
                                        IN CONST UPGRADE_NOTIFY_CB upgrd_nofity_cb,
                                        IN CONST PVOID_T pri_data)

FeaturesExplanation( Summary )

Device firmware upgrade interface. It contains the upgrade of the main control device on the gateway and the sub-devices of each terminal.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_gw_subdevice_update

OPERATE_RET tuya_iot_gw_subdevice_update (IN CONST CHAR_T *id, IN CONST CHAR_T *ver);

FeaturesExplanation( Summary )

Update the firmware version number of the sub-device.

parameter Explanation( Parameters )

Return Value(Return Values)

Sub-device online management

  • Enable tuya_SDK's heartbeat detection mechanismZ.

As shown below, this is a diagram of the interface call when the SDK's heartbeat keep-alive mechanism is turned on.

tuya_iot_dev_online_stat_update

OPERATE_RET tuya_iot_dev_online_stat_update(IN CONST CHAR_T *dev_id, IN CONST BOOL_T online);

FeaturesExplanation( Summary )

The gateway updates the online / offline status of the child device.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_sys_mag_hb_init

OPERATE_RET tuya_iot_sys_mag_hb_init(IN CONST DEV_HEARTBEAT_SEND_CB hb_send_cb);

FeaturesExplanation( Summary )

Enable heartbeat management capabilities of sub-devices.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_set_dev_hb_timeout

OPERATE_RET tuya_iot_set_dev_hb_timeout (IN CONST CHAR_T *dev_id, IN CONST TIME_S hb_timeout_time);

FeaturesExplanation( Summary )

Set the heartbeat timeout time of the sub-device. If the gateway does not receive the heartbeat of the sub-device within the set time, the gateway will set the sub-device offline.

parameter Explanation( Parameters )

Return Value(Return Values)

tuya_iot_fresh_dev_hb

OPERATE_RET tuya_iot_fresh_dev_hb(IN CONST CHAR_T *dev_id)

FeaturesExplanation( Summary )

When the gateway receives the heartbeat information of the sub-device, it calls this function to refresh the heartbeat state of the sub-device.

parameter Explanation( Parameters )

Return Value(Return Values)