Last Updated on : 2024-09-06 03:34:39download
The device pairing modes supported by Powered by Tuya
cameras include:
Wi-Fi Easy Connect (EZ) mode, also known as the SmartConfig mode
Hotspot mode (AP mode)
QR code mode
QR code mode is relatively simple. We recommend that you use the QR code mode. If the device can not scan the QR code, try the Wi-Fi EZ mode.
EZ mode and AP mode are the same for other Powered by Tuya
devices. For more information, see Pair devices.
The following sections focus on the QR code mode for smart cameras.
Flow chart
Class and Protocol
Class (Protocol) | Description |
---|---|
TuyaSmartActivator | Network configuration package |
TuyaSmartActivatorDelegate | Network configuration result delegate |
Declaration
Get token from service.
- (void)getTokenWithHomeId:(long long)homeId
success:(TYSuccessString)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
homeId | The home id of which the device will be bound |
success | Success callback, response token |
failure | Failure callback, the error indicates the reason of failure |
Declaration
Start network configuration.
- (void)startConfigWiFi:(TYActivatorMode)mode
ssid:(NSString *)ssid
password:(NSString *)password
token:(NSString *)token
timeout:(NSTimeInterval)timeout;
Parameters
Parameter | Description |
---|---|
mode | Configuration mode |
ssid | Ssid of Wi-Fi |
password | Password of Wi-Fi |
token | Token |
timeout | Timeout |
Declaration
Stop network configuration.
- (void)stopConfigWiFi;
Declaration
Network configuration result delegate callback.
- (void)activator:(TuyaSmartActivator *)activator didReceiveDevice:(TuyaSmartDeviceModel *)deviceModel error:(NSError *)error;
Parameters
Parameter | Description |
---|---|
activator | TuyaSmartActivator object |
deviceModel | TuyaSmartDeviceModel object, nil if failed |
error | Indicates the reason of failure, nil if succeed |
Before starting network configuration, the SDK needs to get the token from the service, and then generate the QR code with the SSID of Wi-Fi and the password. The Token is valid for 10 minutes and will be invalidated upon successful pairing. To pair the device again, a new QR code must be generated. The device must be bound in a home, so the token is associated with the home ID. After the device is successfully activated with this token, the device is displayed in the device list of this home.
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)")
}
})
}
After got the token, the SSID and password of the wi-fi which the device is expected to connect are also needed, which are concatenated into a string in the following way, and then a QR code picture is generated according to this string.
Example
ObjC
NSDictionary *dictionary = @{
@"s": self.ssid,
@"p": self.pwd,
@"t": self.token
};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];
self.wifiJsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
Swift
let dictionary = [
"s": self.ssid,
"p": self.pwd,
"t": self.token
]
let jsonData = JSONSerialization.data(withJSONObject: dictionary, options: JSONSerialization.WritingOptions.Element)
self.wifiJsonStr = String(data: jsonData, encoding: String.Encoding.utf8)
Use the wifiJsonStr
to generate the QR code, reset the device, point the QR code at the camera, and the device will sound a prompt after capturing the information of the QR code. At this point, start listening to the distribution results through the following interface.
Example
ObjC
[[TuyaSmartActivator sharedInstance] startConfigWiFi:TYActivatorModeQRCode ssid:self.ssid password:self.pwd token:self.token timeout:100];
Swift
TuyaSmartActivator.sharedInstance()?.startConfigWiFi(TYActivatorModeQRCode, ssid: self.ssid, password: self.pwd, token: self.token, timeout: 100)
Use this method to stop pairing.
Example
ObjC
[[TuyaSmartActivator sharedInstance] stopConfigWiFi];
Swift
TuyaSmartActivator.sharedInstance()?.stopConfigWiFi()
The result of pairing is returned by TuyaSmartActivatorDelegate
.
Example
ObjC
- (void)activator:(TuyaSmartActivator *)activator didReceiveDevice:(TuyaSmartDeviceModel *)deviceModel error:(NSError *)error {
if (deviceModel) {
// success
}else {
// error
}
}
Swift
func activator(_ activator: TuyaSmartActivator!, didReceiveDevice deviceModel: TuyaSmartDeviceModel?, error: Error!) {
if deviceModel != nil {
// success
}else {
// error
}
}
Powered by Tuya
cameras support three binding modes: strong, medium, and weak. After the device is successfully activated in a home of the account, different binding modes and different verification methods are required for unbinding.
Powered by Tuya
cameras support the strong binding mode, and cannot change to other modes. If you have a strong demand and have evaluated the impact of changing the binding mode, you can submit a ticket to request technical support.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback