Link SDK Access
Tuya Gateway Link SDK Development Manual
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
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
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)
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
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)
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
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)
Gateway Reset
APP Reset Geteway
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)
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
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)
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
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)
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
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
Device command to issue callback
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)
Device status report
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)
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
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)
Unbind the subdevice
Interface & callback description
tuya_iot_gw_unbind_dev
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
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)
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
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)