From 3b47201d878ba8ff973b84baf15942475688e964 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期五, 15 十二月 2023 16:04:28 +0800 Subject: [PATCH] 合并第一个版本 --- HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-) diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java index 6e8ef74..09cc1e0 100644 --- a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/mqtt/MqttRecvClient.java @@ -7,6 +7,7 @@ import com.hdl.sdk.link.common.utils.LogUtils; import com.hdl.sdk.link.core.bean.LinkPacket; +import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; import com.hdl.sdk.link.core.bean.eventbus.EventBindMiniRemoteSuccessInfo; import com.hdl.sdk.link.core.bean.eventbus.EventNotifyRefreshGatewayAesKeyInfo; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; @@ -30,6 +31,7 @@ import org.greenrobot.eventbus.EventBus; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -148,7 +150,7 @@ connOpts.setCleanSession(true); connOpts.setKeepAliveInterval(10); connOpts.setAutomaticReconnect(true); - connOpts.setConnectionTimeout(10); + connOpts.setConnectionTimeout(60); connOpts.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1); sampleClient.setCallback(new MqttCallbackExtended() { public void connectComplete(boolean reconnect, String serverURI) { @@ -207,6 +209,11 @@ return; } LogUtils.d(TAG, "缃戝叧閲嶈繛mqtt绉橀挜鏇存柊閫氱煡->" + topic); + + BaseEventBus baseEventBus=new BaseEventBus(); + baseEventBus.setTopic(topic); + EventBus.getDefault().post(baseEventBus); + EventNotifyRefreshGatewayAesKeyInfo eventNotifyRefreshGatewayAesKeyInfo = new EventNotifyRefreshGatewayAesKeyInfo(); eventNotifyRefreshGatewayAesKeyInfo.setGatewayId(topics[2]); EventBus.getDefault().post(eventNotifyRefreshGatewayAesKeyInfo); @@ -223,8 +230,9 @@ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayByOidOrGatewayId(cloudsGatewayId); if (cloudsGatewayId.equals(HDLLinkConfig.getInstance().getHomeId())) { aes = getHomeAES(); - } else if (gatewayBean != null && HDLConnectHelper.getGatewayTypeList().contains(gatewayBean.getGatewayType())) { - //姣背娉qtt涓撶敤绉橀挜 + } + else if (gatewayBean != null && HDLConnectHelper.getGatewayTypeList().contains(gatewayBean.getGatewayType())) { + //姣背娉qtt涓撶敤绉橀挜銆侀�嗗彉鍣╩qtt涓撶敤绉橀挜 aes = gatewayBean.getAesKey(); } else { aes = HDLLinkConfig.getInstance().getAesKey(); @@ -239,7 +247,11 @@ return; } String bodyStr = new String(bytes); - LogUtils.d(TAG, "\r\n" + "mqtt->杩滅▼鍥炲鏁版嵁" + bodyStr); + if (HDLConnectHelper.isInverterTopic(topic)) { + LogUtils.d(TAG, "\r\n" + "mqtt->杩滅▼鍥炲鏁版嵁" + Arrays.toString(HDLConnectHelper.byteArrayConvertIntArray(bytes))); + } else { + LogUtils.d(TAG, "\r\n" + "mqtt->杩滅▼鍥炲鏁版嵁" + bodyStr); + } /** * 绾㈠瀹濊澶囬�氳繃/thing/topo/found涓婚 涓婃姤绾㈠瀹濊澶囧凡缁忓叆缃戜簡 鐒跺悗鐩存帴return 涓嶉渶瑕佸啀涓嬭浜� */ @@ -278,6 +290,9 @@ * @param sendTopic 璇锋眰涓婚 */ public synchronized void checkAndsubscribeAllTopics(String sendTopic) { + if (null == sampleClient) { + return; + } if (null != sampleClient && sampleClient.isConnected() == false) { return; } @@ -379,6 +394,9 @@ * 鍒囨崲浣忓畢鐨勬椂鍊欒闃呰鍏ㄩ儴鍙栨秷 */ public void removeAllTopic() { + if (null == sampleClient) { + return; + } if (null != sampleClient && sampleClient.isConnected() == false) { return; } @@ -401,6 +419,7 @@ mqttRecvClient.sampleClient.disconnect(); mqttRecvClient.sampleClient.close(); mqttRecvClient = null; + lastTopicFilters.clear(); } } catch (MqttException e) { e.printStackTrace(); -- Gitblit v1.8.0