更新时间:2023-05-25 06:23:52
根据 ThingSmartDeviceModel
和 IPC SDK 中的接口,可以判断设备是否为低功耗设备。
示例代码
- (BOOL)isLowPowerDevice;
低功耗门铃由电池供电,为了节省电量,在一定时间内没有 P2P(Peer-2-peer)连接会休眠。休眠后无法直接连接 P2P,您需要先唤醒设备,再连接 P2P 通道。使用 ThingSmartDevice
类提供的接口来唤醒设备。
示例代码
- (void)awakeDeviceWithSuccess:(nullable ThingSuccessHandler)success failure:(nullable ThingFailureError)failure;
当唤醒休眠的低功耗设备返回 success
调用时,只是表示唤醒命令已经成功下发给门铃设备,并不代表门铃设备已启动。当门铃设备启动时,会通过设备功能点 ThingSmartCameraWirelessAwakeDPName
上报 YES
。
示例代码
Objective C:
- (void)viewDidLoad {
[super viewDidLoad];
self.dpManager = [[ThingSmartCameraDPManager alloc] initWithDeviceId:self.devId];
self.device = [ThingSmartDevice deviceWithDeviceId:self.devId];
// 添加 DP 监听
[self.dpManager addObserver:self];
[self start];
}
- (void)start {
if (self.isConnected) {
[self.videoContainer addSubview:self.camera.videoView];
self.camera.videoView.frame = self.videoContainer.bounds;
[self.camera startPreview];
}else if (!self.isConnecting) {
if (self.device.deviceModel.isLowPowerDevice) {
[self.device awakeDeviceWithSuccess:nil failure:nil];
}
[self.camera connect];
self.isConnecting = YES;
}
}
Swift:
func viewDidLoad() {
super.viewDidLoad()
self.dpManager = ThingSmartCameraDPManager(deviceId: self.devId)
self.device = ThingSmartDevice(deviceId: self.devId)
// 添加 DP 监听
self.dpManager?.addObserver(self)
self.start()
}
func start() {
guard self.isConnected || self.isConnecting else {
if self.device?.deviceModel.isLowPowerDevice() {
self.device?.awake(success: nil, failure: nil)
}
self.camera.connect()
self.isConnecting = true
return
}
self.videoContainer.addSubView(self.camera.videoView)
self.camera.videoView.frame = self.videoContainer.bounds
self.camera.startPreview()
}
低功耗门铃有两种供电方式,插电供电和电池供电。通过 IPC SDK,您可以查询设备当前的供电模式以及当前的电量,还可以设置一个低电量报警阈值,当电量过低时,触发一个报警通知。
DPName | DPCode | DPId | 值说明 |
---|---|---|---|
ThingSmartCameraWirelessBatteryLockDPName | wireless_batterylock | 153 |
|
DPName | DPCode | DPId | 值说明 |
---|---|---|---|
ThingSmartCameraWirelessElectricityDPName | wireless_electricity | 145 | 设备电量是上报 0-100 的整数 |
该 DP 下发不需要携带参数,所以传 null 值即可。
DPName | DPCode | DPId |
---|---|---|
ThingSmartCameraWirelessLowpowerDPName | wireless_lowpower | 147 |
设备供电方式,设备供电方式发生变化时,会上报。
DPName | DPCode | DPId | 值说明 |
---|---|---|---|
ThingSmartCameraWirelessPowerModeDPName | wireless_powermode | 146 |
|
该 DP 下发不需要携带参数,所以传 null 值即可。
示例代码
Objective C:
- (void)viewDidLoad {
if ([self.dpManager isSupportDP:ThingSmartCameraWirelessPowerModeDPName]) {
ThingSmartCameraPowerMode powerMode = [[self.dpManager valueForDP:ThingSmartCameraWirelessPowerModeDPName] thingsdk_toString];
if ([powerMode isEqualToString:ThingSmartCameraPowerModePlug]) {
// 插电供电
}else if ([powerMode isEqualToString:ThingSmartCameraPowerModeBattery]) {
// 电池供电
}
}
if ([self.dpManager isSupportDP:ThingSmartCameraWirelessElectricityDPName]) {
NSInteger electricity = [[self.dpManager valueForDP:ThingSmartCameraWirelessElectricityDPName] thingsdk_toInt];
NSLog(@"设备当前的电量为:%@%%", @(electricity));
}
if ([self.dpManager isSupportDP:ThingSmartCameraWirelessLowpowerDPName]) {
// 设置电量低于 20% 时,触发低电量警告
[self.dpManager setValue:@(20) forDP:ThingSmartCameraWirelessLowpowerDPName success:^(id result) {
} failure:^(NSError *error) {
// 网络错误
}];
}
if ([self.dpManager isSupportDP:ThingSmartCameraWirelessBatteryLockDPName]) {
// 解除电池锁,以拆卸电池
[self.dpManager setValue:@(NO) forDP:ThingSmartCameraWirelessBatteryLockDPName success:^(id result) {
} failure:^(NSError *error) {
// 网络错误
}];
}
}
Swift:
override func viewDidLoad() {
super.viewDidLoad()
if self.dpManager.isSupportDP(.wirelessPowerModeDPName) {
let powerMode = self.dpManager.value(forDP: .wirelessPowerModeDPName) as! String
switch ThingSmartCameraPowerMode(rawValue: powerMode) {
case .plug: break
// 插电供电
case .battery: break
// 电池供电
default: break
}
}
if self.dpManager.isSupportDP(.wirelessElectricityDPName) {
let electricity = self.dpManager.value(forDP: .wirelessElectricityDPName) as! Int
print("设备当前的电量为:", electricity)
}
if self.dpManager.isSupportDP(.wirelessLowpowerDPName) {
// 设置电量低于 20% 时,触发低电量警告
self.dpManager.setValue(20, forDP: .wirelessLowpowerDPName, success: { _ in
}) { _ in
// 网络错误
}
}
if self.dpManager.isSupportDP(.wirelessBatteryLockDPName) {
// 解除电池锁,以拆卸电池
self.dpManager.setValue(false, forDP: .wirelessBatteryLockDPName, success: { _ in
}) { _ in
// 网络错误
}
}
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈