TuyaLink-Based Device Binding

Last Updated on : 2024-03-04 07:25:38

TuyaLink is an open solution that enables IoT devices, including proprietary network modules and smart devices, to connect to Tuya’s cloud services. TuyaLink allows you to quickly integrate with the Tuya ecosystem and achieve interconnectivity between devices across different domains. A range of development resources for PaaS, SaaS, and apps helps you implement IoT projects with improved cost efficiency and reduced lead time. For more information, see TuyaLink.

Bind a device

Each TuyaLink-based device is created with a QR code on the Tuya IoT Development Platform. You can scan the QR code, transfer the URL to the device binding API, and thus bind the device.

API description

- (void)bindThingLinkDeviceWithQRCode:(NSString *)code
                               homeId:(long long)homeId
                              success:(void (^)(ThingSmartDeviceModel *deviceModel))success
                              failure:(TYFailureError)failure;

Parameters

Parameter Description
code The content to be extracted from a QR code. It is a URL in most cases.
homeId The home ID.
success The success callback. A device model is returned.
failure The failure callback. An error message is returned.

Example

Objective-C:

- (void)bindThingLinkWithQRCodeStr:(NSString *)codeStr {
    TuyaSmartThingLinkActivator *activator = [TuyaSmartThingLinkActivator new];
    [activator bindThingLinkDeviceWithQRCode:codeStr homeId:self.homeId success:^(TuyaSmartDeviceModel * _Nonnull deviceModel) {
        NSLog(@"Bind Success. %@", deviceModel.devId);
    } failure:^(NSError *error) {
        NSLog(@"Bind Failure. %@", error)
    }];
}

Swift:

func bindThingLink(qrcode codeStr: String) -> Void {
  let activator = TuyaSmartThingLinkActivator.init()
  activator.bindThingLinkDevice(withQRCode: codeStr, homeId: homeId) { device in
    print("Bind Success. \(device.devId) ");
  } failure: { error in
    print("Bind Failure. \(error?.localizedDescription ?? "") ");
  }
}