Last Updated on : 2024-11-20 08:51:48download
SDK has two major capabilities, including device integration and router management.
Enable Tuya smart devices that support Pegasus network pairing to connect to Tuya Cloud Platform.
Support the following operations on Tuya Smart App:
Enable or disable 2.4 GHz or 5 GHz Wi-Fi.
Change your account password.
Select the signal strength.
Configure encryption methods.
Display the devices that are connecting to the router in real time, and control the network speed.
Tuya Pegasus solution applies the IEEE 802.11-based beacon, probe request and probe response frames. In this way, the client can connect to Tuya cloud platform through Pegasus network pairing. In this solution, you can configure network for the client, and change the router for the server through Pegasus network pairing.
When the server waits for adding devices, it broadcasts the beacon packet. When the client receives the beacon packet with Pegasus organizationally unique identifier (OUI), it broadcasts the probe request packet that carries the device information to peripheral servers that support Pegasus network pairing.
When the server that waits for adding devices receives the broadcast, it transmits the client device information to the cloud. The cloud sends the encryption key of the client device to the server. The server sends the encrypted network pairing information to the terminal device through probe response frames. The terminal device computes the key based on the universally unique identifier (UUID) and related data, and decrypts the encrypted network pairing information. In this way, it can connect to the network, be activated, and bind the account in the cloud. Pegasus network pairing solution adopts one-key-per-device authentication mechanism where the key and network pairing data are dynamically generated in the cloud, ensuring secure device access. The information is encrypted by the fixed key for the first time.
Roles:
The Pegasus OUI value is 0x68
, 0x57
, and 0x2d
.
For the PID generated in the SDK demo, the UUID and authkey is used only for testing, not for physical products. Otherwise, the physical products will be unavailable. You need to apply for a PID in the Developer Platform. Each device has a unique UUID and authkey.
Tuya compiles the database based on client’s toolchain, and provides developer manual and relevant demos.
File name | Description |
---|---|
user_main.c |
SDK demo main entry files. |
tuya_iot_wired_net.c |
Related to wired network pairing, such as obtaining IP and MAC address. |
tuya_pegasus_test.c |
Related to Pegasus network pairing services. |
tuya_route_service_test.c |
Related to router services. |
For details about SDK calling process, see user_main.c file
.
// Write in authorization information, and set storage path.
memset(&env, 0 , sizeof(TUYA_GW_ENV_S));
snprintf(env.storage_path, sizeof(env.storage_path), "%s", CFG_STORAGE_PATH);
snprintf(env.product_key, sizeof(env.product_key), "%s", PRODUCT_KEY);
snprintf(env.uuid, sizeof(env.uuid), "%s", UUID);
snprintf(env.auth_key, sizeof(env.auth_key), "%s", AUTHKEY);
snprintf(env.sw_ver, sizeof(env.sw_ver), "%s", USER_SW_VER);
env.is_oem = TRUE;
// Register gateway callback API.
env.gw_stat_changed_cb = __gw_dev_status_changed_cb;
env.gw_ug_inform_cb = __gw_dev_rev_upgrade_info_cb;
env.gw_reset_cb = __gw_dev_reset_inform_cb;
env.gw_reboot_cb = __gw_dev_reboot_cb;
env.obj_dp_cmd_cb = __gw_dev_obj_dp_cmd_cb;
env.raw_dp_cmd_cb = __gw_dev_raw_dp_cmd_cb;
env.dp_query_cb = __gw_dev_dp_query_cb;
env.nw_stat_cb = __gw_dev_net_status_cb;
env.get_log_file = __gw_get_log_file_cb;
// Gateway services are enabled, and SDK connects to Tuya cloud platform.
op_ret = tuya_gw_service_start(&env);
if (OPRT_OK ! = op_ret) {
printf("tuya_gw_start error:%d\n", op_ret);
return op_ret;
}
// Pegasus network pairing services.
op_ret = tuya_pegasus_test_start();
if(OPRT_OK ! = op_ret) {
PR_ERR("tuya_pegasus_test_start err:%d",op_ret);
return -5;
}
// Router services.
op_ret = tuya_route_test_start();
if(OPRT_OK ! = op_ret) {
PR_ERR("tuya_route_test_start err:%d",op_ret);
return -6;
}
tuya_gw_service_start
OPERATE_RET tuya_gw_service_start(TUYA_GW_ENV_S *p_env);
typedef struct {
CHAR_T storage_path[STR_LEN_MAX+1]; // Path for SDK data storage. It must correspond to a read-write file system partition.
CHAR_T product_key[STR_LEN_MAX+1]; // Product ID/key.
CHAR_T uuid[STR_LEN_MAX+1]; // Authorization information: UUID
CHAR_T auth_key[STR_LEN_MAX+1]; // Authorization information: authkey
CHAR_T sw_ver[STR_LEN_MAX+1]; // SDK version No.
BOOL_T is_oem; // Whether it is oem2.0.
TUYA_GW_STAT_CHANGED_CB gw_stat_changed_cb; // Callback of device status change in the cloud.
TUYA_GW_UG_INFORM_CB gw_ug_inform_cb; // Entry of device upgrade.
TUYA_GW_RESET_IFM_CB gw_reset_cb; // Entry of device reset request.
TUYA_GW_REBOOT_CB gw_reboot_cb; // Entry of progress reboot request.
TUYA_GW_OBJ_DP_CMD_CB obj_dp_cmd_cb; // Entry of sending formatting command.
TUYA_GW_RAW_DP_CMD_CB raw_dp_cmd_cb; // Entry of sending pass-through command.
TUYA_GW_DP_QUERY_CB dp_query_cb; // Entry of querying specific device data.
TUYA_GW_NW_STAT_CB nw_stat_cb; // Callback of Internet status change.
TUYA_GW_GET_LOG_FILE_CB get_log_file; // Remotely obtain SDK log files.
#ifdef TUYA_ZIGBEE_ENABLE
TUYA_ZB_CONFIG_S zb_config; // Zigbee configuration information.
#endif
} TUYA_GW_ENV_S;
#ifdef TUYA_ZIGBEE_ENABLE
typedef struct{
CHAR_T serial_port[STR_LEN_MAX+1]; // Zigbee serial port device No.
BOOL_T is_cts; // Whether flow control is available.
CHAR_T tmp_dir[STR_LEN_MAX+1]; // Temporary file directory.
CHAR_T bin_dir[STR_LEN_MAX+1]; // Bin file directory. Do not store files in this directory, since it may be a read-only file system in other platforms.
CHAR_T log_dir[STR_LEN_MAX+1]; // Log storage directory.
} TUYA_ZB_CONFIG_S;
#endif
Function description
Enable gateway service, and register the required callback.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | p_cbs |
Pointer to the struct of Pegasus network pairing callback. |
[IN] | get_probe_intr_ms |
The interval between polling probe frames. |
Return value
0
indicates success.Description
The basic gateway service is Tuya network SDK. If you need Zigbee gateway function, you can choose the router SDK with Zigbee gateway function to develop. The Pegasus router SDK adopts the same external API as these of its extension SDK.
gw_stat_changed_cb
typedef VOID (*TUYA_GW_STAT_CHANGED_CB)(IN CONST GW_STATUS_E status);
// Example
VOID __gw_dev_status_changed_cb(IN CONST GW_STATUS_E status);
Function description
When the gateway status changes, this callback is used to notify users.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | status |
Gateway status: 0 : Gateway is reset. 1 : Gateway is activated. 2 : Gateway is started for the first time. 3 : Gateway is activated and is running. |
Return value
None
gw_ug_inform_cb
typedef VOID (*TUYA_GW_UG_INFORM_CB)(IN CONST FW_UG_S *fw);;
// Example
VOID __gw_dev_rev_upgrade_info_cb(IN CONST FW_UG_S *fw);
Function description
Notify over-the-air (OTA) gateway firmware updates. It indicates the service end publishes the latest firmware.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | fw |
The information of the latest firmware includes firmware type, upgrade type, download URL, firmware version, firmware size, and hash value. See the definition in tuya_cloud_com_defs.h . |
Return value
None
Description
Users can download the firmware and perform verification based on the struct information.
gw_reset_cb
typedef VOID (*TUYA_GW_RESET_IFM_CB)(GW_RESET_TYPE_E type);
// Example
VOID __gw_dev_reset_inform_cb(GW_RESET_TYPE_E type);
Function description
Callback notification of resetting the gateway. Reboot the gateway application.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | type |
Reset type: 1 : Locally restore factory settings. 2 : Reset the remote gateway. Unbind the account through the app. 3 : Reset the local gateway. Unbind the account. 4 : Remotely restore factory settings. 5 : Restore data factory settings. |
Return value
None
Description
The SDK users implement the APIs content.
gw_reboot_cb
typedef VOID (*TUYA_GW_REBOOT_CB)(VOID);
// Example
VOID __gw_dev_reboot_cb(VOID);
Function description
Reset and reboot the gateway.
Parameters
Input/output | Parameter | Description |
---|---|---|
None | None | None |
Return value
None
Description
The SDK users implement the APIs content.
obj_dp_cmd_cb
typedef VOID (*TUYA_GW_OBJ_DP_CMD_CB)(IN CONST TY_RECV_OBJ_DP_S *dp);
// Example
VOID __gw_dev_obj_dp_cmd_cb(IN CONST TY_RECV_OBJ_DP_S *dp);
Function description
Callback of OBJ data point (DP) information command.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | dp | TY_RECV_OBJ_DP_S includes: 1 : DP command type. 2 : DP transmission type. 3 : Device ID controlled by the DP. 4 : If dtt_tp adopts multicast, mb_id indicates the group ID. 5 : Array length of the DP struct. 6 : DP struct array. See tuya_cloud_com_defs.h. |
Return value
None
Description
None
raw_dp_cmd_cb
typedef VOID (*TUYA_GW_RAW_DP_CMD_CB)(IN CONST TY_RECV_RAW_DP_S *dp);
// Example
VOID __gw_dev_raw_dp_cmd_cb(IN CONST TY_RECV_RAW_DP_S *dp);
Function description
Callback of raw DP information command.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | dp |
The struct includes: 1 : DP command type. 2 : DP transmission type. 3 : Device ID controlled by the DP. 4 : Custom DP No. 5 : If dtt_tp adopts multicast, mb_id indicates group ID. 6 : The number of raw data bytes. 7 : Raw data. See tuya_cloud_com_defs.h . |
Return value
None
Description
None
dp_query_cb
typedef VOID (*TUYA_GW_DP_QUERY_CB)(IN CONST TY_DP_QUERY_S *dp_qry);
// Example
VOID __gw_dev_dp_query_cb(IN CONST TY_DP_QUERY_S *dp_qry)
Function description
Entry of querying specific device data.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | dp_qry |
The struct includes: 1 : Device ID controlled by the DP. 2 : The number of queried DPs. 3 : Collection of custom DP No. See tuya_cloud_com_defs.h . |
Return value
None
Description
nw_stat_cb
typedef VOID (*TUYA_GW_NW_STAT_CB)(IN CONST GW_BASE_NW_STAT_T stat);
// Example
OPERATE_RET ty_pegasus_get_mac_cb(OUT NW_MAC_S *mac);
Function description
The network status management is called back, and users can process transmission according to the network status.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | network status |
GB_STAT_LAN_UNCONN : LAN is not connected. GB_STAT_LAN_CONN : LAN is connected but the cloud is disconnected. GB_STAT_CLOUD_CONN : WAN is connected to the cloud. |
Return value
None
Description
Status2 indicates that the user is successfully connected to the cloud.
get_log_file
typedef VOID (*TUYA_GW_GET_LOG_FILE_CB)(OUT CHAR_T *file_name, IN CONST INT_T len);
// Example
VOID __gw_get_log_file_cb(OUT CHAR_T *file_name, IN CONST INT_T len);
Function description
Obtain SDK logs.
Parameters
Input/output | Parameter | Description |
---|---|---|
[OUT] | file_name |
File name of the log package. The specific absolute path is required. |
[IN] | len |
File name length of the log package. |
Return value
None
Description
Users can decide how long the logs are to be stored according to their device performance. It is recommended to store at least three-day SDK logs to facilitate remote technical support and fault locating.
tuya_gw_service_reset
OPERATE_RET tuya_gw_service_reset(VOID)
Function description
Gateway SDK is restored, and is in the inactive status.
Parameters
Input/output | Parameter | Description |
---|---|---|
None | None | None |
Return value
None
Description
The SDK with Zigbee function prohibits Zigbee sub-device from connecting, and set the gateway to inactive status.
The SDK without Zigbee function sets the gateway to inactive status.
tuya_hal_pegasus_init
OPERATE_RET tuya_hal_pegasus_init(TUYA_PEGASUS_CBS_S *p_cbs, UINT_T get_probe_intr_ms);
typedef struct {
TY_PEGASUS_EVENT_CB event_cb;
TY_PEGASUS_SEND_FRAME_CB send_frame_cb;
TY_PEGASUS_GET_SSID_PWD_CB get_ssid_pwd_cb;
TY_PEGASUS_GET_MAC_CB get_mac_cb;
TY_PEGASUS_SET_OUI_CB set_oui_cb;
} TUYA_PEGASUS_CBS_S;
Function description
For the initialization function of the Pegasus network pairing, register the required callback.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | p_cbs |
Pointer to the struct of Pegasus network pairing callback. |
[IN] | get_probe_intr_ms |
The interval between polling probe frames. |
Return value
0
indicates success.Description
The basic gateway service is Tuya network SDK. If you need Zigbee gateway function, you can choose the router SDK with Zigbee gateway function to develop. The Pegasus router SDK adopts the same external API as these of its extension SDK.
get_mac_cb
typedef OPERATE_RET (*TY_PEGASUS_GET_MAC_CB)(OUT NW_MAC_S *mac);
// Example
OPERATE_RET ty_pegasus_get_mac_cb(OUT NW_MAC_S *mac);
Function description
Obtain the MAC address of AP.
Parameters
Input/output | Parameter | Description |
---|---|---|
[OUT] | mac |
MAC address of the router. |
Return value
0
indicates success.Description
The SDK users implement the APIs content.
get_ssid_pwd_cb
typedef OPERATE_RET (*TY_PEGASUS_GET_SSID_PWD_CB)(OUT UINT8_T *ssid, IN INT_T slen, OUT UINT8_T *pwd, IN INT_T plen);
// Example
OPERATE_RET ty_pegasus_get_ssid_pwd_cb(OUT UINT8_T *ssid, IN INT_T slen, OUT UINT8_T *pwd, IN INT_T plen)
Function description
Obtain the SSID and password of the 2.4 GHz Wi-Fi.
Parameters
Input/output | Parameter | Description |
---|---|---|
[OUT] | ssid |
First memory address of SSID. |
[IN] | slen |
SSID length |
[OUT] | pwd |
First memory address of password. |
[IN] | plen |
Password length |
Return value
0
indicates success.Description
The SDK users implement the APIs content.
set_oui_cb
typedef OPERATE_RET (*TY_PEGASUS_SET_OUI_CB)(IN BYTE_T *oui, IN BYTE_T oui_len);
// Example
OPERATE_RET ty_pegasus_set_oui_cb(IN BYTE_T *oui, IN BYTE_T oui_len)
Function description
Set Tuya OUI.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | oui |
Tuya OUI |
[IN] | oui_len |
OUI length |
Return value
0
indicates success.Description
The SDK users implement the APIs content.
The Pegasus network pairing of the router only processes the probe frames with Tuya OUI values that are 0x68
, 0x57
, and 0x2d
.
send_frame_cb
typedef OPERATE_RET (*TY_PEGASUS_SEND_FRAME_CB)(IN CONST TY_FRAME_TYPE_E type, IN CONST UINT8_T *vsie, IN CONST UINT_T vsie_len, IN NW_MAC_S *srcmac, IN NW_MAC_S *dstmac);
// Example
OPERATE_RET ty_pegasus_send_frame_cb(IN CONST TY_FRAME_TYPE_E type, IN CONST UINT8_T *vsie,
IN CONST UINT_T vsie_len, IN NW_MAC_S *srcmac, IN NW_MAC_S *dstmac)
typedef enum {
TY_FRAME_TP_BEACON = 1,
TY_FRAME_TP_PROBE_REQ = 2,
TY_FRAME_TP_PROBE_RESP = 3,
TY_FRAME_TP_INVALD
} TY_FRAME_TYPE_E;
Function description
Send probe response frames and beacon frames.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | type |
Frame type |
[IN] | vsie |
VSIE memory address |
[IN] | vsie_len |
VSIE length |
[IN] | srcmac |
MAC address of the router. |
[IN] | dstmac |
MAC address of the client. |
Return value
0
indicates success.Description
The SDK users implement the APIs content.
When the router sends probe response frames and beacon frames, the SDK user only needs to forward and broadcast the data respectively, without caring about the specific data types.
event_cb
typedef VOID (*TY_PEGASUS_EVENT_CB)(IN CONST TY_PEGASUS_EVENT_E event);
// Example
VOID ty_pegasus_event_cb(IN CONST TY_PEGASUS_EVENT_E event)
typedef enum {
TY_PEGASUS_START = 1,
TY_PEGASUS_STOP = 2,
TY_PEGASUS_GET_PROBE_START = 3,
TY_PEGASUS_EVENT_INVALD
} TY_PEGASUS_EVENT_E;
Function description
Transmit events related to Pegasus network pairing, such as the probe request from the client.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | event |
Pegasus network pairing status: TY_PEGASUS_START : Start Pegasus. TY_PEGASUS_STOP : Stop Pegasus. TY_PEGASUS_GET_PROBE_START : Transmit probe frames.TY_PEGASUS_EVENT_INVALD : Invalid event. |
Return value
None
Description
The SDK users implement the APIs content.
When the event status becomes TY_PEGASUS_GET_PROBE_START
, the router transmits the probe request frames with Tuya OUI that is sent by the client. Pay attention to the following points:
The client sends network pairing request every 250 milliseconds (continuously send 5 frames each time) and times out after 5 seconds.
If the router receives same frames, it is recommended to filter out the same frames by adopting CRC verification. By recording the CRC value of the previous and subsequent frames, the router only reports the different frames.
Processing frames from the client usually compromises performance of the router. It is recommended to transmit frames in an asynchronous way. In this way, the router is generally in the blocked state. Only when the router is in TY_PEGASUS_GET_PROBE_START
status and receives the frames to be transmitted, it will execute frame transmission. See the first point for extracting frames to avoid network pairing failure.
tuya_pegasus_rept_probe
OPERATE_RET tuya_pegasus_rept_probe(const UINT8_T *vsie, const UINT_T vsie_len, NW_MAC_S *smac, NW_MAC_S *dmac)
Function description
Transmit probe request frames from the client.
Parameters
Input/output | Parameter | Description |
---|---|---|
[OUT] | vsie |
VSIE memory address |
[OUT] | vsie_len |
VSIE length |
[OUT] | srcmac |
MAC address of the client |
[OUT] | dstmac |
MAC address of the router |
Return value
0
indicates success.pegasus_server_second_start
int pegasus_server_second_start(uint32_t timeout_s);
Function description
The secondary network pairing.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | timeout_s |
Timeout duration of the secondary network pairing. |
Return value
0
indicates success.Description
Secondary network pairing: When the router password is changed, the activated device will be offline. Generally, after you configure the network again, the device will go online again. But the secondary network pairing solution allows the device to automatically re-connect to the router without network pairing. Only the router that has the capability of secondary network pairing can perform this operation.
tuya_route_service_init
OPERATE_RET tuya_route_service_init(IN CONST TUYA_ROUTE_CBS_S *p_route_cbs,
IN CONST TUYA_ROUTE_STA_CBS_S *p_sta_cbs);
typedef struct {
TY_ROUTE_CMD_CB route_cmd_cb;
TY_ROUTE_QUERY_PWD_CB route_query_cb;
TY_ROUTE_SET_PWD_CB route_set_cb;
}TUYA_ROUTE_CBS_S;
typedef struct {
TY_ROUTE_STA_CMD_CB sta_cmd_cb;
}TUYA_ROUTE_STA_CBS_S;
typedef VOID (*TY_ROUTE_CMD_CB)(IN CONST TY_ROUTE_CMD_E cmd);
typedef VOID (*TY_ROUTE_QUERY_PWD_CB)(IN CONST CHAR_T *ssid);
typedef VOID (*TY_ROUTE_SET_PWD_CB)(IN CONST CHAR_T *ssid, IN CONST CHAR_T *pwd);
typedef VOID (*TY_ROUTE_STA_CMD_CB)(IN CONST TY_ROUTE_STA_CMD_E cmd, IN CONST CHAR_T *mac,
IN CONST UINT_T value);
// Example
VOID ty_route_cmd_cb(IN CONST TY_ROUTE_CMD_E cmd);
VOID ty_route_query_pwd_cb(IN CONST CHAR_T *ssid);
VOID ty_route_set_pwd_cb(IN CONST CHAR_T *ssid, IN CONST CHAR_T *pwd);
VOID ty_route_sta_cmd_cb(IN CONST TY_ROUTE_STA_CMD_E cmd, IN CONST CHAR_T *mac,
IN CONST UINT_T value);
Function description
API function of router service initialization.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | p_route_cbs |
Pointer to the struct of router command, query or setting callback. |
[IN] | p_sta_cbs |
Pointer to the struct of STA command callback. |
Return value
0
indicates success.route_cmd_cb
typedef VOID (*TY_ROUTE_CMD_CB)(IN CONST TY_ROUTE_CMD_E cmd);
typedef enum {
TY_ROUTE_CMD_GET_ONLINE_LIST = 1,
TY_ROUTE_CMD_GET_BLACK_LIST = 2,
TY_ROUTE_CMD_INVALD
} TY_ROUTE_CMD_E;
// Example
VOID ty_route_cmd_cb(IN CONST TY_ROUTE_CMD_E cmd);
Function description
Obtain device list.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | cmd |
TY_ROUTE_CMD_GET_ONLINE_LIST : Obtain online device list. TY_ROUTE_CMD_GET_BLACK_LIST : Obtain blacklist. TY_ROUTE_CMD_INVALD : Invalid command. |
Return value
None
Description
The SDK users implement the APIs content.
route_query_cb
typedef VOID (*TY_ROUTE_QUERY_PWD_CB)(IN CONST TUYA_ROUTE_PWD_E type);
typedef enum {
TY_ROUTE_PWD_INVALID = 0,
TY_ROUTE_PWD_2_4G = 1,
TY_ROUTE_PWD_5G = 2,
} TUYA_ROUTE_PWD_E;
// Example
VOID ty_route_query_pwd_cb(IN CONST TUYA_ROUTE_PWD_E type);
Function description
Query Wi-Fi password.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | type |
Command types of querying password: TY_ROUTE_PWD_INVALID : Invalid command. TY_ROUTE_PWD_2_4G : Obtain 2.4 GHz Wi-Fi password. TY_ROUTE_PWD_5G : Obtain 5 GHz Wi-Fi password. |
Return value
None
Description
The SDK users implement the APIs content.
route_set_cb
typedef VOID (*TY_ROUTE_SET_PWD_CB)(IN CONST TUYA_ROUTE_PWD_E type, IN CONST CHAR_T *pwd);
// Example
VOID ty_route_set_pwd_cb(IN CONST TUYA_ROUTE_PWD_E type, IN CONST CHAR_T *pwd);
Function description
Set the Wi-Fi password.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | type |
Set password command types:TY_ROUTE_PWD_INVALID : Invalid command. TY_ROUTE_PWD_2_4G : Set the password for 2.4 GHz Wi-Fi. TY_ROUTE_PWD_5G : Set the password for 5 GHz Wi-Fi. |
[IN] | pwd |
Password |
Return value
0
indicates success.Description
The SDK users implement the APIs content.
sta_cmd_cb
typedef VOID (*TY_ROUTE_STA_CMD_CB)(IN CONST TY_ROUTE_STA_CMD_E cmd, IN CONST CHAR_T *mac,
IN CONST UINT_T value);
typedef enum {
TY_STA_CMD_ALLOW_NET = 1,
TY_STA_CMD_SPEED_LIMIT = 2,
TY_STA_CMD_UP_LIMIT = 3,
TY_STA_CMD_DOWN_LIMIT = 4,
TY_STA_CMD_GET_ALL_CONFIG = 5,
TTY_STA_CMD_INVALD
} TY_ROUTE_STA_CMD_E;
// Example
VOID ty_route_sta_cmd_cb(IN CONST TY_ROUTE_STA_CMD_E cmd, IN CONST CHAR_T *mac,
IN CONST UINT_T value);
Function description
Callback of the STA command.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | cmd |
TY_STA_CMD_ALLOW_NET : Whether to allow network commands. TY_STA_CMD_SPEED_LIMIT : Whether to enable speed limit. TY_STA_CMD_UP_LIMIT : The maximum upstream rate.TY_STA_CMD_DOWN_LIMIT : The maximum downstream rate.TY_STA_CMD_GET_ALL_CONFIG : All above configuration information. TTY_STA_CMD_INVALD : Invalid command. |
[IN] | mac |
MAC address |
[IN] | value |
The execution result of the corresponding command. |
Return value
None
Description
The SDK users implement the APIs content.
tuya_route_rept_online_list
OPERATE_RET tuya_route_rept_online_list(IN CONST USHORT_T dev_count,
IN CONST TUYA_ROUTE_DEV_LIST_S *p_list)
typedef struct {
CHAR_T dev_name[TY_ROUTE_DEV_NAME_MAX]; // Device name
CHAR_T mac[TY_ROUTE_MAC_STR_LEN]; // Mac address
}TUYA_ROUTE_DEV_LIST_S;
Function description
Transmit the online device list.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | dev_count |
The number of devices. |
[IN] | p_list |
Pointer to the struct of device information. |
Return value
0
indicates success.tuya_route_rept_pwd
OPERATE_RET tuya_route_rept_pwd(IN CONST TUYA_ROUTE_PWD_E type, IN CONST CHAR_T *pwd)
Function description
Transmit the Wi-Fi password.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | type |
Wi-Fi type |
[IN] | pwd |
Password |
Return value
0
indicates success.tuya_route_rept_sta_allow_net
OPERATE_RET tuya_route_rept_sta_allow_net(IN CONST CHAR_T *mac,
IN CONST BOOL_T allow,
IN CONST UINT_T sta_dpid)
Function description
Transmit the command that whether a device with the specified MAC address is allowed to access the network.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | mac |
MAC address of the device. |
[IN] | allow |
The parameter adopts Boolean value: 1 indicates network access is allowed. 0 indicates network access is now allowed. |
[IN] | sta_dpid |
DP |
Return value
0
indicates success.tuya_route_rept_sta_limit
OPERATE_RET tuya_route_rept_sta_limit(IN CONST CHAR_T *mac,
IN CONST BOOL_T limit,
IN CONST UINT_T sta_dpid)
Function description
Transmit the command that whether the speed limit is enabled for a device with the specified MAC address.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | mac |
MAC address of the device. |
[IN] | limit |
Adopt the Boolean value: 1 indicates the speed limit is enabled. 0 indicates the speed limit is disabled. |
[IN] | sta_dpid |
DP |
Return value
0
indicates success.tuya_route_rept_sta_up_limit
OPERATE_RET tuya_route_rept_sta_up_limit(IN CONST CHAR_T *mac,
IN CONST UINT_T limit,
IN CONST UINT_T sta_dpid)
Function description
Transmit the maximum upstream rate for a device with the specified MAC address.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | mac |
MAC address of the device. |
[IN] | limit |
The maximum upstream rate. |
[IN] | sta_dpid |
DP |
Return value
0
indicates success.tuya_route_rept_sta_down_limit
OPERATE_RET tuya_route_rept_sta_down_limit(IN CONST CHAR_T *mac,
IN CONST UINT_T limit,
IN CONST UINT_T sta_dpid)
Function description
Transmit the maximum downstream rate for a device with the specified MAC address.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | mac |
MAC address of the device. |
[IN] | limit |
The maximum downstream rate. |
[IN] | sta_dpid |
DP |
Return value
0
indicates success.tuya_route_rept_sta_all
OPERATE_RET tuya_route_rept_sta_all(IN CONST CHAR_T *mac,
IN CONST TUYA_ROUTE_STA_CONF_S *config,
IN CONST UINT_T sta_dpid)
typedef struct {
BOOL_T allow;
BOOL_T limit;
UINT_T up_limit;
UINT_T down_limit;
} TUYA_ROUTE_STA_CONF_S;
Function description
Transmit all the STA information for a device with the specified MAC address, including whether to allow access to network, whether to enable speed limit, the maximum upstream rate, and the maximum downstream rate.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | mac |
MAC address of the device |
[IN] | config |
All STA information |
[IN] | sta_dpid |
DP |
Return value
0
indicates success.tuya_route_sta_data_parse
OPERATE_RET tuya_route_sta_data_parse(IN CONST CHAR_T *data)
Function description
Parse all STAT information.
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | data |
The received STA information in the cloud. |
Return value
0
indicates success.The production test only targets the extension SDK (with Zigbee function). With Tuya dongle, the user can perform production test for the communication function of the Zigbee module through SDK production test API. For the function usage, see the following APIs and the created thread tuya_factory_manage.
tuya_gw_get_zigbee_ver
OPERATE_RET tuya_gw_get_zigbee_ver(CHAR_T *p_ver, UINT_T in_len)
Function description
Obtain Zigbee version No.
Parameters
Input/output | Parameter | Description |
---|---|---|
[OUT] | p_ver |
Firmware No. of the Zigbee module. |
[IN] | in_len |
Firmware No. length of the Zigbee module. |
Return value
0
indicates success.tuya_gw_zigbee_rf_test
OPERATE_RET tuya_gw_zigbee_rf_test(UINT_T channel, UINT_T number)
Function description
Set Zigbee RF test
Parameters
Input/output | Parameter | Description |
---|---|---|
[IN] | channel |
Zigbee channel |
[IN] | number |
Set the number of sent frames. |
Return value
0
indicates success.tuya_get_zigbee_rf_test_result
USHORT_T tuya_get_zigbee_rf_test_result()
Function description
Obtain Zigbee RF test result.
Parameters
Input/output | Parameter | Description |
---|---|---|
None | None | None |
Return value
0
: Indicates communication is successful, and frames from Zigbee module are obtained.Description
The number in tuya_gw_zigbee_rf_test
represents the number of frames to be sent. The return value of tuya_get_zigbee_rf_test_result
represents the number of frames that Zigbee module successfully receives. If the sending and receiving frames are consistent, it indicates the surrounding signals present a little interference to data transmission, and no packet is dropped. If there is interference, the received frames may be less than the sent frames. If multiple dongles are testing at the same time, the received frames might be greater than the sent frames — the possibility is relatively small.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback