Low Power Camera

Last Updated on : 2024-06-17 07:54:00download

Check for low power camera

ThingSmartDeviceModel and API methods of the IPC SDK can be called to check whether a low power camera is used.

Example

- (BOOL)isLowPowerDevice;

Wake up a low power camera from sleep mode

A low power camera is powered by batteries. This device runs in sleep mode to minimize power consumption if peer-to-peer (P2P) connections are not used within a certain period. P2P connections are unavailable in sleep mode. They can be used only after the device is woken up. The API methods of the class ThingSmartDevice are called for the wake-up.

Example

- (void)awakeDeviceWithSuccess:(nullable ThingSuccessHandler)success failure:(nullable ThingFailureError)failure;

Listen for wake-up of sleep camera

When success is returned in the request for wake-up of the sleep camera, this response only means that the wake-up command is sent to the camera, but does not mean that the camera is started. You can check whether the low power camera is awake by listening for reports of the device DP 149 (DP Code: wireless_awake). For how to listen for DP reports, see Trigger a data callback.

Example

Objective-C:

- (void)viewDidLoad {
        [super viewDidLoad];
    self.dpManager = [[ThingSmartCameraDPManager alloc] initWithDeviceId:self.devId];
        self.device = [ThingSmartDevice deviceWithDeviceId:self.devId];
        // Adds a listener for the 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)
        // Adds a listener for the 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()
}

Battery management

A lower power camera can be connected to mains power or powered by batteries. You can call the IPC SDK to query the power mode and the current battery level of the device. A threshold can be set to generate low battery alerts conditionally. After this threshold is reached, the alert will be generated.

Lock or unlock a battery

DPName DPCode DPId Description
ThingSmartCameraWirelessBatteryLockDPName wireless_batterylock 153
  • true: lock
  • false: unlock

Query battery level and device status

DPName DPCode DPId Description
ThingSmartCameraWirelessElectricityDPName wireless_electricity 145 Device battery level, an integer from 0 to 100

To send the DP data, pass in null without a parameter.

Set a threshold for low battery alerts

DPName DPCode DPId
ThingSmartCameraWirelessLowpowerDPName wireless_lowpower 147

Query power supply mode

When the power supply mode is changed, the device reports the DP status.

DPName DPCode DPId Description
ThingSmartCameraWirelessPowerModeDPName wireless_powermode 146
  • 0: powered by batteries
  • 1: connected to mains power

To send the DP data, pass in null without a parameter.

Example

Objective-C:

- (void)viewDidLoad {
        if ([self.dpManager isSupportDP:ThingSmartCameraWirelessPowerModeDPName]) {
        ThingSmartCameraPowerMode powerMode = [[self.dpManager valueForDP:ThingSmartCameraWirelessPowerModeDPName] thingsdk_toString];
        if ([powerMode isEqualToString:ThingSmartCameraPowerModePlug]) {
                        // Connected to mains power.
        }else if ([powerMode isEqualToString:ThingSmartCameraPowerModeBattery]) {
            // Powered by batteries.
        }

    }

    if ([self.dpManager isSupportDP:ThingSmartCameraWirelessElectricityDPName]) {
        NSInteger electricity = [[self.dpManager valueForDP:ThingSmartCameraWirelessElectricityDPName] thingsdk_toInt];
        NSLog(@"Current battery level: %@%%", @(electricity));
    }

    if ([self.dpManager isSupportDP:ThingSmartCameraWirelessLowpowerDPName]) {
        // If the device's battery level is lower than the threshold, an alert is triggered.
        [self.dpManager setValue:@(20) forDP:ThingSmartCameraWirelessLowpowerDPName success:^(id result) {

        } failure:^(NSError *error) {
            // A network error.
        }];
    }

    if ([self.dpManager isSupportDP:ThingSmartCameraWirelessBatteryLockDPName]) {
        // Release the battery lock to remove the battery.
        [self.dpManager setValue:@(NO) forDP:ThingSmartCameraWirelessBatteryLockDPName success:^(id result) {

        } failure:^(NSError *error) {
            // A network 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
            // Connected to mains power.
        case .battery: break
            // Powered by batteries.
        default: break
        }
    }

    if self.dpManager.isSupportDP(.wirelessElectricityDPName) {
        let electricity = self.dpManager.value(forDP: .wirelessElectricityDPName) as! Int
        print("Current battery level: ", electricity)
    }

    if self.dpManager.isSupportDP(.wirelessLowpowerDPName) {
        // If the device's battery level is lower than the threshold, an alert is triggered.
        self.dpManager.setValue(20, forDP: .wirelessLowpowerDPName, success: { _ in

        }) { _ in
            // A network error.
        }
    }

    if self.dpManager.isSupportDP(.wirelessBatteryLockDPName) {
        // Release the battery lock to remove the battery.
        self.dpManager.setValue(false, forDP: .wirelessBatteryLockDPName, success: { _ in

        }) { _ in
            // A network error.
        }
    }
}