Last Updated on : 2023-05-22 06:38:25download
This QR code mode is only available to smart cameras. For more information, see QR code mode.
A wired device connects to a router over an Ethernet cable. During the pairing process, users do not need to enter the name or password of the router. The following figure shows the process to pair a Zigbee wired gateway.
The SDK provides the capability to discover the wired device that is ready for pairing. The device must be connected to the same network as the mobile phone to enable pairing. Then, register the notification of discovering a wired device. When the SDK receives the data broadcasted by the wired device, it forwards the data as a notification to the app.
Notification
// Receives the data broadcasted by the wired device and forwards the notification. `objec` is a dictionary type of data, @{@"productId":productId, @"gwId":gwId}
extern NSString *const TuyaSmartActivatorNotificationFindGatewayDevice;
Before the wired pairing process, the SDK must get a pairing token from the cloud in the networked state. The token is valid for 10 minutes and expires immediately after the device is paired. A new token must be generated if the device needs to be paired again.
API description
Get the pairing token
- (void)getTokenWithHomeId:(long long)homeId
success:(TYSuccessString)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
homeId | The ID of the home with which the device is bound. |
success | The success callback. A pairing token is returned. |
failure | The failure callback. An error message is returned. |
Example
ObjC:
- (void)getToken {
[[TuyaSmartActivator sharedInstance] getTokenWithHomeId:homeId success:^(NSString *token) {
NSLog(@"getToken success: %@", token);
// TODO: startConfigWiFi
} failure:^(NSError *error) {
NSLog(@"getToken failure: %@", error.localizedDescription);
}];
}
Swift:
func getToken() {
TuyaSmartActivator.sharedInstance()?.getTokenWithHomeId(homeId, success: { (token) in
print("getToken success: \(token)")
// TODO: startConfigWiFi
}, failure: { (error) in
if let e = error {
print("getToken failure: \(e)")
}
})
}
API description
- (void)startConfigWiFiWithToken:(NSString *)token timeout:(NSTimeInterval)timeout
Parameters
Parameter | Description |
---|---|
token | The pairing token. |
timeout | The timeout period. |
Example
ObjC:
- (void)startConfigWiFiToken:(NSString *)token {
// Implements the delegate method of `TuyaSmartActivator`.
[TuyaSmartActivator sharedInstance].delegate = self;
// Starts pairing.
[[TuyaSmartActivator sharedInstance] startConfigWiFiWithToken:token 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 startConfigWifiToken(_ token: String) {
// Implements the delegate method of `TuyaSmartActivator`.
TuyaSmartActivator.sharedInstance()?.delegate = self
// Starts pairing.
TuyaSmartActivator.sharedInstance()?.startConfigWiFi(withToken: token, 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)")
}
}
After the pairing process is started, the app continuously broadcasts the pairing data until a device is paired or the process times out. To allow users to cancel or complete pairing during the process, you must call the API method [TuyaSmartActivator stopConfigWiFi]
to stop pairing.
API description
- (void)stopConfigWiFi;
Example
ObjC:
- (void)stopConfigWifi {
[TuyaSmartActivator sharedInstance].delegate = nil;
[[TuyaSmartActivator sharedInstance] stopConfigWiFi];
}
Swift:
func stopConfigWifi() {
TuyaSmartActivator.sharedInstance()?.delegate = nil
TuyaSmartActivator.sharedInstance()?.stopConfigWiFi()
}
API description
- (void)activeSubDeviceWithGwId:(NSString *)gwId timeout:(NSTimeInterval)timeout
Parameters
Parameter | Description |
---|---|
gwId | The gateway ID. |
timeout | The timeout period. |
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)")
}
}
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")
}
This method only applies to devices that are supplied with a QR code and connected to the internet.
Returns the UUID by using the API methods in Common API Methods. The URL obtained after the device QR code is scanned is used as a request parameter to get the UUID.
Parameters
Parameter | Description |
---|---|
apiName | tuya.m.qrcode.parse |
Version | 4.0 |
postData | @{@“code”:url} |
Example
ObjC:
[self.apiRequest requestWithApiName:@"tuya.m.qrcode.parse" postData:@{@"code":url} version:@"4.0" success:^(id result) {
} failure:^(NSError *error) {
}];
Swift:
apiRequest .request(withApiName: "tuya.m.qrcode.parse", postData: ["code":url], version: "4.0", success: {_ in
}, failure: { (Error) in
})
- (void)getTokenWithUUID:(NSString *)uuid
homeId:(long long)homeId
success:(TYSuccessString)success
failure:(TYFailureError)failure;
Example
ObjC:
[[TuyaSmartActivator sharedInstance] getTokenWithUUID:uuid homeId:homeId success:^(NSString *result) {
// Returns the pairing token.
} failure:^(NSError *error) {
}];
Swift:
TuyaSmartActivator.sharedInstance()?.getTokenWithUUID(uuid, homeId: homeid, success: { (token) in
print("getToken success: \(token)")
// TODO: startConfigWiFi
}, failure: { (error) in
if let e = error {
print("getToken failure: \(e)")
}
})
- (void)startConfigWiFi:(TYActivatorMode)mode
ssid:(NSString *)ssid
password:(NSString *)password
token:(NSString *)token
timeout:(NSTimeInterval)timeout;
Example
ObjC:
[[TuyaSmartActivator sharedInstance] startConfigWiFi:TYActivatorModeEZ ssid:@"" password:@"" token:self.token timeout:Timeout];
Swift:
TuyaSmartActivator.sharedInstance()?.startConfigWiFi(TYActivatorModeEZ, ssid:nil, password: nil, token: token, timeout: Timeout)
- (void)activator:(TuyaSmartActivator *)activator didReceiveDevice:(TuyaSmartDeviceModel *)deviceModel error:(NSError *)error;
Example
ObjC:
[TuyaSmartActivator sharedInstance].delegate = self;
- (void)activator:(TuyaSmartActivator *)activator didReceiveDevice:(TuyaSmartDeviceModel *)deviceModel error:(NSError *)error {
// get deviceModel
}
Swift:
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)")
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback