Last Updated on : 2024-06-27 09:49:54download
The App SDK controls devices with data points (DPs) and facilitates interaction between the device and the app through standard DPs. The Smart Camera SDK, built on top of the Smart Life App SDK, includes smart camera-specific DPs.
ThingSmartCameraDPManager
allows communication with the device, such as sending control commands and querying the current device status.ThingSmartCameraDPObserver
listens for changes in device status.API description
- (instancetype)initWithDeviceId:(NSString *)devId;
Parameters
Parameter | Description |
---|---|
devId | The device ID. |
API description
/// Adds a listener of device status.
- (void)addObserver:(id<ThingSmartCameraDPObserver>)observer;
/// Removes a listener of device status.
- (void)removeObserver:(id<ThingSmartCameraDPObserver>)observer;
Parameters
Parameter | Description |
---|---|
observer | The listener method. You need to implement ThingSmartCameraDPObserver . |
API description
This method retrieves the DP code for a DP ID.
- (NSString *)dpCodeWithDpId:(NSString *)dpId;
Example
#import <ThingSmartCameraKit/ThingSmartCameraKit.h>
NSString *dpCode = [deviceModel dpCodeWithDpId:dpId];
API description
This method retrieves the DP ID for a DP code.
- (NSString *)dpIdWithDpCode:(NSString *)dpCode;
Example
#import <ThingSmartCameraKit/ThingSmartCameraKit.h>
NSString *dpId = [deviceModel dpIdWithDpCode:dpCode];
API description
- (BOOL)isSupportDPCode:(ThingSmartCameraDPKey)DPCode;
Parameters
Parameter | Description |
---|---|
DPCode | The DP code. |
Return value
Type | Description |
---|---|
BOOL | Whether the specified DP code is supported. |
API description
Retrieve the DP value directly from the cache. If the DP is not supported, return nil.
- (id)valueForDPCode:(ThingSmartCameraDPKey)DPCode;
Parameters
Parameter | Description |
---|---|
DPCode | The DP code. |
Return value
Parameter | Description |
---|---|
id | Convert the value based on the DP data type. See Standard DPs for details. |
This method is not recommended except for memory card features.
API description
- (void)valueForDPCode:(ThingSmartCameraDPKey)DPCode success:(ThingSuccessID)success failure:(ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
DPCode | The DP code. |
success | The success callback, returning the current value of the specified DP. |
failure | The failure callback, returning an error message. |
API description
Set the value of a DP.
- (void)setValue:(id)value forDPCode:(ThingSmartCameraDPKey)DPCode success:(ThingSuccessID)success failure:(ThingFailureError)failure;
Parameters
Parameter | Description |
---|---|
value | The value of the DP. A numeric or Boolean value should be wrapped as an NSNumber . |
DPCode | The DP code. |
success | The success callback, returning the current value of the specified DP. |
failure | The failure callback, returning an error message. |
NULL
to the device. The device will then typically proactively report the value of the specified DP on receiving NULL
. The camera manufacturer implements this logic. If they do not implement it, sending NULL
will crash the camera firmware. When using this method, make sure to verify with the manufacturer that they have properly managed the NULL
logic for relevant DPs.ThingSmartCameraDPObserver
enables you to listen for DP status changes proactively reported by the device. After setting a DP value, the device will proactively report the updated value.
API description
The delegate callback to be invoked when the DP status changes.
- (void)cameraDPDidUpdate:(ThingSmartCameraDPManager *)manager dps:(NSDictionary *)dpsData;
Parameters
Parameter | Description |
---|---|
manager | The ThingSmartCameraDPManager object that triggers the callback. |
dpsData | The ID and current value of the changed DP, formatted as { dpName: value } . |
Example
Objective-C:
- (void)viewDidLoad {
[super viewDidLoad];
self.dpManager = [[ThingSmartCameraDPManager alloc] initWithDeviceId:self.devId];
[self.dpManager addObserver:self];
if ([self.dpManager isSupportDPCode:@"basic_osd"]){
self.osdSwitch = [[self.dpManager valueForDPCode:@"basic_osd"] boolValue];
}
}
- (void)openOSD {
if ([self.dpManager isSupportDPCode:@"basic_osd"]) {
__weak typeof(self) weakSelf = self;
[self.dpManager setValue:@(YES) forDPCode:@"basic_osd" success:^(id result) {
weakSelf.osdSwitch = [result boolValue];
} failure:^(NSError *error) {
// A network error.
}];
}
}
#pragma mark - ThingSmartCameraDPObserver
- (void)cameraDPDidUpdate:(ThingSmartCameraDPManager *)manager dps:(NSDictionary *)dpsData {
// The updated DPs contain the DP that enables or disables time watermarks.
if ([dpsData objectForKey:ThingSmartCameraBasicOSDDPName]) {
self.osdSwitch = [[dpsData objectForKey:ThingSmartCameraBasicOSDDPName] boolValue];
}
}
Swift:
override func viewDidLoad() {
super.viewDidLoad()
self.dpManager = ThingSmartCameraDPManager(deviceId: self.devId)
self.dpManager.addObserver(self)
if self.dpManager.isSupportDPCode("basic_osd") {
self.osdSwitch = self.dpManager.value(forDPCode: "basic_osd") as! Bool
}
}
func openOSD() {
// Determine if the device supports this feature.
guard self.dpManager.isSupportDPCode("basic_osd") else {
return
}
self.dpManager.setValue(true, forDPCode: "basic_osd", success: { result in
self.osdSwitch = result as! Bool
}) { _ in
// Network error
}
}
func cameraDPDidUpdate(_ manager: ThingSmartCameraDPManager!, dps dpsData: [AnyHashable : Any]!) {
// The updated DPs contain the DP that enables or disables time watermarks.
if let osdValue = dpsData[ThingSmartCameraDPKey.basicOSDDPName] {
self.osdSwitch = osdValue as! Bool
}
}
You can review the standard DPs for smart cameras on the Tuya Developer Platform.
See Standard DPs for details.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback