Last Updated on : 2023-05-25 06:23:50
This topic describes the mode of pairing a sub-device. This type of device is connected to the Tuya IoT Cloud through a gateway such as a Zigbee gateway or Bluetooth gateway. Therefore, the pairing mode depends on a specific gateway that processes device activation and notifications.
The following figure shows the process to pair a sub-device that is connected through a Zigbee gateway.
API description
- (void)activeSubDeviceWithGwId:(NSString *)gwId timeout:(NSTimeInterval)timeout
Parameters
Parameter | Description |
---|---|
gwId | The gateway ID. |
timeout | The timeout value of a pairing task. |
Example
ObjC:
- (void)activeSubDevice {
// Implements the delegate method of `ThingSmartActivator`.
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) {
// The device is paired.
}
if (error) {
// Failed to pair the device.
}
}
Swift:
func activeSubDevice() {
// Implements the delegate method of `ThingSmartActivator`.
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 {
// The device is paired.
}
if let e = error {
// Failed to pair the device.
print("\(e)")
}
}
API description
- (void)stopActiveSubDeviceWithGwId:(NSString *)gwId
Parameters
Parameter | Description |
---|---|
gwId | The gateway ID. |
Example
ObjC:
- (void)stopActiveSubDevice {
self.subActivator.delegate = nil;
[self.subActivator stopActiveSubDeviceWithGwId:@"your_device_id"];
}
Swift:
func stopActiveSubDevice() {
subActivator.delegate = nil
subActivator.stopActiveSubDevice(withGwId: "your_device_id")
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback