English
English
简体中文
Contact Us
Register
Log In

TuyaLink-Based Device Binding

Last Updated on : 2022-09-22 12:30:12download

TuyaLink is an open solution that enables IoT devices, including proprietary network modules and smart devices, to connect to Tuya’s cloud services.

TuyaLink lowers the bar for IoT development by integrating with Tuya’s IoT Core technologies, including things data model, rule engines, data parsing, device management, operations and monitoring, alert management, OTA firmware updates, and application development.

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.

TuyaLink-Based Device Binding

For more information, see TuyaLink.

Bind a device

Each TuyaLink-based device is created with a QR code on the Tuya IoT Development Platform. To bind a TuyaLink-based device with the app, users scan the QR code of the device first. The system parses the URL of the QR code and returns a universally unique identifier (UUID) of the device. Then, the UUID is used in the API request to bind the device.

API description

- (void)bindTuyaLinkDeviceWithQRCode:(NSString *)code
                              homeId:(long long)homeId
                             success:(void (^)(TuyaSmartDeviceModel *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

ObjC:

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

Swift:

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