| | |
| | | import androidx.activity.result.ActivityResultCallback; |
| | | import androidx.activity.result.ActivityResultLauncher; |
| | | import androidx.activity.result.contract.ActivityResultContracts; |
| | | import androidx.annotation.NonNull; |
| | | |
| | | import androidx.annotation.RequiresApi; |
| | | import androidx.appcompat.app.AppCompatActivity; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Intent; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | |
| | | |
| | | import com.chad.library.adapter.base.BaseQuickAdapter; |
| | | import com.chad.library.adapter.base.listener.OnItemClickListener; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlsdk.device.DevicesListActivity; |
| | | import com.hdl.sdk.common.config.TopicConstant; |
| | | import com.hdl.sdk.common.event.EventListener; |
| | | import com.hdl.sdk.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.common.utils.IdUtils; |
| | | import com.hdl.sdk.common.utils.IpUtils; |
| | | import com.hdl.sdk.common.utils.gson.GsonConvert; |
| | | import com.hdl.sdk.connect.HDLLink; |
| | | import com.hdl.sdk.connect.bean.LinkRequest; |
| | | import com.hdl.sdk.connect.bean.LinkResponse; |
| | | import com.hdl.sdk.connect.bean.request.AuthenticateRequest; |
| | | import com.hdl.sdk.connect.bean.request.PropertyReadRequest; |
| | | import com.hdl.sdk.connect.bean.response.BaseLocalResponse; |
| | | import com.hdl.sdk.connect.bean.response.GatewaySearchBean; |
| | | import com.hdl.sdk.connect.callback.HDLLinkCallBack; |
| | | import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack; |
| | | import com.hdl.sdk.connect.config.HDLLinkConfig; |
| | | import com.hdl.sdk.connect.socket.HDLAuthSocket; |
| | | import com.hdl.sdk.connect.socket.HDLSocket; |
| | | import com.hdl.sdk.connect.bean.request.DeviceControlRequest; |
| | | import com.hdl.sdk.connect.protocol.LinkMessageDecoder; |
| | | import com.hdl.sdk.connect.protocol.LinkMessageEncoder; |
| | | import com.hdl.sdk.socket.SocketOptions; |
| | | import com.hdl.sdk.socket.codec.MessagePipeLine; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.bean.LinkFunctionBean; |
| | | import com.hdl.sdk.link.bean.LinkSceneBean; |
| | | import com.hdl.sdk.link.common.config.TopicConstant; |
| | | import com.hdl.sdk.link.common.event.EventListener; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.link.common.utils.IdUtils; |
| | | import com.hdl.sdk.link.common.utils.gson.GsonConvert; |
| | | import com.hdl.sdk.link.core.bean.LinkResponse; |
| | | import com.hdl.sdk.link.core.bean.request.AuthenticateRequest; |
| | | import com.hdl.sdk.link.core.bean.request.DeviceControlRequest; |
| | | import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; |
| | | import com.hdl.sdk.link.core.bean.response.GatewaySearchBean; |
| | | import com.hdl.sdk.link.core.callback.HDLLinkCallBack; |
| | | import com.hdl.sdk.link.core.callback.HDLLinkResponseCallBack; |
| | | import com.hdl.sdk.link.core.callback.HDLLinkTCallBack; |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.core.connect.HDLUdpConnect; |
| | | |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.security.MessageDigest; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static com.hdl.sdk.common.config.TopicConstant.GATEWAY_SEARCH_REPLY; |
| | | |
| | | public class MainActivity extends AppCompatActivity { |
| | | |
| | |
| | | private TextView responseTv; |
| | | boolean isOn; |
| | | private EventListener allTopicsListener; |
| | | private String testLightSid = "0001010D48C71B02020100010101"; |
| | | private String testLightSid = "1493092497588469761"; |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | |
| | | removeAllTopicsListener(); |
| | | } |
| | | |
| | | /** |
| | | * 初始化HDLSDK |
| | | */ |
| | | void initHDLSDK() { |
| | | HDLLinkLocalSdk.getInstance().init("1530018255883706369","735c1677504a7034"); |
| | | } |
| | | |
| | | /** |
| | | * 三方设备集成到HDL时,需要初始化的信息 |
| | | */ |
| | | void initThird(){ |
| | | initDeviceInfo();//初始化基本信息,非常重要,认证时要用 |
| | | checkIfCertified();//检测是否已经认证了,用于判断 |
| | | } |
| | | |
| | | @RequiresApi(api = Build.VERSION_CODES.O) |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | setContentView(R.layout.activity_main); |
| | | responseTv = findViewById(R.id.response_tv); |
| | | tv = findViewById(R.id.state_tv); |
| | | rv = findViewById(R.id.rv); |
| | | rv.setLayoutManager(new LinearLayoutManager(this)); |
| | | |
| | | checkIfCertified(); |
| | | initDeviceInfo(); |
| | | registerAllTopicsListener(); |
| | | initView(); |
| | | initHDLSDK();//这步比较重要,在使用前要设置好当前网关Id及加解密钥 |
| | | // initThird();//三方设备集成时要初始化 |
| | | registerAllTopicsListener();//注册监听接收所有主题的数据 |
| | | |
| | | ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { |
| | | @Override |
| | |
| | | |
| | | } |
| | | }); |
| | | |
| | | //初始化安卓权限 |
| | | launcher.launch(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}); |
| | | |
| | | final List<DemoBean> beans = new ArrayList<>(); |
| | |
| | | rv.setAdapter(demoAdapter); |
| | | |
| | | |
| | | // final SocketOptions options = new SocketOptions(); |
| | | // |
| | | // MessagePipeLine pipeLine = new MessagePipeLine(); |
| | | // options.setHandleMessage(pipeLine); |
| | | // options.setEnabledHeartbeat(false); |
| | | |
| | | demoAdapter.setOnItemClickListener(new OnItemClickListener() { |
| | | @Override |
| | | public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) { |
| | | public void onItemClick(BaseQuickAdapter<?, ?> adapter, View view, int position) { |
| | | switch (position) { |
| | | case 0: |
| | | //入网认证 |
| | |
| | | break; |
| | | case 8: |
| | | //功能列表 |
| | | startDevicesListActivity(); |
| | | // startDevicesListActivity(); |
| | | break; |
| | | case 9: |
| | | //UDP发送 |
| | |
| | | } |
| | | }); |
| | | } |
| | | //初始化控件 |
| | | void initView(){ |
| | | responseTv = findViewById(R.id.response_tv); |
| | | tv = findViewById(R.id.state_tv); |
| | | rv = findViewById(R.id.rv); |
| | | rv.setLayoutManager(new LinearLayoutManager(this)); |
| | | } |
| | | |
| | | |
| | | public void showToast(String text) { |
| | |
| | | * 检测是否认证过 |
| | | */ |
| | | void checkIfCertified() { |
| | | boolean isCertified = HDLLink.getInstance().checkIfCertified(); |
| | | boolean isCertified = HDLLinkLocalSdk.getInstance().checkIfCertified(); |
| | | String mes = isCertified ? "已经认证过" : "未认证"; |
| | | showToast(mes); |
| | | tv.setText(mes); |
| | |
| | | handleLinkResponse(response); |
| | | } |
| | | }; |
| | | HDLLink.getInstance().registerAllTopicsListener(allTopicsListener); |
| | | HDLLinkLocalSdk.getInstance().registerAllTopicsListener(allTopicsListener); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } else { |
| | | //其它主题 |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | * 移除所有主题数据的监听 |
| | | */ |
| | | void removeAllTopicsListener() { |
| | | HDLLink.getInstance().removeAllTopicsListener(allTopicsListener); |
| | | HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener); |
| | | } |
| | | |
| | | void initDeviceInfo() |
| | | { |
| | | void initDeviceInfo() { |
| | | AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean(); |
| | | infoBean.setDeviceMAC("123456789"); |
| | | infoBean.setIPMAC("12345678900"); |
| | | infoBean.setDeviceMAC("AA00000000000100"); |
| | | infoBean.setIPMAC("AA00000000000100"); |
| | | infoBean.setDeviceName("音乐播放器");//设备名字 |
| | | infoBean.setDeviceModel("MCLog.431");//设备型号 |
| | | infoBean.setAccessMode("WIFI"); |
| | | infoBean.setIPGateway("192.168.88.1"); |
| | | infoBean.setIPAddress("192.168.88.100"); |
| | | infoBean.setIPGateway("192.168.1.1"); |
| | | infoBean.setIPAddress("192.168.1.116"); |
| | | infoBean.setGateway_type("music.standard"); |
| | | infoBean.setHw_version("HW2.0"); |
| | | infoBean.setFw_version("Fw1.0"); |
| | | infoBean.setOID("010105000000FE08"); |
| | | infoBean.setSid("010105000000FE08110100000000"); |
| | | infoBean.setOID("010105000000FE11");//每个设备oid都要不一样 |
| | | infoBean.setSid("110105000000FE08110100000011");//每个设备的sid都要不一样 |
| | | HDLLinkConfig.getInstance().setDeviceInfoBean(infoBean); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | tv.setText("开始入网认证..."); |
| | | //认证提交参数准备 |
| | | |
| | | //测试服务 |
| | | String spkStr = "ir.module";//产品spk |
| | | String macStr = "AA000000000000BB";//设备唯一MAC地址 |
| | | String secret = "87ae414b7a853f65";//通过spk和mac提交云端认证后分配的secret |
| | | // 测试服务 |
| | | // String spkStr = "ir.module";//产品spk |
| | | // String macStr = "AA000000000000AF";//设备唯一MAC地址 |
| | | // String secret = "44b360eb74b7ba64";//通过spk和mac提交云端认证后分配的secret |
| | | |
| | | //正式服务器 |
| | | // String spkStr = "screen.mirror";//产品spk |
| | | // String macStr = "AA000000000000AC";//设备唯一MAC地址 |
| | | // String secret = "ee62124c151b737c";//通过spk和mac提交云端认证后分配的secret |
| | | // 正式服务器 |
| | | String spkStr = "screen.mirror";//产品spk |
| | | String macStr = "AA00000000000100";//设备唯一MAC地址 |
| | | String secret = "e186beeb7974998e";//通过spk和mac提交云端认证后分配的secret |
| | | |
| | | String mac_key = stringToMD5(stringToMD5(macStr + secret)); |
| | | String versionString = "HDL_V1.0.1";// |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | | HDLLinkConfig.getInstance().getDeviceInfoBean().setDeviceMAC(macStr); |
| | | |
| | | //1.设置认证信息 |
| | | AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean(); |
| | | requestBean.setMAC(macStr); |
| | | requestBean.setSupplier("raysgem"); |
| | | requestBean.setSupplier("WISE"); |
| | | requestBean.setFirmwareVersion(versionString); |
| | | requestBean.setHardwareModel("1956F"); |
| | | AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean(); |
| | | authbean.setSpk(spkStr); |
| | | authbean.setMACKey(mac_key); |
| | | authbean.setRequest(requestBean); |
| | | |
| | | //2.设置设备信息 |
| | | AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean(); |
| | | infoBean.setDeviceMAC(macStr); |
| | | infoBean.setIPMAC(macStr); |
| | | infoBean.setDeviceName("红外宝");//设备名字 |
| | | infoBean.setDeviceModel("HDL");// |
| | | infoBean.setAccessMode("WIFI"); |
| | | infoBean.setIPGateway("192.168.88.1"); |
| | | infoBean.setIPAddress(IpUtils.getIP(this)); |
| | | |
| | | infoBean.setOID("010105000000FE08"); |
| | | infoBean.setSid("010105000000FE08110100000000"); |
| | | // infoBean.set |
| | | AuthenticateRequest.VersionBean[] versionBeans = new AuthenticateRequest.VersionBean[]{new AuthenticateRequest.VersionBean("FW", versionString), new AuthenticateRequest.VersionBean("HW", "1956F")}; |
| | | infoBean.setVersions(versionBeans); |
| | | AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, infoBean, authbean); |
| | | HDLLink.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() { |
| | | //HDLLinkConfig.getInstance().getDeviceInfoBean()这个初始化的时候要先设置好 |
| | | AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), authbean); |
| | | HDLLinkLocalSdk.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | tv.setText("认证失败"); |
| | | responseTv.setText(e.getMsg()); |
| | | Log.i("TAG", "onError: 认证失败"); |
| | | // tv.setText("认证失败"); |
| | | // responseTv.setText(e.getMsg()); |
| | | Log.i("TAG", "onError: 认证失败" + e.getMsg()); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | tv.setText("认证成功"); |
| | | responseTv.setText(msg.toString()); |
| | | // tv.setText("认证成功"); |
| | | // responseTv.setText(msg.toString()); |
| | | Log.i("TAG", "onSuccess: 认证成功" + msg.toString()); |
| | | } |
| | | }); |
| | | } |
| | |
| | | */ |
| | | void searchGatewayBroadcast() { |
| | | tv.setText("搜索网关中..."); |
| | | HDLLink.getInstance().searchGatewayBroadcast(new HDLAuthSocket.SearchGatewayCallBack() { |
| | | HDLLinkLocalSdk.getInstance().searchGatewayBroadcast(new HDLUdpConnect.SearchGatewayCallBack() { |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | tv.setText("网关不在线"); |
| | | responseTv.setText(e.getMsg()); |
| | | public void onSuccess(GatewaySearchBean gatewaySearchBean) { |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccess(GatewaySearchBean gatewaySearchBean) { |
| | | tv.setText("网关在线"); |
| | | responseTv.setText("搜索成功 网关id:" + gatewaySearchBean.getGatewayId()); |
| | | // LogUtils.i("TAG", "onSuccess: 搜索成功:"+gatewaySearchBean.getGatewayId()); |
| | | public void onError(HDLLinkException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | |
| | | void getFunctionList() { |
| | | tv.setText("获取功能列表中..."); |
| | | responseTv.setText(""); |
| | | HDLLink.getInstance().getFunctionList(new HDLLinkCallBack() { |
| | | HDLLinkLocalSdk.getInstance().getFunctionList(new HDLLinkTCallBack<List<LinkFunctionBean>>() { |
| | | @Override |
| | | public void onError(HDLLinkException error) { |
| | | tv.setText(error.getMsg()); |
| | | public void onSuccess(List<LinkFunctionBean> data) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccess(String data) { |
| | | tv.setText("获取功能列表成功"); |
| | | responseTv.setText(data); |
| | | public void onError(HDLLinkException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | |
| | | tv.setText("功能属性读取"); |
| | | List<String> sids = new ArrayList<>(); |
| | | sids.add(testLightSid); |
| | | HDLLink.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() { |
| | | |
| | | HDLLinkLocalSdk.getInstance().getFunctionAttribute(sids, new HDLLinkTCallBack<List<LinkFunctionBean>>() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | responseTv.setText(msg); |
| | | public void onSuccess(List<LinkFunctionBean> data) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | |
| | | } |
| | | }); |
| | | } |
| | |
| | | tv.setText("读取状态中..."); |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(testLightSid);//要读取设备的sid |
| | | HDLLink.getInstance().propertyRead(list, new HDLLinkCallBack() { |
| | | HDLLinkLocalSdk.getInstance().propertyRead(list, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String data) { |
| | | tv.setText("读取成功"); |
| | | responseTv.setText(data); |
| | | public void onSuccess(String msg) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | tv.setText("读取失败"); |
| | | responseTv.setText(e.getMsg()); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 控制失败 |
| | | * 控制设备 |
| | | * 回复响应code为200 代表执行成功 |
| | | */ |
| | | void controlDecide() { |
| | |
| | | statusBeanList.add(bean); |
| | | request.setStatus(statusBeanList); |
| | | requestList.add(request); |
| | | HDLLink.getInstance().propertyDown(requestList, new HDLLinkCallBack() { |
| | | HDLLinkLocalSdk.getInstance().propertyDown(requestList, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String data) { |
| | | responseTv.setText(data); |
| | | // responseTv.setText(data); |
| | | Log.i("TAG", "onSuccess 控制设备成功" + data.toString()); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | // responseTv.setText(e.getMsg()); |
| | | Log.i("TAG", "onError 控制设备失败" + e.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | |
| | | */ |
| | | void getSceneList() { |
| | | tv.setText("读取场景列表"); |
| | | HDLLink.getInstance().getSceneList(new HDLLinkCallBack() { |
| | | HDLLinkLocalSdk.getInstance().getSceneList(new HDLLinkTCallBack<List<LinkSceneBean>>() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | responseTv.setText(msg); |
| | | public void onSuccess(List<LinkSceneBean> data) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | |
| | | } |
| | | }); |
| | | } |
| | |
| | | } else { |
| | | sids.add("04010560D2C76E0A0A0100010000"); |
| | | } |
| | | HDLLink.getInstance().controlScene(sids, new HDLLinkCallBack() { |
| | | HDLLinkLocalSdk.getInstance().controlScene(sids, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | responseTv.setText(msg); |
| | | // responseTv.setText(msg); |
| | | Log.i("TAG", "onSuccess 场景控制成功" + msg.toString()); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | // responseTv.setText(e.getMsg()); |
| | | Log.i("TAG", "onError 场景控制失败" + e.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | void startDevicesListActivity() { |
| | | /* void startDevicesListActivity() { |
| | | Intent intent = new Intent(this, DevicesListActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * TCP发送 只发一次,不监听回复,不重发 |
| | |
| | | tv.setText("TCP发送 只发一次,不监听回复,不重发"); |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr); |
| | | HDLLinkLocalSdk.getInstance().tcpSendMsg(propertyDownTopic, bodyStr); |
| | | } |
| | | |
| | | /** |
| | |
| | | tv.setText("UDP发送 只发一次,不监听回复,不重发"); |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().udpSendMsg(propertyDownTopic, bodyStr); |
| | | HDLLinkLocalSdk.getInstance().udpSendMsg(propertyDownTopic, bodyStr,null); |
| | | } |
| | | |
| | | private String getPropertyDownBodyStr() { |
| | |
| | | tv.setText("UDP发送,监听主题回复,带重发带回调"); |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().udpSendMsg(propertyDownTopic, bodyStr, new HDLLinkResponseCallBack() { |
| | | HDLLinkLocalSdk.getInstance().udpSendMsg(propertyDownTopic, bodyStr, new HDLLinkResponseCallBack() { |
| | | @Override |
| | | public void onSuccess(LinkResponse msg) { |
| | | Log.i("udpSendWithCallback", "udpSendWithCallback"); |
| | | responseTv.setText(GsonConvert.getGson().toJson(msg)); |
| | | Log.i("TAG", "onSuccess UDP发送成功" + GsonConvert.getGson().toJson(msg)); |
| | | // responseTv.setText(GsonConvert.getGson().toJson(msg)); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | // responseTv.setText(e.getMsg()); |
| | | Log.i("TAG", "onError UDP发送失败" + e.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | |
| | | tv.setText("TCP发送,监听主题回复,带重发带回调"); |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr, new HDLLinkCallBack() { |
| | | HDLLinkLocalSdk.getInstance().tcpSendMsg(propertyDownTopic, bodyStr, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | Log.i("tcpSendWithCallback", "tcpSendWithCallback"); |
| | | responseTv.setText(msg); |
| | | Log.i("TAG", "onSuccess TCP发送成功" + msg); |
| | | // responseTv.setText(msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | // responseTv.setText(e.getMsg()); |
| | | Log.i("TAG", "onError TCP发送失败"); |
| | | } |
| | | }); |
| | | } |