1.1. Low power doorbell

1.1.1. Sleep and wake

Low power doorbell is powered by battery. In order to save power, camera will sleep when no p2p connection for a certain period of time. After sleeping, it cannot be directly connected to p2p. You need to wake up the device, and then connect to the p2p channel after waking up.

Declaration

void wirelessWake(String localkey, String devId);

Parameter

Parameter Description
localkey Device localkey
devId device Id

Example

mDeviceControl = TuyaCameraDeviceControlSDK.getCameraDeviceInstance(devId);
//wake up
mDeviceControl.wirelessWake(localkey, devId); 
//connect
camera.connect(p2pId, p2pWd,localKey);

1.1.2. Doorbell call

When the device is successfully bound to the home and online, when someone rings the doorbell, the SDK will receive the event of the doorbell call.

Integrated push notification

Integrated push, Press the doorbell and the app receives the push message.

Registration Tuya push protocol

The premise is that the APP process is active.

registerCameraPushListener

After logging in to your tuya account, register registerCameraPushListener.

 void registerCameraPushListener(ITuyaGetBeanCallback<CameraPushDataBean> callback);

Parameter Description

Parameter Description
ITuyaGetBeanCallback get data callback
CameraPushDataBean 消息体数据模型

CameraPushDataBean

Parameter Description
timestamp message time stamp
devid device id
msgid message id
etype message Type

Note: etype = doorbell for doorbell message

unRegisterCameraPushListener

After logging out of the tuya account, unregister and call unRegisterCameraPushListener

void unRegisterCameraPushListener(ITuyaGetBeanCallback<CameraPushDataBean> callback);

Sample Code

   package com.tuya.smart.android.demo.base.utils;

   import android.app.Activity;
   import android.content.Context;
   import android.content.Intent;
   import android.os.Bundle;

   import com.tuya.smart.android.camera.api.ITuyaHomeCamera;
   import com.tuya.smart.android.camera.api.bean.CameraPushDataBean;
   import com.tuya.smart.android.common.utils.L;
   import com.tuya.smart.android.demo.R;
   import com.tuya.smart.android.demo.login.activity.LoginActivity;
   import com.tuya.smart.android.demo.base.app.Constant;
   import com.tuya.smart.api.MicroContext;
   import com.tuya.smart.home.sdk.TuyaHomeSdk;
   import com.tuya.smart.sdk.api.ITuyaGetBeanCallback;
   import com.tuyasmart.stencil.utils.BaseActivityUtils;

   import static com.tuya.smart.camera.utils.IntentUtils.INTENT_CONTENT;
   import static com.tuya.smart.camera.utils.IntentUtils.INTENT_DEVID;
   import static com.tuya.smart.camera.utils.IntentUtils.INTENT_MSGID;
   import static com.tuya.smart.camera.utils.IntentUtils.INTENT_TITLE;


   /**
    * Created by letian on 16/7/15.
    */
   public class LoginHelper {
       private static final String TAG = "LoginHelper";
       private static ITuyaHomeCamera homeCamera;

       private static ITuyaGetBeanCallback<CameraPushDataBean> mTuyaGetBeanCallback = new ITuyaGetBeanCallback<CameraPushDataBean>() {
           @Override
           public void onResult(CameraPushDataBean o) {
               L.d(TAG, "onMqtt_43_Result on callback");
               L.d(TAG, "timestamp=" + o.getTimestamp());
               L.d(TAG, "devid=" + o.getDevId());
               L.d(TAG, "msgid=" + o.getEdata());
               L.d(TAG, "etype=" + o.getEtype());

           }
       };

       public static void afterLogin() {

           //there is the somethings that need to set.For example the lat and lon;
           //   TuyaSdk.setLatAndLong();
           homeCamera = TuyaHomeSdk.getCameraInstance();
           if (homeCamera != null) {
               homeCamera.registerCameraPushListener(mTuyaGetBeanCallback);
           }
       }

       private static void afterLogout() {
           L.d(TAG, "afterLogout unregister thread " + Thread.currentThread().getName());
           if (homeCamera != null) {
               homeCamera.unRegisterCameraPushListener(mTuyaGetBeanCallback);
           }
           homeCamera = null;
       }

       /**
        *
        * @param context
        */
       public static void reLogin(Context context) {
           reLogin(context, true);
       }

       public static void reLogin(Context context, boolean tip) {
           onLogout(context);
           if (tip) {
               ToastUtil.shortToast(context, R.string.login_session_expired);
           }
           ActivityUtils.gotoActivity((Activity) context, LoginActivity.class, ActivityUtils.ANIMATE_FORWARD, true);
       }

       private static void onLogout(Context context) {
           afterLogout();
           exit(context);
       }

       /**
        *
        * @param context
        */
       public static void exit(Context context) {
           Constant.finishActivity();
           TuyaHomeSdk.onDestroy();
       }
   }

Note: When the app process is killed, the listener is invalid. When the app logs in successfully, register for monitoring; when the app logs out, cancel the monitoring.

1.1.3. Battery management

There are two ways to power low-power doorbells, plug-in and battery-powered. The SDK can query the current power supply mode and current power of the device. You can also set a low battery alarm threshold. When the battery is too low, an alarm notification will be triggered.

Battery lock data publish

Example

mTuyaCameraDevice.registorTuyaCameraDeviceControlCallback(DpWirelessBatterylock.ID, new ITuyaCameraDeviceControlCallback<Boolean>() {
  @Override
  public void onSuccess(String s, DpNotifyModel.ACTION action, DpNotifyModel.SUB_ACTION sub_action, Boolean o) {
    showPublishTxt.setText("LAN/Cloud query result: " + o);
  }

  @Override
  public void onFailure(String s, DpNotifyModel.ACTION action, DpNotifyModel.SUB_ACTION sub_action, String s1, String s2) {

  }
});
mTuyaCameraDevice.publishCameraDps(DpWirelessBatterylock.ID, true);

Batter and device status info data publish

Example

mTuyaCameraDevice.registorTuyaCameraDeviceControlCallback(DpWirelessElectricity.ID, new ITuyaCameraDeviceControlCallback<Integer>() {
  @Override
  public void onSuccess(String s, DpNotifyModel.ACTION action, DpNotifyModel.SUB_ACTION sub_action, Integer o) {
    showPublishTxt.setText("LAN/Cloud query result: " + o);
  }

  @Override
  public void onFailure(String s, DpNotifyModel.ACTION action, DpNotifyModel.SUB_ACTION sub_action, String s1, String s2) {

  }
});
mTuyaCameraDevice.publishCameraDps(DpWirelessElectricity.ID, null);

Tip: DpWirelessElectricity data publish only needs null value (dose not require parameters).

Low battery alarm value data publish

Example

mTuyaCameraDevice.registorTuyaCameraDeviceControlCallback(DpWirelessLowpower.ID, new ITuyaCameraDeviceControlCallback<Integer>() {
  @Override
  public void onSuccess(String s, DpNotifyModel.ACTION action, DpNotifyModel.SUB_ACTION sub_action, Integer o) {
    showPublishTxt.setText("LAN/Cloud query result: " + o);
  }

  @Override
  public void onFailure(String s, DpNotifyModel.ACTION action, DpNotifyModel.SUB_ACTION sub_action, String s1, String s2) {

  }
});
mTuyaCameraDevice.publishCameraDps(DpWirelessLowpower.ID, 20);

Power supply method data publish

Example

mTuyaCameraDevice.registorTuyaCameraDeviceControlCallback(DpWirelessPowermode.ID, new ITuyaCameraDeviceControlCallback<String>() {
                @Override
                public void onSuccess(String s, DpNotifyModel.ACTION action, DpNotifyModel.SUB_ACTION sub_action, String o) {
                    showPublishTxt.setText("LAN/Cloud query result: " + o);
                }

                @Override
                public void onFailure(String s, DpNotifyModel.ACTION action, DpNotifyModel.SUB_ACTION sub_action, String s1, String s2) {

                }
            });
mTuyaCameraDevice.publishCameraDps(DpWirelessPowermode.ID, null);

Tip: DpWirelessPowermode data publish only needs null value (dose not require parameters).

results matching ""

    No results matching ""