Tuya Cloud API SDK for Golang.
Make sure you have serverHOST
, AccessID
and AccessKey
.
Before running this SDK, you need to initialize it with the following method:
config.SetEnv(common.URLCN, "AccessID", "AccessKey")
Example
If you want to fetch the device info, you can call device.GetDevice()
:
deviceID := "xxx"
got, err := device.GetDevice(deviceID)
if err!=nil{
xxx
}
// process got
Method | API | Description |
---|---|---|
token.GetTokenAPI | GET /v1.0/token?grant_type=1 | Get access_token with simple method |
token.RefreshToken | GET /v1.0/token/{easy_refresh_token} | Refresh token |
device.GetDevice | GET /v1.0/devices/{device_id} | Get device details |
device.GetDeviceFunctions | GET /v1.0/devices/{deviceId}/functions | Get function list |
device.GetDeviceFunctionByCategory | GET /v1.0/functions/{category} | Get function list by category |
device.GetDeviceStatus | GET /v1.0/devices/{device_id}/status | Get device data point details |
device.PostDeviceCommand | POST /v1.0/devices/{device_id}/commands | Send device command |
device.DeleteDevice | DELETE /v1.0/devices/{device_id} | Remove device |
user.PostUserRegister | POST /v1.0/apps/{schema}/user | User registration |
user.GetDeviceListByUid | GET /v1.0/users/{uid}/devices | Get deice list by user ID |
device.dn.GetDevicesByToken | POST /v1.0/device/paring/token | Generate pairing token |
Note: The refreshToken
interface will return a new access_token
, even if the old token has not expired.
This logic is already implemented in the GetToken
method, and generally you do not need to call the refreshToken
interface.
No, this logic has been implemented in the API method. The token information will be cached in memory.
When calling an interface, if the token has expired, do I need to manually call the refresh-token interface?
No, in the GetToken()
method, it will check whether the token has expired. If token expires, it will be pulled again.
If a token is refreshed in multiple nodes, then you need to implement common.TokenLocalManage
interface
Tuya's cloud token only guarantees that refreshing problems will not occur on the end-users side, but if the token of one user refreshes concurrently on multiple nodes, it will cause one node to be successful while other nodes fail. GetToken
interface will return an access_token
and refresh_token
, but refresh_token
interface will erase the current refresh_token
and generate a new token, so the old token will be invalid.
If the interface returns an error, it can generally be a URL error or a JSON parsing error, you can contact Tuya technical staff for help.
If error is empty, but the success field of the response is false, you can troubleshoot according to the detailed error information in the Msg
field.
Multiple deviceIDs, separated by commas.
After creating the App SDK, the channel ID on the detail page is the schema.
Pair_token
refers to the network pairing token of an app user, which can be obtained from v1.0/devices/token
.
There are two ways:
- You can implement the
common.APIRequest
interface. If it is a POST request, you need to also implement theRequestBody
interface. Then callDoAPIRequest()
. For more information, seeUserDevicesAPI
. - Submit an issue, and we will handle the update.
You can get support from Tuya with the following methods:
- Tuya Smart Help Center: https://support.tuya.com/en/help
- Technical Support: https://iot.tuya.com/council