| | |
| | | import com.hdl.sdk.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.common.utils.IdUtils; |
| | | import com.hdl.sdk.common.utils.LogUtils; |
| | | import com.hdl.sdk.common.utils.SPUtils; |
| | | import com.hdl.sdk.common.utils.gson.GsonConvert; |
| | | import com.hdl.sdk.connect.HDLLink; |
| | | import com.hdl.sdk.connect.bean.LinkResponse; |
| | |
| | | import com.hdl.sdk.connect.bean.request.ListSidRequest; |
| | | import com.hdl.sdk.connect.bean.request.ListUploadRequest; |
| | | import com.hdl.sdk.connect.bean.response.BaseLocalResponse; |
| | | import com.hdl.sdk.connect.bean.response.BindInfoBean; |
| | | import com.hdl.sdk.connect.bean.response.GatewaySearchBean; |
| | | import com.hdl.sdk.connect.bean.response.UpdateInfo; |
| | | import com.hdl.sdk.connect.callback.HDLLinkCallBack; |
| | |
| | | import com.hdl.sdk.connect.cloud.CallBackListener; |
| | | import com.hdl.sdk.connect.cloud.CheckAppVersionListener; |
| | | import com.hdl.sdk.connect.cloud.HDLException; |
| | | import com.hdl.sdk.connect.cloud.bean.GatewayInfo; |
| | | import com.hdl.sdk.connect.cloud.listener.GatewayListener; |
| | | import com.hdl.sdk.connect.cloud.listener.SibichiListener; |
| | | import com.hdl.sdk.connect.cloud.bean.AiLoginInfo; |
| | | import com.hdl.sdk.connect.config.HDLLinkConfig; |
| | | import com.hdl.sdk.connect.socket.HDLAuthSocket; |
| | | import com.hdl.sdk.sourceos.utils.SPKey; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.security.MessageDigest; |
| | |
| | | private List<SceneBean> sceneList = new ArrayList<>(); |
| | | private List<SceneDetailBean> sceneDetailList = new ArrayList<>(); |
| | | private List<SceneDetailBean> roomSceneList = new ArrayList<>(); |
| | | private GatewayInfo gatewayInfo; |
| | | |
| | | void applyDeviceSecret() { |
| | | tv.setText("开始申请设备密钥..."); |
| | | responseTv.setText(""); |
| | | |
| | | // //正式服务器 |
| | | // String appKey = "i8hR07jzrIS";//appkey |
| | | // String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret |
| | | |
| | | //测试服务器 |
| | | String appKey = "FcRyUJlLJFF"; |
| | | String appSecret = "wz8wn75ABidx8vXcFGUotqhwFkTaYvvJ"; |
| | | |
| | | // String appKey = "L2OZliZRxHc"; |
| | | // String appSecret = "aCIWSvJDOukXfx3kivsKW11x9xdR3IbV"; |
| | | String supplier = "JINMAOYUN";//厂商 |
| | | // String mac = "AA00000000000100";//设备唯一MAC地址 |
| | | String mac = editText.getText().toString(); |
| | |
| | | Toast.makeText(this, "mac不能为空!", Toast.LENGTH_SHORT).show(); |
| | | return; |
| | | } |
| | | |
| | | HDLLink.getInstance().applyDeviceSecret(this, appKey, appSecret, supplier, mac, spk, new CallBackListener() { |
| | | //调用云端接口需初始化HDLLink.getInstance().initCloud(); |
| | | HDLLink.getInstance().applyDeviceSecret(supplier, mac, spk, new CallBackListener() { |
| | | @Override |
| | | public void onError(HDLException e) { |
| | | tv.setText("申请失败"); |
| | |
| | | tv.setText("开始检测更新..."); |
| | | responseTv.setText(""); |
| | | |
| | | // //正式服务器 |
| | | String appKey = "i8hR07jzrIS";//appkey |
| | | String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret |
| | | |
| | | String appCode = "1697150870315999233";//appCode |
| | | |
| | | HDLLink.getInstance().checkAppVersion(this, appKey, appSecret, getAppVersionName(this), appCode, new CheckAppVersionListener() { |
| | | //调用云端接口需初始化HDLLink.getInstance().initCloud(); |
| | | HDLLink.getInstance().checkAppVersion(getAppVersionName(this), appCode, new CheckAppVersionListener() { |
| | | @Override |
| | | public void onSuccess(UpdateInfo info) { |
| | | tv.setText("有新更新"); |
| | |
| | | @Override |
| | | public void onError(HDLException e) { |
| | | tv.setText("检测更新失败"); |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | void getSibichiToken() { |
| | | tv.setText("获取思必驰token..."); |
| | | responseTv.setText(""); |
| | | |
| | | BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO); |
| | | String clientId = "4ED634B5A7AD97A770A52AC00FF43805";//思必驰clientId |
| | | |
| | | //调用云端接口需初始化HDLLink.getInstance().initCloud(); |
| | | HDLLink.getInstance().getSibichiToken(bindInfoBean.getHomeId(), clientId, new SibichiListener() { |
| | | @Override |
| | | public void onSuccess(AiLoginInfo info) { |
| | | tv.setText("思必驰token"); |
| | | responseTv.setText(info.toString()); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLException e) { |
| | | tv.setText("获取思必驰token失败"); |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | void syncMainGateway() { |
| | | tv.setText("获取主网关信息..."); |
| | | responseTv.setText(""); |
| | | |
| | | BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO); |
| | | if (bindInfoBean == null) { |
| | | Toast.makeText(this, "请先扫码绑定住宅!", Toast.LENGTH_SHORT).show(); |
| | | return; |
| | | } |
| | | //调用云端接口需初始化HDLLink.getInstance().initCloud(); |
| | | HDLLink.getInstance().syncMainGateway(bindInfoBean.getHomeId(), new GatewayListener() { |
| | | @Override |
| | | public void onSuccess(GatewayInfo info) { |
| | | tv.setText("获取主网关信息"); |
| | | responseTv.setText(info.toString()); |
| | | if (info != null) { |
| | | HDLLinkConfig.getInstance().setGatewayId(info.getGatewayId()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLException e) { |
| | | tv.setText("获取主网关信息失败"); |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | }); |
| | |
| | | |
| | | selectnetwork(); |
| | | checkIfCertified(); |
| | | initDeviceInfo();//初始化 |
| | | //initDeviceInfo();//不走从机入网的方式不需要初始化 |
| | | registerAllTopicsListener(); |
| | | HDLLink.getInstance().setDeleteNetworkListener(new DeleteNetworkListener() { |
| | | @Override |
| | |
| | | beans.add(new DemoBean("获取房间场景列表")); |
| | | beans.add(new DemoBean("获取自动化列表")); |
| | | beans.add(new DemoBean("⾃动化启⽤禁⽤")); |
| | | beans.add(new DemoBean("生成二维码绑定住宅")); |
| | | beans.add(new DemoBean("获取思必驰token")); |
| | | beans.add(new DemoBean("获取网关信息")); |
| | | demoAdapter = new DemoAdapter(beans); |
| | | rv.setAdapter(demoAdapter); |
| | | |
| | |
| | | case 19: |
| | | //⾃动化启⽤禁⽤ |
| | | editEnableLogic(); |
| | | break; |
| | | case 20: |
| | | //生成二维码绑定住宅 |
| | | startSourceBindActivity(); |
| | | break; |
| | | case 21: |
| | | //获取思必驰token |
| | | getSibichiToken(); |
| | | break; |
| | | case 22: |
| | | //获取网关信息 |
| | | syncMainGateway(); |
| | | break; |
| | | } |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | void initLink() { |
| | | //step1:先生成二维码,用onpro扫码绑定住宅获取住宅信息 |
| | | BindInfoBean bindInfoBean = (BindInfoBean) SPUtils.getSerializableEntity(SPKey.BIND_HOME_INFO); |
| | | if (bindInfoBean != null) { |
| | | HDLLinkConfig.getInstance().setHomeId(bindInfoBean.getHomeId()); |
| | | HDLLinkConfig.getInstance().setLocalSecret(bindInfoBean.getLocalSecret()); |
| | | |
| | | } |
| | | //step2:再获取网关信息 |
| | | if (gatewayInfo != null) { |
| | | HDLLinkConfig.getInstance().setGatewayId(gatewayInfo.getGatewayId());//当前主网关id |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 入网认证 |
| | | */ |
| | |
| | | tv.setText("开始入网认证..."); |
| | | //认证提交参数准备 |
| | | |
| | | // 测试服务 |
| | | // String spkStr = "ir.module";//产品spk |
| | | // String macStr = "AA000000000000AF";//设备唯一MAC地址 |
| | | // String secret = "44b360eb74b7ba64";//通过spk和mac提交云端认证后分配的secret |
| | | |
| | | // 正式服务器 |
| | | //正式服务器 |
| | | String spkStr = "screen.mirror";//产品spk |
| | | String macStr = "f2c5d8bad48f";//设备唯一MAC地址 |
| | | // String secret = "e186beeb7974998e";//通过spk和mac提交云端认证后分配的secret |
| | | |
| | | String mac_key = stringToMD5(stringToMD5(macStr + secret)); |
| | | String versionString = "HDL_V1.0.1";// |
| | |
| | | tv.setText("设备功能属性读取"); |
| | | responseTv.setText(""); |
| | | List<String> sids = new ArrayList<>(); |
| | | sids.add(testLightSid); |
| | | if (devicesList.size() != 0) { |
| | | sids.add(devicesList.get(0).getSid()); |
| | | } else { |
| | | sids.add(testLightSid); |
| | | } |
| | | |
| | | HDLLink.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | |
| | | tv.setText("读取状态中..."); |
| | | responseTv.setText(""); |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(testLightSid);//要读取设备的sid |
| | | if (devicesList.size() != 0) { |
| | | list.add(devicesList.get(0).getSid()); |
| | | } else { |
| | | list.add(testLightSid);//要读取设备的sid |
| | | } |
| | | HDLLink.getInstance().propertyRead(list, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String data) { |
| | |
| | | isOn = !isOn; |
| | | List<DeviceControlRequest> requestList = new ArrayList<>(); |
| | | DeviceControlRequest request = new DeviceControlRequest(); |
| | | request.setSid(testLightSid); |
| | | if (devicesList.size() != 0) { |
| | | request.setSid(devicesList.get(0).getSid()); |
| | | } else { |
| | | request.setSid(testLightSid);//要读取设备的sid |
| | | } |
| | | List<DeviceControlRequest.StatusBean> statusBeanList = new ArrayList<>(); |
| | | DeviceControlRequest.StatusBean bean = new DeviceControlRequest.StatusBean(); |
| | | bean.setKey("on_off"); |
| | |
| | | void getRoomSceneList() { |
| | | tv.setText("获取房间场景列表"); |
| | | responseTv.setText(""); |
| | | String uid = "64a4fc6f-4eae-4d1d-82e4-40140c802c48"; |
| | | String uid = "64a4fc6f-4eae-4d1d-82e4-40140c802c48";//房间uid |
| | | |
| | | roomSceneList.clear(); |
| | | if (sceneDetailList != null && sceneDetailList.size() != 0) { |
| | |
| | | startActivity(intent); |
| | | } |
| | | |
| | | void startSourceBindActivity() { |
| | | Intent intent = new Intent(this, SourceBindActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | /** |
| | | * TCP发送 只发一次,不监听回复,不重发 |
| | | */ |