Last Updated on : 2024-11-20 08:51:47download
This topic describes the APIs used to implement the basic functionality of a gateway.
typedef struct {
GW_APP_LOG_PATH_CB gw_app_log_path_cb;
}TY_IOT_APP_CBS_S;
Functional description
The application callback, such as requesting the locally stored logs.
Member description
Member | Description |
---|---|
gw_app_log_path_cb | For more information, see gw_app_log_path_cb. |
typedef struct {
CHAR_T *uuid;
CHAR_T *auth_key;
} GW_PROD_INFO_S;
Functional description
The gateway authorization information, applying to the wireless connection SDK.
Member description
Member | Description |
---|---|
uuid | The UUID string. It cannot be NULL. |
auth_key | The AuthKey string. It cannot be NULL. |
typedef struct {
CHAR_T *uuid;
CHAR_T *auth_key;
CHAR_T *ap_ssid;
CHAR_T *ap_passwd;
} WF_GW_PROD_INFO_S;
Functional description
The gateway authorization information, applying to the wired connection SDK.
Member description
Member | Description |
---|---|
uuid | The UUID string. It cannot be NULL. Its length must be less than or equal to 16 bytes. |
auth_key | The AuthKey string. It cannot be NULL. Its length must be less than or equal to 32 bytes. |
ap_ssid | The SSID prefix. Its length must be less than or equal to 16 bytes. If it is set to NULL, the SSID prefix defaults to SmartLife-XXXX where XXXX is the MAC address. |
ap_passwd | Its length must be less than or equal to 16 bytes. It defaults to NULL. |
typedef struct {
/** attach ota channel */
GW_PERMIT_DEV_TP_T tp;
/** attach version, format xx.xx.xx */
CHAR_T ver[SW_VER_LEN+1];
}GW_ATTACH_ATTR_T;
Functional description
The version information of the module that is connected to the gateway.
Member description
Member | Description |
---|---|
tp | The update channel. Its value must match the update channel you configure for the custom firmware on the Tuya Developer Platform. |
ver | The version number. |
typedef struct {
VOID (*gw_reset_cb)(GW_RESET_TYPE_E type);
VOID (*gw_reboot_cb)(VOID);
VOID (*gw_upgrade_cb)(CONST FW_UG_S *fw);
VOID (*gw_active_stat_cb)(GW_STATUS_E stat);
VOID (*gw_active_url_cb)(CHAR_T *url);
} TY_GW_INFRA_CBS_S;
Functional description
The callbacks used for firmware update, reset, restart, and activation.
Member description
Member | Description |
---|---|
gw_reset_cb | For more information, see gw_reset_cb. |
gw_reboot_cb | For more information, see gw_reboot_cb. |
gw_upgrade_cb | For more information, see gw_upgrade_cb. |
gw_active_stat_cb | For more information, see gw_active_stat_cb. |
gw_active_url_cb | For more information, see gw_active_url_cb. |
typedef struct {
GW_PERMIT_DEV_TP_T type;
TIME_T timeout;
GW_GET_NCP_VER_CB get_ver_cb;
} TY_GW_NCP_DETECT_S;
Functional description
Gets the version information of the module that is connected to the gateway.
Member description
Member | Description |
---|---|
type | The type of the module. Its value is associated with the update channel. |
timeout | The specified timeout, in seconds. If the gateway does not receive the version number of the module on a specific sub-device within the timeout period, it will not report the information of this module. |
get_ver_cb | A callback that reads the firmware version number. For more information, see GW_GET_NCP_VER_CB. |
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;
Functional description
The firmware update information.
Member description
Member | Description |
---|---|
tp | The type of the firmware. Its value is associated with the update channel. |
type | The update methods: UPGRADE_TYPE_NORMAL : Normal update. UPGRADE_TYPE_SILENT : Auto update. |
fw_url | The update download URL. |
sw_ver | The firmware version number. |
file_size | The size of the firmware update. |
fw_hmac | The firmware HMAC code. |
int tuya_os_intf_init(void)
Functional description
Initializes the OS layer of the SDK. This API must be called first after the SDK starts.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_init(IN CONST CHAR_T *fs_storge_path)
Functional description
Initializes the IoT layer of the SDK. This API must be called after the tuya_os_intf_init but before other APIs.
Parameter description
Parameter name | Description |
---|---|
fs_storge_path | The storage path that must be read/write. Its length must not exceed 110 bytes. |
Return value
Return value | Description |
---|---|
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_sdk_pre_init(BOOL_T is_gw)
Functional description
Preinitializes the service layer of the SDK.
Parameter description
Parameter name | Description |
---|---|
is_gw | tuya_iot_wf_sdk_init is used to identify whether a device is a gateway product.
|
Return value
Return value | Description |
---|---|
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_sdk_init(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)
Functional description
Initializes the service layer of the SDK, applying to the wired connection SDK.
Parameter description
Parameter name | Description |
---|---|
product_key | The product ID (PID) of the product that you create on the Tuya Developer Platform. |
sw_ver | The firmware version number. |
attr | The version information of the module that is connected to the gateway. For more information, see GW_ATTACH_ATTR_T. |
attr_num | The number of connected modules that support the OTA update feature. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_wf_sdk_init(IN CONST GW_WF_CFG_MTHD_SEL cfg,
IN CONST GW_WF_START_MODE start_mode,
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)
Functional description
Initializes the service layer of the SDK, applying to the wired connection SDK.
Parameter description
Parameter name | Description |
---|---|
cfg | The Wi-Fi work mode. |
start_mode | The pairing mode over the wireless network. |
product_key | The product ID (PID) of the product that you create on the Tuya Developer Platform. |
wf_sw_ver | The firmware version number. |
attr | The version information of the module that is connected to the gateway. For more information, see GW_ATTACH_ATTR_T. |
attr_num | The number of connected modules that support the OTA update feature. |
Return value
Return value | Description |
---|---|
OPRT_OK | Success |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_wired_wf_sdk_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 CHAR_T *product_key,
IN CONST CHAR_T *sw_ver,
IN CONST GW_ATTACH_ATTR_T *attr,
IN CONST UINT_T attr_num)
Functional description
Initializes the service layer of the SDK, applying to the wired and wireless combo connection SDK.
Parameter description
Parameter name | Description |
---|---|
net_mode | The types of network connection:
|
cfg | The types of Wi-Fi work mode:
|
start_mode | The types of pairing mode over the wireless network:
|
product_key | The product ID (PID) of the product that you create on the Tuya Developer Platform. |
wf_sw_ver | The firmware version number. |
attr | The version information of the module that is connected to the gateway. For more information, see GW_ATTACH_ATTR_T. |
attr_num | The number of connected modules that support the OTA update feature. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
VOID tuya_iot_app_cbs_init(IN CONST TY_IOT_APP_CBS_S *app_cbs)
Functional description
Registers the application callback, such as requesting the locally stored logs.
Parameter description
Parameter name | Description |
---|---|
app_cbs | The struct containing application callback. For more information, see TY_IOT_APP_CBS_S. |
Return value
Return value | Description |
---|---|
VOID | / |
CHAR_T *tuya_iot_get_sdk_info(VOID)
Functional description
Gets the information about the Tuya SDK for use.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
A string | The SDK information includes the build time, platform, version number, and enabled features. |
OPERATE_RET tuya_iot_set_gw_prod_info(IN CONST GW_PROD_INFO_S *prod_info)
Functional description
Sets the authorization information for the wired gateway. The authorization information must be obtained from the Tuya Developer Platform. Otherwise, the gateway cannot work as expected. This API applies to the wired connection SDK.
Parameter description
Parameter name | Description |
---|---|
prod_info | The authorization information. For more information, see GW_PROD_INFO_S. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_set_wf_gw_prod_info(IN CONST WF_GW_PROD_INFO_S *wf_prod_info)
Functional description
Sets the authorization information for the wireless gateway. The authorization information must be obtained from the Tuya Developer Platform. Otherwise, the gateway cannot work as expected. This API applies to the wireless connection SDK.
Parameter description
Parameter name | Description |
---|---|
wf_prod_info | The authorization information. For more information, see WF_GW_PROD_INFO_S. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_gw_unactive(VOID);
Functional description
Unbinds the gateway locally, applying to the wired connection SDK. This API does not erase the device data.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_wf_gw_unactive(VOID);
Functional description
Unbinds the gateway locally, applying to the wireless connection SDK. This API does not erase the device data.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_wired_wifi_gw_unactive(VOID);
Functional description
Unbinds the gateway locally, applying to the wired and wireless combo connection SDK. This API does not erase the device data.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_gw_reset(VOID);
Functional description
Unbinds the gateway locally, applying to the wired connection SDK. This API erases the device data.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_wf_gw_reset(VOID);
Functional description
Unbinds the gateway locally, applying to the wireless connection SDK. This API erases the device data.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_wired_wifi_gw_reset(VOID);
Functional description
Unbinds the gateway locally, applying to the wired and wireless combo connection SDK. This API erases the device data.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_sdk_reg_netstat_cb(IN CONST SDK_GET_NW_STAT_CB nw_stat_cb,
IN CONST SDK_WIRED_NW_STAT_CB wr_nw_stat_cb,
IN CONST SDK_WIFI_NW_STAT_CB wf_nw_stat_cb)
Functional description
Registers the callbacks for network status management.
Parameter description
Parameter name | Description |
---|---|
nw_stat_cb | A callback to invoke when the network status changes. For more information, see SDK_GET_NW_STAT_CB. |
wr_nw_stat_cb | A callback to invoke when the status of the wired connection changes. For more information, see SDK_WIRED_NW_STAT_CB. |
wf_nw_stat_cb | A callback to invoke when the status of the wireless connection changes. For more information, see SDK_WIFI_NW_STAT_CB. |
VOID tuya_iot_set_prod_ability(GW_ABI abi)
Functional description
Sets the capability of the gateway. It must be called before tuya_iot_sdk_init.
Parameter description
Parameter name | Description |
---|---|
abi | The types of the gateway capability:
|
Return value
Return value | Description |
---|---|
VOID | / |
OPERATE_RET tuya_iot_get_gw_stat(TY_GW_STAT_T *stat)
Functional description
Gets the activation state of the gateway.
Parameter description
Parameter name | Description |
---|---|
stat | The activation states:
|
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPEROPERATE_RET tuya_iot_httpc_common_post(IN CONST CHAR_T *api_name,
IN CONST CHAR_T *api_ver,
IN CHAR_T *post_data,
OUT ty_cJSON **pp_result)
Functional description
The HTTP POST method. It must be called after the gateway is activated.
Parameter description
Parameter name | Description |
---|---|
api_name | The API name. |
api_ver | The API version number. |
post_data | The payload. |
pp_result | The return result from the cloud, in JSON format. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_iot_httpc_download_file(IN CONST CHAR_T *url,
IN CONST UINT_T mlk_buf_len,
IN CONST GW_GET_FILE_DATA_CB cb,
IN PVOID_T priv_data,
IN CONST UINT_T total_len,
INOUT BYTE_T file_hmac[32])
Functional description
Downloads files from the cloud. It must be called after the gateway is activated.
Parameter description
Parameter name | Description |
---|---|
url | The URL. |
mlk_buf_len | The size of each packet when a large file is transferred in multiple packets. |
cb | The data reception callback. |
priv_data | The private data, used as the parameter of the callback. |
total_len | The total size of the file. |
file_hmac | The HMAC check value. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
VOID tuya_iot_enable_blemesh_compatible(VOID)
Functional description
Enables the Bluetooth mesh capability. If you do not choose the Bluetooth mesh protocol for your gateway product, you can call this API to enable the Bluetooth mesh feature for it. It must be called after the gateway is activated.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
VOID | / |
OPERATE_RET tuya_iot_dev_join_permit(GW_PERMIT_DEV_TP_T tp,
BOOL_T permit,
UINT_T timeout);
Functional description
Locally enables or disables sub-devices to join the network.
Parameter description
Parameter name | Description |
---|---|
tp | The device type. |
permit | Enable or disable joining the network. |
timeout | The specified timeout, in seconds. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_user_svc_init(CONST GW_INFRA_CBS_S *cbs)
Functional description
Initializes the user services.
Parameter description
Parameter name | Description |
---|---|
cb | The struct containing the user callback. For more information, see TY_GW_INFRA_CBS_S. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_user_svc_start(CONST VOID *cbs)
Functional description
Starts the user services.
Parameter description
Parameter name | Description |
---|---|
cbs | A reserved parameter. You can set it to NULL. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_user_ncp_ver_upload_reg(TY_GW_NCP_DETECT_S *ncp)
Functional description
Reports the version information of the module that is connected to the gateway, which is performed asynchronously after initialization. It works for the same purpose as the attr
in the tuya_iot_sdk_init. To use this API, make sure to set the attr
and attr_num
in tuya_iot_sdk_init to NULL and 0 respectively.
Parameter description
Parameter name | Description |
---|---|
ncp | A reserved parameter. You can set it to NULL. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_user_iot_get_gw_nw_stat(GW_NW_STAT_T *stat)
Functional description
Gets the network status of the gateway.
Parameter description
Parameter name | Description |
---|---|
stat | The network status:
|
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
VOID tuya_user_iot_set_gw_ext_stat(IN CONST GW_EXT_STAT_T ext_stat)
Functional description
Sets the extension state of the gateway.
Parameter description
Parameter name | Description |
---|---|
ext_stat | The extension states:
|
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_user_iot_wd_common_write(IN CONST CHAR_T *key,
IN CONST BYTE_T *value,
IN CONST UINT_T len)
Functional description
Writes key-value pair to the database.
Parameter description
Parameter name | Description |
---|---|
key | The unique ID. |
value | Binary data. |
len | Data length. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_user_iot_wd_common_read(IN CONST CHAR_T *key,
OUT BYTE_T **value,
OUT UINT_T *p_len)
Functional description
Reads key-value pair from the database.
Parameter description
Parameter name | Description |
---|---|
key | The unique ID. |
value | Binary data. Freeing memory is necessary. |
len | Data length. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_user_iot_wd_common_delete(IN CONST CHAR_T *key)
Functional description
Deletes key-value pair from the database.
Parameter description
Parameter name | Description |
---|---|
key | The unique ID. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
OPERATE_RET tuya_user_iot_set_country_code(CHAR_T *country_code)
Functional description
Sets the country code.
Parameter description
Parameter name | Description |
---|---|
country_code | Follows ISO 3166-1 country code standard, such as US and CN. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
typedef VOID (*SDK_GET_NW_STAT_CB)(IN CONST SDK_NW_STAT_T stat)
Functional description
A callback to invoke when the network status changes.
Parameter description
Parameter name | Description |
---|---|
stat | The network status:
|
Return value
Return value | Description |
---|---|
VOID | / |
typedef VOID (*SDK_WIRED_NW_STAT_CB)(IN CONST SDK_WIRED_NW_STAT_T stat)
Functional description
A callback to invoke when the status of the wired connection changes.
Parameter description
Parameter name | Description |
---|---|
stat | The status of the wired network:
|
Return value
Return value | Description |
---|---|
VOID | / |
typedef VOID (*SDK_WIFI_NW_STAT_CB)(IN CONST SDK_WIFI_NW_STAT_T stat)
Functional description
A callback to invoke when the status of the wireless connection changes.
Parameter description
Parameter name | Description |
---|---|
stat | The status of the wireless network:
|
Return value
Return value | Description |
---|---|
VOID | / |
typedef OPERATE_RET (*GW_GET_NCP_VER_CB)(OUT CHAR_T *ver)
Functional description
A callback to invoke when the firmware version number of the module is read.
Parameter description
Parameter name | Description |
---|---|
ver | The firmware version number. |
Return value
Return value | Description |
---|---|
OPRT_OK | Operation succeeded. |
Error code | For more information about the error code, see tuya_error_code.h . |
VOID gw_reset_cb(GW_RESET_TYPE_E type)
Functional description
A callback to invoke when the gateway is reset.
Parameter description
Parameter name | Description |
---|---|
type | The types of resetting:
|
Return value
Return value | Description |
---|---|
VOID | / |
VOID (*gw_reboot_cb)(VOID)
Functional description
A callback to invoke when applications are restarted. You need to implement application restart in this callback.
Parameter description
Parameter name | Description |
---|---|
VOID | / |
Return value
Return value | Description |
---|---|
VOID | / |
VOID (*gw_upgrade_cb)(CONST FW_UG_S *fw)
Functional description
A callback to invoke when an update notification is received. You need to implement the firmware update functionality in this callback.
Parameter description
Parameter name | Description |
---|---|
fw | The firmware information. For more information, see FW_UG_S. |
Return value
Return value | Description |
---|---|
VOID | / |
VOID (*gw_active_stat_cb)(GW_STATUS_E stat)
Functional description
A callback to invoke when the gateway status changes.
Parameter description
Parameter name | Description |
---|---|
stat | The gateway status:
|
Return value
Return value | Description |
---|---|
VOID | / |
VOID (*gw_active_url_cb)(CHAR_T *url)
Functional description
A callback to invoke when a URL for generating a QR code is received.
Parameter description
Parameter name | Description |
---|---|
url | A URL used to generate a QR code for pairing. |
Return value
Return value | Description |
---|---|
VOID | / |
VOID app_log_path_cb(OUT CHAR_T *path, IN CONST INT_T len)
Functional description
A callback to invoke when a local log request is received. You need to assign the log path to the variable path
in this callback.
Parameter description
Parameter name | Description |
---|---|
path | The path buffer. Assign the log path to this variable. |
len | The size of the path buffer. |
Return value
Return value | Description |
---|---|
VOID | / |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback