Sub-device configuration

Last Updated on : 2022-02-17 05:25:44download

Sub-device configuration

Start network configuration

Declaration

- (void)activeSubDeviceWithGwId:(NSString *)gwId timeout:(NSTimeInterval)timeout

Parameters

Parameters Description
gwId Gateway Id
timeout Timeout, default 100 seconds

Example

Objc:

- (void)activeSubDevice {
    // Set TuyaSmartActivator delegate,impl delegate method
	[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) {
		//active success
    }

    if (error) {
        //active failure
    }
}

Swift:

func activeSubDevice() {
    // Set TuyaSmartActivator delegate,impl delegate method
    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 {
        //active success
    }

    if let e = error {
        //active failure
        print("\(e)")
    }
}

Stop activating the sub-device

The stopActiveSubDeviceWithGwId method has to be invoked if you need to cancel the network configuration or the network configuration is completed.

Declaration

- (void)stopActiveSubDeviceWithGwId:(NSString *)gwId

Parameters

Parameters Description
gwId 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")
}