Sub-Device Pairing

Last Updated on : 2024-06-26 09:52:10download

This topic describes the mode of pairing a sub-device. This type of device is connected to the Tuya 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.

Start pairing

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)")
    }
}

Stop activating a sub-device

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")
}