1.1. 低功耗门铃

1.1.1. 休眠唤醒

低功耗门铃由电池供电,为了节省电量,在一定时间内没有 p2p 连接会休眠,休眠后无法直接连接 p2p,需要先唤醒设备,再连接 p2p 通道。

接口说明

void wirelessWake(String localKey, String devId);

示例代码

String mDevId = devBean.getDevId();
String mLocalkey = devBean.getLocalKey();
mTuyaCameraDevice.wirelessWake(mDevId,mLocalkey);

1.1.2. 门铃呼叫

设备成功绑定到家庭且在线状态下,有人按门铃,IPC SDK 将收到门铃呼叫的事件。

集成推送通知

集成推送,按门铃,app 端收到推送消息。

注册涂鸦推送协议

前提: APP 进程处于 active 状态

registerCameraPushListener

在登录 tuya 账号后,注册 registerCameraPushListener ,调用方法:

 void registerCameraPushListener(ITuyaGetBeanCallback<CameraPushDataBean> callback);

参数说明

参数 说明
ITuyaGetBeanCallback 收到消息数据的回调
CameraPushDataBean 消息体数据模型

CameraPushDataBean

参数 描述
timestamp 消息时间戳
devid 设备 id
msgid 消息 id
etype 消息类型

Note: 门铃来电消息的 etype=doorbell

unRegisterCameraPushListener

在退出 tuya 账号后,反注册,调用 unRegisterCameraPushListener

void unRegisterCameraPushListener(ITuyaGetBeanCallback<CameraPushDataBean> callback);

示例代码

   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: 当app进程被杀死的时候,该监听无效。当app登录成功之后,注册监听;app退出登录,取消监听

1.1.3. 电池管理

低功耗门铃有两种供电方式,插电和电池供电。通过 IPC SDK 可以查询到设备当前的供电模式以及当前的电量。还可以设置一个低电量报警阈值,当电量过低时,会触发一个报警通知。

电池锁的数据下发

示例代码

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);

电池及设备状态信息的数据下发

示例代码

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);

注意:DpWirelessElectricity数据下发不需要带参数,所以传null值即可。

低电量报警阈值的数据下发

示例代码

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);

设备供电方式的数据下发

示例代码

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);

注意:DpWirelessPowermode 数据下发不需要带参数,所以传null值即可。

results matching ""

    No results matching ""