Link SDK Access
Last updated
Last updated
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.
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.
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.
Support LINUX or ANDROID system.
Support TCP / IP protocol stack.
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.
For the directory structure and usage, please refer to the README.md
file in the product package.
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.
tuya_iot_init
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
FeaturesExplanation( Summary )
Obtain the TUYA networke SDK version information.
Parameter Explanation( Parameters )
Return Value(Return Values)
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
Features Explanation( Summary )
Wi-Fi product information.
Member Explanation
tuya_iot_set_wf_gw_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
FeaturesExplanation( Summary )
Wi-Fi gateway initialization interface.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_iot_wf_gw_dev_init
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
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:
Return Value(Return Values)
Non-Wi-Fi configuration device interface,Reference "tuya_iot_base_api.h"
GW_PROD_INFO_S
FeaturesExplanation( Summary )
Gateway product information.
Member Explanation
tuya_iot_set_gw_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
FeaturesExplanation( Summary )
Networking module gateway initialization interface.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_iot_gw_dev_init
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
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:
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
Parameter explanation reference tuya_iot_set_wf_gw_prod_info function section.
tuya_iot_wired_Wi-Fi_gw_init
FeaturesExplanation( Summary )
Wired + Wi-Fi gateway initialization interface.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_iot_wired_Wi-Fi_gw_dev_init
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 :
GW_WF_CFG_MTHD_SEL definition:
In Linux / Android, select GWCM_OLD_PROD.
GW_WF_START_MODE definition:
parameter attr the user sets the adapter that he supports.For example, the gateway supports zigbee, it can be set to:
Return Value(Return Values)
tuya_iot_reg_get_wired_Wi-Fi_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
Features Explanation
Set up wired and Wi-Fi network interfaces.
parameter Explanation( Parameters )
Return Value(Return Values)
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.
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
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
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
FeaturesExplanation( Summary )
Obtain the IP address of the wired network card
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_hal_wired_station_conn
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
FeaturesExplanation( Summary )
Get the MAC address of the wired network interface. Optional implementation.
parameter Explanation( Parameters )
Return Value(Return Values)
hwl_bnw_set_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
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
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
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
FeaturesExplanation( Summary )
Get the network status.
parameter Explanation( Parameters )
Return Value(Return Values)
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
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
FeaturesExplanation( Summary )
Wired + Wi-Fi reset. same as tuya_iot_wf_gw_unactive 。
tuya_iot_wf_fast_get_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:
Return Value(Return Values)
tuya_iot_wired_Wi-Fi_fast_get_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
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:
Return Value(Return Values)
AP distribution network
Implement the interface that the user needs
After the device is reset, make the SDK enter the network to be configured state
tuya_iot_set_user_def_ap_if
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
FeaturesExplanation(Summary)
AP configuration structure.
Member Explanation
User-implemented Interface
tuya_hal_Wi-Fi_get_ip
FeaturesExplanation( Summary )
Obtain the IP address of the Wi-Fi network card.
parameter Explanation( Parameters )
Type definition of WF_IF_E:
Return Value(Return Values)
tuya_hal_Wi-Fi_get_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
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
FeaturesExplanation( Summary )
Set Wi-Fi working mode.
parameter Explanation( Parameters )
The working mode of Wi-Fi is defined as follows:
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
FeaturesExplanation( Summary )
Get Wi-Fi working mode.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_hal_Wi-Fi_station_connect
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
FeaturesExplanation
Disconnect the Wi-Fi device and router.
parameter Explanation
Return Value
tuya_hal_Wi-Fi_station_get_conn_ap_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
FeaturesExplanation( Summary )
Get the network status of the Wi-Fi device.
parameter Explanation( Parameters )
WF_STATION_STAT_E Explanation:
Return Value(Return Values)
tuya_hal_Wi-Fi_set_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
FeaturesExplanation( Summary )
Start the Wi-Fi AP hotspot.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_hal_Wi-Fi_ap_stop
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
FeaturesExplanation( Summary )
Get AP list information in the current environment.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_hal_Wi-Fi_assign_ap_scan
FeaturesExplanation( Summary )
Get the AP information of the specified SSID.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_hal_Wi-Fi_release_ap
FeaturesExplanation( Summary )
Release processing of allocated resources.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_hal_Wi-Fi_set_cur_channel
FeaturesExplanation( Summary )
Set the Wi-Fi working channel.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_hal_Wi-Fi_get_cur_channel
FeaturesExplanation( Summary )
Get the current working channel.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_hal_Wi-Fi_sniffer_set
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
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)
The user can reset the gateway through the APP.
gw_reset_cb
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:
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)
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 .
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.
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
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.
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.
FW_UG_S
FeaturesExplanation(Summary)
Upgraded firmware information.
Member Explanation
gw_ug_cb
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
FeaturesExplanation( Summary )
Networking module firmware upgrade processing interface.
parameter Explanation( Parameters )
Return Value(Return Values)
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
FeaturesExplanation( Summary )
Report the upgrade progress.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_iot_dev_upgd_result_report
FeaturesExplanation( Summary )
Report device upgrade results.
parameter Explanation( Parameters )
TI_UPGRD_STAT_S definition:
Return Value(Return Values)
tuya_iot_refuse_upgrade
FeaturesExplanation( Summary )
Stop the upgrade during the upgrade process.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_iot_gw_version_update
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:
Return Value(Return Values)
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.
TY_RECV_OBJ_DP_S
FeaturesExplanation(Summary)
OBJ function point information command callback.
Member Explanation
TY_RECV_RAW_DP_S
FeaturesExplanation(Summary)
DP point data structure of RAW type.
Member Explanation
TY_DP_QUERY_S
FeaturesExplanation(Summary)
Query DP point information.
Member Explanation
dev_obj_dp_cb
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
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
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)
dev_report_dp_json_async
FeaturesExplanation( Summary )
Asynchronous way, report function point information.
parameter Explanation( Parameters )
Return Value(Return Values)
dev_report_dp_raw_sync
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
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)
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
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
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
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
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
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)
Interface & callback description
tuya_iot_gw_unbind_dev
FeaturesExplanation(Summary)
Unbind the subdevice
parameter Explanation( Parameters )
Return Value(Return Values)
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
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
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
FeaturesExplanation( Summary )
Update the firmware version number of the sub-device.
parameter Explanation( Parameters )
Return Value(Return Values)
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
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
FeaturesExplanation( Summary )
Enable heartbeat management capabilities of sub-devices.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_iot_set_dev_hb_timeout
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
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)
tuya_iot_dev_traversal
FeaturesExplanation( Summary )
Sub-device traversal. Through this interface, all sub-devices under the gateway can be traversed.
parameter Explanation( Parameters )
Return Value(Return Values)
gw_dev_grp_cb
FeaturesExplanation( Summary )
The user registers the callback function gw_dev_grp_cb in TY_IoT_GW_CBS_S . In this callback, the group operation processing command is realized.
parameter Explanation( Parameters )
Return Value(Return Values)
gw_dev_scene_cb
FeaturesExplanation( Summary )
The user registers the callback function gw_dev_scene_cb in TY_IoT_GW_CBS_S .The scene processing command feature is implemented in this callback.
parameter Explanation( Parameters )
Return Value(Return Values)
dev_reset_cb
FeaturesExplanation( Summary )
The user registers the callback function dev_reset_cb in TY_IoT_CBS_S .In this callback, reset processing of the sub-device needs to be handled.
parameter Explanation( Parameters )
Return Value(Return Values)
tuya_iot_app_cbs_init
FeaturesExplanation( Summary )
Initialize the application callback. Currently only supports users to register local log to get callback.
parameter Explanation( Parameters )
Return Value(Return Values)
Notes (Notes)
Log management is essential for equipment maintenance and troubleshooting.It is recommended to leave about 5M ~ 10M space on the device side to save the device operation log.When the device fails, you can pull the device log on the developer platform through the gateway device ID information.** For the convenience of equipment problem analysis, this function must be implemented. **
Fake code
It is convenient for developers to locate problems during debugging and will be continuously updated.
Error code definition view: tuya_cloud_error_code.h
Version
Compilation / Revision Instructions
Revision Person
Revision Date
Remarks
1.0.0
Create document
Liu Bo
20200327
Parameter Name
Explanation
fs_storge_path
Assign a readable and writable path to the SDK. The path length cannot be greater than 110 bytes.
Return Value
Explanation
OPRT_OK
Success
Error Code
Fail return Error Code
Parameter Name
Explanation
VOID
\
Return Value
Explanation
SDK Message String
Including SDK compile time, platform, version number, enabled features, etc.
Member name
Explanation
gw_status_cb
Gateway status callback.
gw_ug_cb
Reference gw_ug_cb
gw_reset_cb
Reference gw_reset_cb
dev_obj_dp_cb
Reference dev_obj_dp_cb
dev_raw_dp_cb
Reference dev_raw_dp_cb
dev_dp_query_cb
dp point query callback
dev_ug_cb
Reference dev_ug_cb
dev_reset_cb
Reference dev_reset_cb
Member name
Explanation
uuid
uuid string. Must not be NULL. The length is less than or equal to 16 bytes.
auth_key
auth_key string. Must not be NULL. The length is less than or equal to 32 bytes.
ap_ssid
SSID prefix. The length is less than or equal to 16 bytes. If set to NULL, the ssid prefix is "Smartlife-" by default.
ap_passwd
The length is less than or equal to 16 bytes. The default is NULL.
Parameter Name
Explanation
wf_prod_info
Gateway product information. Reference WF_GW_PROD_INFO_S Explanation。
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
cfg
Wi-Fi configuration method
start_mode
Wi-Fi distribution mode
cbs
Callback registered by the user.Reference TY_IoT_CBS_S
gw_cbs
Gateway callback registered by the user.Reference TY_IoT_GW_CBS_S
product_key
Obtained when the platform creates a product
wf_sw_ver
Firmware version number
attr
Gateway adapter configuration list
attr_num
Number of gateway adapter configuration lists
Return Value
Explanation
OPRT_OK
Success
Error Code
Fail return Error Code
Parameter Name
Explanation
nw_stat_cb
Register network status callback function
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Member name
Explanation
uuid
uuid string. Must not be NULL.
auth_key
auth_key string. Must not be NULL.
Parameter Name
Explanation
prod_info
product information. Reference GW_PROD_INFO_S
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
cbs
The user needs to register the callback function array.Reference TY_IoT_CBS_S
gw_cbs
The user needs to register the callback function array of gateway.Reference TY_IoT_GW_CBS_S
product_key
The product ID of the product when it was created on the platform.
sw_ver
The firmware version number.
attr
Gateway adapter configuration list.
attr_num
The number of gateway adapter configuration lists.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
nw_stat_cb
Register the network change callback function
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
net_mode
Network Type
cfg
Wi-Fi configuration method
start_mode
Wi-Fi distribution mode
cbs
The user needs to register the callback function array.Reference TY_IoT_CBS_S
gw_cbs
Array of gateway callback functions that users need to register.Reference TY_IoT_GW_CBS_S
product_key
Obtained when the platform is created
wf_sw_ver
Firmware version number
attr
Gateway adapter configuration list
attr_num
Number of gateway adapter configuration lists
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
net_mode
Network Type
cfg
Wi-Fi configuration method
sw_ver
Device firmware version string, format :xx.xx.xx
cbs
The user needs to register the callback function array.Reference TY_IoT_CBS_S
gw_cbs
Gateway callback
product_key
Array of gateway callback functions that users need to register.Reference TY_IoT_GW_CBS_S
wf_sw_ver
Firmware version number
attr
Gateway adapter configuration list
attr_num
Number of gateway adapter configuration lists
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
nw_stat_cb
Register callback function for network status change
wf_nw_stat_cb
Register callback function for Wi-Fi network status change
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
wired_net_name
Wired network interface name
Wi-Fi_net_name
Wi-Fi interface network name
Return Value
Explanation
VOID
\
Parameter Name
Explanation
VOID
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
ip
IP information structure.Network card IP address, subnet mask, gateway.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
VOID
Return Value
Explanation
TRUE
The device is online
FALSE
The device is disconnected from the network.
Parameter Name
Explanation
mac
The MAC information of the obtained network interface.
Return Value
Explanation
OPRT_OK
Get success
Error Code
Get failed
Parameter Name
Explanation
mac
Set the MAC address of the wired network card.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
ssid
The ssid of the Wi-Fi router.
password
The password of the Wi-Fi router.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
VOID
Return Value
Explanation
TRUE
If the hardware has a Wi-Fi interface, the user wants to connect to Wi-Fi.
FALSE
If the hardware does not have a Wi-Fi interface, you need to return FALSE if you do not want to connect to Wi-Fi.
Parameter Name
Explanation
rssi
rssi saves the obtained rssi information.
Return Value
Explanation
OPRT_OK
Get Success
Other
Get failed
Parameter Name
Explanation
status
network status. Networking is TRUE, otherwise it is FALSE.
Return Value
Explanation
OPRT_OK
Get success
Other
Get failed
Parameter Name
Explanation
VOID
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
nc_type
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
wf_nw_cfg_err_code_cb
Callback function for obtaining error code generated by Wi-Fi distribution
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
ssid
Custom SSID prefix
passwd
AP password
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Member name
Explanation
ssid
ssid
s_len
ssid length
passwd
password
p_len
password length
chan
Wi-Fi working channel
md
Wi-Fi encryption type
ssid_hidden
hidden SSID
max_conn
Maximum number of station equipment connections
ms_interval
broadcast interval
Parameter Name
Explanation
wf
The working type of the Wi-Fi network card.
ip
Save the obtained IP information structure, the information contains IP, submask, gateway.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
wf
Working type of Wi-Fi network card.
mac
Save the obtained MAC address.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
wf
The working type of the Wi-Fi network card.
mac
The set MAC address.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
wf
Set the Wi-Fi device working mode.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
mode
It has the same meaning as the parameter mode in hwl_wf_wk_mode_set.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
ssid
The ssid connected to the router.
password
Connect the password of the router.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
rssi
Obtained rssi.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
stat
User needs to fill in statistics.Reference WF_STATION_STAT_E Explanation。
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
p_country_code
Wi-Fi devices work in different countries, with different frequencies and channel signal strengths.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
cfg
Set the AP according to the passed function "parameter cfg".Reference WF_AP_CFG_IF_S
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
VOID
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
ap_ary
List of AP information in the current environment.
num
The length of the AP information list in the current environment.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
ssid
The ssid of the specified AP.
ap
Get the specified AP information.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
ap
Release the content applied here: tuya_hal_Wi-Fi_all_ap_scan and tuya_hal_Wi-Fi_assign_ap_scan
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
chan
Channels that require Wi-Fi equipment to work.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
chan
Fill the working channel of the current Wi-Fi device.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
en
Enable / disable Wi-Fi sniffer mode.
cb
Notify callback function. The captured air 802.11 data contains the frame header.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
ssid
The ssid used by the network in AP mode.
passwd
The password used for network configuration in AP mode.
token
Token used in distribution network in AP mode.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
type
Return Value
Explanation
VOID
Member name
Explanation
tp
Firmware type
type
UPGRADE_TYPE_NORMAL : Ordinary upgrade UPGRADE_TYPE_SILENT : Forced upgrade
fw_url
URL of firmware download
sw_ver
Firmware version number
file_size
Firmware size
fw_hmac
Firmware HMAC check code
Parameter Name
Explanation
fw
Firmware information.Reference FW_UG_S
Return Value
Explanation
VOID
Parameter Name
Explanation
fw
Firmware information
get_file_cb
Callback function for download content storage
upgrd_nofity_cb
Callback function to notify the upgrade status of the application
pri_data
Parameters passed to get_file_cb and upgrd_nofity_cb
notify
Choose whether to report upgrade progress by SDK
download_buf_size
Download the maximum cache, in bytes
Return Value
Explanation
OPRT_OK
Success
Error Code
Fail return Error Code
Parameter Name
Explanation
percent
Upgrade progress value. 0 ~ 99
devid
When it is a child device, the ID of the child device is passed in; When it is a gateway, NULL
tp
Equipment type
Return Value
Explanation
OPRT_OK
Success
Error Code
Fail return Error Code
Parameter Name
Explanation
devid
When it is a child device, the ID of the child device is passed in; When it is a gateway, NULL
tp
Equipment type
result
Upgrade result
Return Value
Explanation
OPRT_OK
Success
Error Code
Fail return Error Code
Parameter Name
Explanation
fw
Firmware information.Reference FW_UG_S
devid
When it is a child device, the ID of the child device is passed in; When it is a gateway, NULL
Return Value
Explanation
OPRT_OK
Success
Error Code
Fail return Error Code
Parameter Name
Explanation
type
Gateway type
ver
Firmware version number
Return Value
Explanation
OPRT_OK
Success
Error Code
Fail return 的Error Code
Member name
Explanation
cmd_tp
Command type, how the command is generated
dtt_tp
Type of transmission
cid
CID is NULL, expressed as a gateway device is not empty, expressed as a sub-device.
mb_id
When dtt_tp is multicast, mb_id is the group ID
dps_cnt
Number of function point structure arrays
dps_cnt
Function point structure array
Parameter Name
Explanation
cmd_tp
Command type, how the command is generated
dtt_tp
Type of transmission
cid
CID is NULL, expressed as a gateway device is not empty, expressed as a sub-device.
dpid
DP point ID 。
mb_id
When dtt_tp is multicast, mb_id is the group ID
len
Transparent transmission data length
data
Transparent data cache
Parameter Name
Explanation
cid
CID is NULL, expressed as a gateway device is not empty, expressed as a sub-device.
cnt
The number of dp points. If it is equal to 0, it means all DP points.
dpid
The ID of the DP point to be queried.
Parameter Name
Explanation
dp
The SDK calls back the user's OBJ type function point data. Reference TY_RECV_OBJ_DP_S
Return Value
Explanation
Parameter Name
Explanation
dp
The SDK calls back the user's RAW function point data.Reference TY_RECV_RAW_DP_S
Return Value
Explanation
Parameter Name
Explanation
dp_qry
Reference TY_DP_QUERY_S
Return Value
Explanation
Parameter Name
Explanation
dev_id
Device ID
dp_data
Function point data structure
cnt
Number of dp_data structure arrays
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
dev_id
Device ID
dpid
Function point ID
data
Transparent data
len
Transparent data length
timeout
Function blocking timeout
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
dev_id
Device ID
dp_data
Function point information structure array.TY_OBJ_DP_S
cnt
The length of the DP status array
timeout
Function blocking timeout
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Member name
Explanation
gw_add_dev_cb
reference gw_add_dev_cb
gw_del_cb
reference gw_del_cb
gw_dev_grp_cb
reference gw_dev_grp_cb
gw_dev_scene_cb
reference gw_dev_scene_cb
gw_ifm_cb
reference gw_ifm_cb
Parameter Name
Explanation
tp
Sub-device type
permit
Whether to add sub-devices.TRUE true is allowed;FALSE is forbidden.
timeout
The timeout period of the distribution network. ** Unit in seconds **
Return Value
Explanation
TRUE
Successful operation
FALSE
failure
Parameter Name
Explanation
dev_id
The ID of the sub-device that was deleted.
Return Value
Explanation
Parameter Name
Explanation
tp
Sub-device type.
uddd
The device type is defined by the user, which distinguishes different types of devices.
id
Sub-device id. The length cannot exceed 25 bytes.
pk
Sub-device product key。The length cannot exceed 16 bytes.
ver
Sub-device firmware version。The length cannot exceed 10 bytes.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
dev_id
The ID of the bound child device.
op_ret
Binding results. OPRT_OK means to bind Success. Other means the binding failed.
Return Value
Explanation
Parameter Name
Explanation
dev_id
The ID of the sub-device that needs to be unbound from the gateway.
Return Value
Explanation
Parameter Name
Explanation
dev_id
Sub-device ID with new firmware that can be updated.
fw
Return Value
Explanation
Parameter Name
Explanation
devid
Device id string
fw
Upgraded firmware information.Reference FW_UG_S
get_file_cb
Implemented in this callback, download content storage
upgrd_nofity_cb
Notification function that is called back when the download is complete. In this callback, the upgrade function of the device needs to be called.
pri_data
Parameters passed to get_file_cb and upgrd_nofity_cb. For example, download the upgrade file handle.
Return Value
Explanation
OPRT_OK
Success
Error Code
Fail return Error Code
Parameter Name
Explanation
dev_id
Sub-device ID. ** Cannot exceed 25 bytes. **
ver
Subdevice firmware version number. ** Refer to the TUYA definition of version number format in the article. **
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
dev_id
Sub-device ID.
online
online status. TRUE is online, FALSE is offline.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
hb_send_cb
The gateway checks all sub-devices every 3 seconds. If the sub-device is within the heartbeat packet timeout and the sub-device does not send a heartbeat to the gateway, the gateway will set the sub-device offline. Notify users at least three times via hb_send_cb.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
dev_id
Sub-device ID.
hb_timeout_time
Heartbeat timeout time, in seconds. If set to 0xffffffff, the sub-device will be skipped for heartbeat check and will always be online.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
dev_id
sub-device ID
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
iterator
Temporarily save the linked list. The user only needs to define a null pointer.
Return Value
Explanation
DEV_DESC_IF_S
Pointer to the structure of device information. The user can read device information from it.
NULL
The device information has been read.
Parameter Name
Explanation
action
The type of operation for the group. Add and delete group operations.
dev_id
The ID of the sub-device that joined the group grp_id.
grp_id
Group ID .
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
action
The operation type of the scene. Add and delete, and perform scene operations.
dev_id
Sub-device ID.
grp_id
Group ID .
sce_id
Scene ID.
Return Value
Explanation
OPRT_OK
Successful operation
Error Code
Fail return Error Code
Parameter Name
Explanation
dev_id
The ID of the sub-device that needs to be reset.
type
Reset type.
Return Value
Explanation
VOID
Parameter Name
Explanation
app_cbs
Get local log callback name.
Return Value
Explanation
VOID
Error Code
Reason
Solution
-944
When reporting function points, the corresponding DPID is not under the product
Login to the Tuya IoT platform to confirm
-916
The device is disconnected from Tuya Cloud MQTT server long connection
Check whether the device is connected to the external network
-926
When the device reports MQTT data, it waits for the server puback to time out
Check the device network condition or reduce the reporting frequency
-945
DP point attribute values do not match
Check whether the reported DP point attribute value is consistent with the platform definition