更新时间:2024-09-06 03:24:44下载pdf
子设备配网是指智能设备依赖于网关连接到涂鸦,例如 Zigbee 网关、蓝牙网关等。因此,子设备配网的过程必须具体到某个网关,由网关完成设备激活和消息通知。
下图以 Zigbee 网关为例,描述子设备配网流程:
接口说明
- (void)activeSubDeviceWithGwId:(NSString *)gwId timeout:(NSTimeInterval)timeout
参数说明
参数 | 说明 |
---|---|
gwId | 网关 ID |
timeout | 超时时间 |
示例代码
Objc:
- (void)activeSubDevice {
// 设置 TuyaSmartActivator 的 delegate,并实现 delegate 方法
[TuyaSmartActivator sharedInstance].delegate = self;
[[TuyaSmartActivator sharedInstance] activeSubDeviceWithGwId:@"your_device_id" timeout:100];
}
#pragma mark - TuyaSmartActivatorDelegate
- (void)activator:(TuyaSmartActivator *)activator didReceiveDevice:(TuyaSmartDeviceModel *)deviceModel error:(NSError *)error {
if (!error && deviceModel) {
// 配网成功
}
if (error) {
// 配网失败
}
}
Swift:
func activeSubDevice() {
// 设置 TuyaSmartActivator 的 delegate,并实现 delegate 方法
TuyaSmartActivator.sharedInstance()?.delegate = self
TuyaSmartActivator.sharedInstance()?.activeSubDevice(withGwId: "your_device_id", timeout: 100)
}
#pragma mark - TuyaSmartActivatorDelegate
func activator(_ activator: TuyaSmartActivator!, didReceiveDevice deviceModel: TuyaSmartDeviceModel!, error: Error!) {
if deviceModel != nil && error == nil {
//配网成功
}
if let e = error {
//配网失败
print("\(e)")
}
}
接口说明
- (void)stopActiveSubDeviceWithGwId:(NSString *)gwId
参数说明
参数 | 说明 |
---|---|
gwId | 网关 ID |
示例代码
Objc:
- (void)stopActiveSubDevice {
[TuyaSmartActivator sharedInstance].delegate = nil;
[[TuyaSmartActivator sharedInstance] stopActiveSubDeviceWithGwId:@"your_device_id"];
}
Swift:
func stopActiveSubDevice() {
TuyaSmartActivator.sharedInstance()?.delegate = nil
TuyaSmartActivator.sharedInstance()?.stopActiveSubDevice(withGwId: "your_device_id")
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈