更新记录
1.0.11(2026-10-19)
- 增加查询dp接口UTSTuya.getDp
1.0.10(2026-10-19)
- ios端蓝牙扫描数据增加advertisementData广播数据
1.0.9(2026-10-17)
- ios端扫描增加字段
平台兼容性
uni-app(3.8.6)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | - | - | √ | √ | 6.0 | 13 | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(3.8.6)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | 6.0 | 13 | - | - |
其他
| 多语言 | 暗黑模式 | 宽屏模式 | 蒸汽模式 |
|---|---|---|---|
| √ | √ | √ | × |
前言
涂鸦插件,包含Wi-Fi、蓝牙、有线、zigbee版本,可以控制照明、传感、家电、网关等等遵循涂鸦协议的外设,包含账号家庭管理、设备配网、设备控制管理等等
支持定制,请点击上面“进入交流群”联系作者
功能
按照涂鸦APIhttps://developer.tuya.com/cn/docs/app-development/android-energy-consumption?id=Kaosznjd98j7v分类,为了快速查找API方法,可以现在涂鸦官网复制中文方法名称,然后在此网页上搜索,如要查找发送手机号码验证码的API,复制“发送手机号码验证码”在此网页上搜索相关API,有些API无法搜索再仔细阅读此文当或查看demo查找。 关于涂鸦云开发(垂直品类硬件API(万能红外开放能力、设备连接服务、设备OTA固件升级、实时音视频、睡眠带开放能力、体脂秤开放能力、智能门锁开放能力、视频云存储 、邮件服务 、 语音消息服务、消息推送服务、短信服务 、内测版 API)、行业通用API等等)插件见https://ext.dcloud.net.cn/plugin?id=6744
快速入门
设备配网注意点
- 设备配网前需要先创建一个家庭,然后选择一个家庭
- 配网前手机需要开启定位,手机连接Wi-Fi,不能用4G网络
- Wi-Fi路由器需要关闭5G信号(涂鸦设备目前只支持2.4GHz网络),登录路由器,关闭5GHz(各种品牌路由器关闭方法参考厂家说明或自定百度)
集成插件步骤
- 在涂鸦IOT平台里的App 工作台,在App -> App SDK(SDK 开发) -> SDK开发创建应用,并在应用里绑定Android、iOS包名(即uniapp的android包名、iOS的Bundle ID)
- android还需要在涂鸦IOT平台里(点击创建的应用进入应用详情-> 获取密钥-> Android -> 证书)绑定签名的SHA256。(SHA265的获取可参考涂鸦的说明https://developer.tuya.com/cn/docs/app-development/iot_app_sdk_core_sha1?id=Kao7c7b139vrh)
- 进入到创建的应用详情页的SDK页面里,切换到“获取SDK”栏目,选择对应到功能模块,分别下载"下载iOS开发版"、"下载Android开发版“、"获取鸿蒙SDK",下载后解压, 正式版需要重新下载集成一遍
- 点击右上角"试用"按钮,按照指示步骤集成插件到自己的项目
- 下载demo(点击右上角"使用HBuilderX导入示例项目")拷贝demo里的uni_modules/wrs-tuya、Info.plist、AndroidManifest.xml、harmony-configs到项目对应目录
- 为iOS创建一个public的git仓库,将https://gitee.com/uniapp_uts/thing-smart-cryption.git里的内容推送上去,iOS开发版解压后,替换此仓库里的ThingSmartCryption.podspec文件和Build文件夹,替换后提交推送到远程仓库,并打上tag,修改uni_modules/wrs-uts-tuya/utssdk/app-ios/config.json文件,将name为ThingSmartCryption里的git和tag替换为此仓库的git地址和tag
- android开发版解压后,将security-algorithm-1.0.0-beta.aar文件替换uni_modules/wrs-tuya/utssdk/app-android/libs/security-algorithm-1.0.0-beta.aar文件,替换AndroidManifest.xml里THING_SMART_APPKEY和THING_SMART_SECRET的值
- 鸿蒙sdk解压后,替换项目里的uni_modules/wrs-tuya/utssdk/app-harmony/libs/TSmartSecurity.har、uni_modules/wrs-tuya/utssdk/app-harmony/resources/rawfile/t_s.bmp
- manifest.json的app-plus => distribute => android => packagingOptions增加下面配置(可以参考demo)
"packagingOptions": [
"pickFirst 'lib/*/libc++_shared.so'",
"pickFirst 'lib/*/libgnustl_shared.so'",
"pickFirst 'lib/*/liblog.so'",
"pickFirst 'lib/*/libopenh264.so'",
"pickFirst 'lib/*/libyuv.so'"
]
- ios EZ 配网的数据包。此时,App 需要额外开启一个 com.apple.developer.networking.multicast 的权限,参考https://www.jianshu.com/p/c2f6e6aa41a3?v=1682211826634
- 在App.vue里引入插件变量,如:
import {UTSTuya} from "@/uni_modules/wrs-uts-tuya"
import {WRSTuya} from "@/uni_modules/wrs-tuya"
- 删除本地基座和手机上安装的app,重新自定义基座运行
涂鸦错误码查询链接:
https://developer.tuya.com/cn/docs/app-development/errorcode?id=Ka6o3bubtl735
调用接口时,出现"xxx非法客户端"的错误排查步骤:
android:
- 检查uniapp项目的包名是否与涂鸦IOT平台里对应应用的包名一致
- uni_modules/wrs-tuya/utssdk/app-android/libs/security-algorithm-1.0.0-beta.aary里对应文件是否按照集成步骤里的说明进行替换
- android签名的SHA256是否与涂鸦IOT平台里对应应用的包名一致
- 删除手机app重新自定义基座安装
iOS:
- 检查uniapp项目的Bundle ID是否与涂鸦IOT平台里对应应用的包名一致
- 共有仓库里对应文件是否按照集成步骤里的说明进行替换、
- 删除手机app重新自定义基座安装
接口
import {UTSTuya} from "@/uni_modules/wrs-uts-tuya"
import {WRSTuya} from "@/uni_modules/wrs-tuya"
- 初始化SDK
let params = {}
let platform = uni.getSystemInfoSync().platform
switch (platform) {
case "ios": {
params.appkey = "7hsnayvpgapxckxsw99v"
params.appSerect = "vt4fg5rst9eyk8ktydwt7gunqv8jv75u"
}
break;
case "android": {
params.appkey = "87jnyvghe5w5uun99qc3"
params.appSerect = "msp4a54s8s57jhhp4mhc844c7cednyq5"
}
break;
default:
break;
}
UTSTuya.sdkInit(params)
- 设置回调
UTSTuya.onSetCallback((resp) => {
let opt = resp.opt
switch (opt) {
// 低功耗蓝牙配网或蓝牙Wi-Fi双模配网扫描到蓝牙设备的回调
case "onDiscoverDevice": {
let data = resp.data
switch (uni.getSystemInfoSync().platform) {
case 'android': {
if (data.configType == "config_type_wifi") {
let params = {}
params.uuid = data.uuid
params.homeId = this.homeId
params.ssid = this.ssid
params.password = this.password
params.timeout = 120 * 1000
params.token = this.token
UTSTuya.startConfigBLEWifiDevice(params, (resp) => {
if (resp.flag) {
this.showMsg("配网中。。。")
} else {
this.showMsg("配网数据发送失败。。。resp:" + JSON.stringify(resp))
}
})
} else {
}
}
break;
case 'ios': {
let bleType = data.bleType
// typedef enum : NSUInteger {
// /// The unknown type of Bluetooth LE device.
// ThingSmartBLETypeUnknow = 1,
// /// The type of Bluetooth LE device that supports an earlier protocol. The device does not support a security protocol.
// ThingSmartBLETypeBLE,
// /// The type of Bluetooth LE device that supports an earlier protocol of a lower security level.
// ThingSmartBLETypeBLEPlus,
// /// The type of Bluetooth LE device that supports an earlier protocol. The device does not support a security protocol.
// ThingSmartBLETypeBLEWifi,
// /// The type of Bluetooth LE device that supports a later protocol of a higher security level.
// ThingSmartBLETypeBLESecurity,
// /// The type of Bluetooth LE dual-mode device that supports a later protocol of a higher security level.
// ThingSmartBLETypeBLEWifiSecurity,
// /// The type of Bluetooth LE dual-mode device that supports a later protocol of a higher security level and that supports the plug and play (PnP) function.
// ThingSmartBLETypeBLEWifiPlugPlay,
// /// The type of Bluetooth LE and Zigbee dual-mode device that supports a later protocol of a higher security level.
// ThingSmartBLETypeBLEZigbee,
// /// The type of Bluetooth LE and LTE Category 1 dual-mode device that supports a later protocol of a higher security level.
// ThingSmartBLETypeBLELTESecurity,
// /// The beacon security.
// ThingSmartBLETypeBLEBeacon,
// /// Same as the ThingSmartBLETypeBLEWifiPlugPlay, but BLE is prior while configing.
// ThingSmartBLETypeBLEWifiPriorBLE,
// } ThingSmartBLEType;
if (bleType == 1 || bleType == 2 || bleType == 5 || bleType == 3 || bleType ==
8 ||
bleType ==
10) {
this.showMsg("请使用低功耗蓝牙配网")
return
} else {
let params = {}
params.uuid = data.uuid
params.homeId = this.homeId
params.productId = data.productId
params.ssid = this.ssid
params.password = this.password
params.timeout = 100
console.log("startConfigBLEWifiDevice params:" + JSON.stringify(params))
UTSTuya.startConfigBLEWifiDevice(params, (resp) => {
if (resp.flag) {
this.showMsg("配网中。。。")
} else {
this.showMsg("配网数据发送失败。。。resp:" + JSON.stringify(resp))
}
})
}
}
break
default:
break;
}
}
break;
// 蓝牙Wi-Fi双模配网配网成功
case "onReceiveBLEWifiConfigDeviceSuc": {
this.showMsg("配网成功!" + JSON.stringify(resp))
let data = resp.data
let error = resp.error
if (data) {
}
}
break;
// 蓝牙Wi-Fi双模配网失败
case "onReceiveBLEWifiConfigDeviceFail": {
this.showMsg("配网失败!" + JSON.stringify(resp))
}
break;
// 仅支持iOS, AP配网确认同一个Wi-Fi
case "onPassWIFIToSecurityLevelDevice": {
this.showModel("是否继续?(请确认手机连接的是同一个Wi-Fi)", () => {
UTSTuya.continueConfigSecurityLevelDevice()
})
}
break;
default:
break;
}
})
用户账号
查询验证码服务可用地区
UTSTuya.getWhiteListWhoCanSendMobileCodeSuccess((resp)=>{
if(resp.flag) {
let countryCodes = resp.countryCodes
}
})
发送手机号码验证码
UTSTuya.sendVerifyCode({
userName: this.phone, // 手机号码/邮箱账号
region: "", // 区域,默认填写:“” 即可
countryCode: this.countryCode, // 手机区号:如 “86”
type: 1 // 发送验证码类型,1:注册 2:登录 3:重置密码
}, (resp)=>{
let flag = resp.flag
if(flag) {
this.showMsg("验证码已发送")
} else {
this.showMsg("验证码发送失败:" + JSON.stringify(resp))
}
})
校验填入的验证码
UTSTuya.checkCodeWithUserName({
userName: this.phone, // 手机号码/邮箱账号
region: "", // 区域,默认填写:“” 即可
code: "", // 验证码
type: 1 // 发送验证码类型,1:注册 2:登录 3:重置密码 4:注销手机账号
}, (resp)=>{
let flag = resp.flag
if(flag) {
this.showMsg("验证码已发送")
} else {
this.showMsg("验证码发送失败:" + JSON.stringify(resp))
}
})
使用手机号码注册账号
let params = {
phoneNumber: this.phone, // 手机号
passwd: this.password, // 密码
countryCode: this.countryCode, // 手机区号
code: this.code // 验证码
};
UTSTuya.registerAccountWithPhone(params, (resp)=>{
let flag = resp.flag
if(flag) {
this.showMsg("注册成功")
} else {
this.showMsg("注册失败:" + JSON.stringify(resp))
}
})
使用手机号码和密码登录账号
let params = {
phoneNumber: this.phone, // 手机号
countryCode: this.countryCode, // 手机区号
passwd: this.password // 验证码
};
UTSTuya.loginWithPhonePassword(params, (resp) => {
var str = JSON.stringify(resp);
if (resp.flag) { // 成功
let user = resp.data;
try {
uni.setStorageSync('user', user);
} catch (e) {
// error
}
this.showMsg("登陆成功")
uni.reLaunch({
url:"/pages/index/main"
})
} else { // 失败
this.showMsg("登陆失败:" + JSON.stringify(resp));
}
});
使用手机号码和验证码登录账号
let params = {
phone: "", // 手机号
countryCode: "86",
code: "" // 验证码
};
UTSTuya.loginWithPhone(params, (resp) => {
if (resp.flag) { // 成功
} else { // 失败
}
});
重置手机号码注册的账号密码
let params = {
phone: "", // 手机号
countryCode: "86",
code: "" // 验证码
};
UTSTuya.resetPhonePassword(params, (resp) => {
if (resp.flag) { // 成功
} else { // 失败
}
});
为账号绑定邮箱地址-获取绑定验证码
let params = {
phoneNumber: "", // 手机号
countryCode: "86"
};
UTSTuya.sendBindVerifyCode(params, (resp) => {
if (resp.flag) { // 成功
} else { // 失败
}
});
为账号绑定邮箱地址-绑定邮箱地址
let params = {
email: "", // 手机号
countryCode: "86",
code: "",
sId: ""
};
UTSTuya.bindEmail(params, (resp) => {
if (resp.flag) { // 成功
} else { // 失败
}
});
使用邮箱地址注册账号
let params = {
email: this.email, // 手机号
passwd: this.password, // 密码
countryCode: this.countryCode, // 手机区号
code: this.code // 验证码
};
UTSTuya.registerAccountWithEmail(params, (resp) => {
let flag = resp.flag
if (flag) {
this.showMsg("注册成功")
} else {
this.showMsg("注册失败:" + JSON.stringify(resp))
}
})
使用邮箱地址和密码登录账号
let params = {}
params.countryCode = "86"
params.email = ""
params.passwd = ""
UTSTuya.loginWithEmail(params, (resp)=>{
})
使用邮箱地址和验证码登录账号
let params = {}
params.countryCode = "86"
params.email = ""
params.code = ""
UTSTuya.loginWithEmailCode(params, (resp)=>{
})
重置邮箱地址账户的密码
let params = {}
params.countryCode = "86"
params.email = ""
params.emailCode = ""
params.passwd = ""
UTSTuya.resetEmailPassword(params, (resp)=>{
})
为账号绑定手机号-获取绑定验证码
let params = {}
params.countryCode = "86"
params.phoneNumber = ""
UTSTuya.sendBindVerifyCode(params, (resp)=>{
})
为账号绑定手机号-绑定手机号码
let params = {}
params.countryCode = "86"
params.phoneNumber = ""
params.code = ""
UTSTuya.bindMobile(params, (resp)=>{
})
用户 UID 登录
let params = {}
params.countryCode = "86"
params.uid = ""
params.passwd = ""
// params.isCreateHome = true
UTSTuya.loginOrRegisterWithUid(params, (resp)=>{
})
微信登录
let params = {}
params.countryCode = "86"
params.code = ""
UTSTuya.loginByWechat(params, (resp)=>{
})
QQ 登录
let params = {}
params.countryCode = "86"
params.userId = ""
params.accessToken = ""
UTSTuya.loginByQQ(params, (resp)=>{
})
OAuth2 登录
let params = {}
params.countryCode = "86"
params.type = ""
params.accessToken = ""
params.extraInfo = ""
UTSTuya.thirdLogin(params, (resp)=>{
})
作为匿名用户登录
let params = {}
params.countryCode = "86"
params.nickName = ""
UTSTuya.touristRegisterAndLogin(params, (resp)=>{
})
创建家庭
let params = {};
params.name = this.name;
// Get location by yourself, here just sample as Shanghai's location
params.longitude = 120.52;
params.latitude = 30.40;
params.geoName = this.geoName; // 城市名称,如:广州、上海
params.rooms = []
UTSTuya.createHome(params, (resp) => {
if(resp.flag) { // 创建成功
this.showMsg("创建成功")
} else { // 创建失败
this.showMsg("创建失败:" + JSON.stringify(resp))
}
});
查询家庭列表
UTSTuya.getHomeList((resp) => {
if (resp.flag) {
let data = resp.data
if (data) {
this.refreshData(data)
}
} else {
uni.showToast({
title: "code:" + resp.code + " error:" + resp.error,
duration: 2000
});
}
})
获取家庭详细信息
UTSTuya.getHomeDetail(homeId, (resp) => {
if(resp.flag) {
let homeDetail = resp.data
let dataList = homeDetail.deviceList // 设备数组
}
});
设备配网
AP配网
配网结果在UTSTuya.onSetCallback的onReceiveDevice回调里
let params = {}
params.mode = "ap"
params.ssid = this.ssid
params.password = this.password
params.token = this.token
params.timeout = 100
console.log("vue startConfigWiFi params:" + JSON.stringify(params))
UTSTuya.startConfigWiFi(params)
EZ配网
配网结果在UTSTuya.onSetCallback的onReceiveDevice回调里
let params = {}
params.mode = "ez"
params.ssid = this.ssid
params.password = this.password
params.token = this.token
params.timeout = 100
console.log("vue startConfigWiFi params:" + JSON.stringify(params))
UTSTuya.startConfigWiFi(params)
低功耗蓝牙配网
先调用UTSTuya.bleWifiConfigureStart进行蓝牙扫描,扫描到设备再调用配网接口UTSTuya.startConfigBLEDevice
- 扫描蓝牙
let params = {} params.timeout = 60 * 1000 // 仅支持Android params.type = "single" // 仅支持Android UTSTuya.bleWifiConfigureStart(params)
2. 配网
```javascript
let data = resp.data
switch (uni.getSystemInfoSync().platform) {
case 'android': {
if (data.configType == "config_type_single") {
let params = {}
params.uuid = data.uuid
params.homeId = this.homeId
params.ssid = this.ssid
params.password = this.password
params.timeout = 120 * 1000
UTSTuya.startConfigBLEDevice(params, (resp) => {
if (resp.flag) {
this.showMsg("配网成功:" + JSON.stringify(resp.data))
} else {
this.showMsg("配网失败:" + JSON.stringify(resp))
}
})
} else {
}
}
break;
case "ios": {
let bleType = data.bleType
if (bleType == 1 || bleType == 2 || bleType == 5 || bleType == 3 || bleType == 8 ||
bleType ==
10) {
let params = {}
params.uuid = data.uuid
params.homeId = this.homeId
UTSTuya.startConfigBLEDevice(params, (resp) => {
if (resp.flag) {
this.showMsg("配网成功:" + JSON.stringify(resp.data))
} else {
this.showMsg("配网失败:" + JSON.stringify(resp))
}
})
} else {
this.showMsg("请使用蓝牙Wi-Fi双模配网")
}
}
break;
default:
break;
}
蓝牙Wi-Fi双模配网
先调用UTSTuya.bleWifiConfigureStart进行蓝牙扫描,扫描到设备再调用配网接口UTSTuya.startConfigBLEWifiDevice
-
蓝牙扫描
let params = {} params.timeout = 60 * 1000 // 仅支持Android params.type = "single" // 仅支持Android UTSTuya.bleWifiConfigureStart(params) -
配网 配网结果在UTSTuya.onSetCallback的回调onReceiveBLEWifiConfigDeviceSuc、onReceiveBLEWifiConfigDeviceFail
let data = resp.data
switch (uni.getSystemInfoSync().platform) {
case 'android': {
if (data.configType == "config_type_wifi") {
let params = {}
params.uuid = data.uuid
params.homeId = this.homeId
params.ssid = this.ssid
params.password = this.password
params.timeout = 120 * 1000
params.token = this.token
UTSTuya.startConfigBLEWifiDevice(params, (resp) => {
if (resp.flag) {
this.showMsg("配网中。。。")
} else {
this.showMsg("配网数据发送失败。。。resp:" + JSON.stringify(resp))
}
})
} else {
}
}
break;
case 'ios': {
let bleType = data.bleType
// typedef enum : NSUInteger {
// /// The unknown type of Bluetooth LE device.
// ThingSmartBLETypeUnknow = 1,
// /// The type of Bluetooth LE device that supports an earlier protocol. The device does not support a security protocol.
// ThingSmartBLETypeBLE,
// /// The type of Bluetooth LE device that supports an earlier protocol of a lower security level.
// ThingSmartBLETypeBLEPlus,
// /// The type of Bluetooth LE device that supports an earlier protocol. The device does not support a security protocol.
// ThingSmartBLETypeBLEWifi,
// /// The type of Bluetooth LE device that supports a later protocol of a higher security level.
// ThingSmartBLETypeBLESecurity,
// /// The type of Bluetooth LE dual-mode device that supports a later protocol of a higher security level.
// ThingSmartBLETypeBLEWifiSecurity,
// /// The type of Bluetooth LE dual-mode device that supports a later protocol of a higher security level and that supports the plug and play (PnP) function.
// ThingSmartBLETypeBLEWifiPlugPlay,
// /// The type of Bluetooth LE and Zigbee dual-mode device that supports a later protocol of a higher security level.
// ThingSmartBLETypeBLEZigbee,
// /// The type of Bluetooth LE and LTE Category 1 dual-mode device that supports a later protocol of a higher security level.
// ThingSmartBLETypeBLELTESecurity,
// /// The beacon security.
// ThingSmartBLETypeBLEBeacon,
// /// Same as the ThingSmartBLETypeBLEWifiPlugPlay, but BLE is prior while configing.
// ThingSmartBLETypeBLEWifiPriorBLE,
// } ThingSmartBLEType;
if (bleType == 1 || bleType == 2 || bleType == 5 || bleType == 3 || bleType == 8 ||
bleType ==
10) {
this.showMsg("请使用低功耗蓝牙配网")
return
} else {
let params = {}
params.uuid = data.uuid
params.homeId = this.homeId
params.productId = data.productId
params.ssid = this.ssid
params.password = this.password
params.timeout = 100
console.log("startConfigBLEWifiDevice params:" + JSON.stringify(params))
UTSTuya.startConfigBLEWifiDevice(params, (resp) => {
if (resp.flag) {
this.showMsg("配网中。。。")
} else {
this.showMsg("配网数据发送失败。。。resp:" + JSON.stringify(resp))
}
})
}
}
break
default:
break;
}
Zigbee网关配网
配网结果在UTSTuya.onSetCallback的回调onReceiveDevice里
startConfigure() {
switch (uni.getSystemInfoSync().platform) {
case 'android': {
UTSTuya.onRegisterGwSearchListener((resp)=>{
let data = resp.data
if(data) {
this.startConfigZigbeeGateway(data.gwId)
}
})
}
break;
case "ios": {
let params = {}
params.token = this.token
params.timeout = 100
UTSTuya.startConfigWiFiWithToken(params)
}
break;
default:
break;
}
},
startConfigZigbeeGateway(gwId) {
let params = {}
params.gwId = gwId
params.timeout = 100
params.token = this.token
UTSTuya.startConfigZigbeeGateway(params,(resp)=>{
if (resp.flag) {
this.showMsg("配网成功!" + JSON.stringify(resp))
} else if (error) {
this.showMsg("配网失败:" + JSON.stringify(resp))
}
})
},
Zigbee子设备配网
配网结果在UTSTuya.onSetCallback的回调onReceiveDevice里
let params = {}
params.devId = device.devId // 网关ID
params.timeout = 100
UTSTuya.startConfigZigbeeSubDevice(params)
停止配网
UTSTuya.stopConfigZigbeeSubDevice({
devId: this.devId
})
TuyaLink Bind
let homeId = value.homeId;
let params = {}
params.code = this.code
params.homeId = homeId
UTSTuya.bindThingLinkDevice(params, (resp) => {
if (resp.flag) {
this.showMsg("配网成功:" + JSON.stringify(resp))
} else {
this.showMsg("配网失败:" + JSON.stringify(resp))
}
})
设备控制
获取设备详情
// 获取涂鸦设备信息
let deviceBean = UTSTuya.getDeviceBean(devId);
console.log("deviceBean:" + JSON.stringify(deviceBean))
this.device = deviceBean.deviceModel
获取设备schema
let schemaBean = UTSTuya.getSchema(devId);
console.log("schemaBean:" + JSON.stringify(schemaBean))
this.schemaArray = schemaBean.schemaArray;
注册设备监听
监听结果在UTSTuya.onSetCallback的回调onDpUpdate、onRemoved、onStatusChanged、onNetworkStatusChanged、onDevInfoUpdate里
// 注册设备状态监听,页面卸载时移除监听
UTSTuya.registerDevListener(this.device.devId)
取消监听
UTSTuya.unRegisterDevListener(this.device.devId);
发送dps指令给设备
let dps = {};
dps[model.schema.id] = operation;
let params = {};
params.devId = this.device.devId;
params.dps = dps;
// anddroid:local、internet、auto、mqtt、http
// ios: local、internet、auto
params.publishMode = "auto"
// console.log("publishDps params:" + JSON.stringify(params))
UTSTuya.publishDps(params, (resp) => {
console.log("publishDps resp:" + JSON.stringify(resp))
if (resp.flag) {
// 指令下发成功并不是指设备真正操作成功,只是意味着成功发送指令。操作成功会有 DP 数据信息通过 registerDevListener onDpUpdate 接口返回。
// uni.showToast({
// title: "指令下发成功",
// duration: 2000
// });
} else {
uni.showToast({
title: "code:" + resp.code + " error:" + resp.error,
duration: 2000
});
}
});
查询设备信息
查询的数据通过UTSTuya.registerDevListener里的监听返回
let params = {}
params.devId = ""
params.dpId = ""
UTSTuya.getDp(params, (resp)=>{
})
删除设备
UTSTuya.remove(this.devId, (resp) => {
if (resp.flag) { // 删除成功
} else {
}
});
恢复出厂设置
UTSTuya.resetFactory(this.devId, (resp) => {
if (resp.flag) {
} else {
}
});

收藏人数:
购买源码授权版(
试用
使用 HBuilderX 导入示例项目
赞赏(0)
下载 1098
赞赏 0
下载 12694450
赞赏 1956
赞赏
京公网安备:11010802035340号