Low Power Doorbell

Last Updated on : 2023-05-25 06:23:52

Check for low power doorbell

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

Example

- (BOOL)isLowPowerDevice;

Wake up a low power device from sleep mode

A low power doorbell 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 device

When success is returned in the request for wake-up of the sleep doorbell, this response only means that the wake-up command is sent to the device, but does not mean that the device is started. When the device is started, the device reports the data point (DP) ThingSmartCameraWirelessAwakeDPName with the value YES.

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 doorbell 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.
        }
    }
}