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