Sub-Device Pairing

Last Updated on : 2022-03-03 06:44:26

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.

Pairing process

The following figure shows the process to pair a sub-device that is connected through a Zigbee gateway.

Sub-Device Pairing

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 `TuyaSmartActivator`.
	[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) {
		 // The device is paired.
    }

    if (error) {
        // Failed to pair the device.
    }
}

Swift:

func activeSubDevice() {
    // Implements the delegate method of `TuyaSmartActivator`.
    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 {
        // 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 {
  [TuyaSmartActivator sharedInstance].delegate = nil;
	[[TuyaSmartActivator sharedInstance] stopActiveSubDeviceWithGwId:@"your_device_id"];
}

Swift:

func stopActiveSubDevice() {
    TuyaSmartActivator.sharedInstance()?.delegate = nil
    TuyaSmartActivator.sharedInstance()?.stopActiveSubDevice(withGwId: "your_device_id")
}