panlili2024
2025-03-05 134209ad70f82051da3ce63471df0cc8f778e57d
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLSocket.java
@@ -46,6 +46,7 @@
import com.hdl.sdk.socket.listener.ConnectStatusListener;
import com.hdl.sdk.socket.listener.SendListener;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
@@ -480,25 +481,30 @@
                @Override
                public void heartbeat() {
                    if (HDLLinkConfig.getInstance().getDeviceInfoBean() == null || HDLLinkConfig.getInstance().getDeviceInfoBean().getOID() == null) {
                        LogUtils.i("DeviceInfoBean为空,需要设置才能正常心跳");
                        return;
                    }
                    String time = String.valueOf(System.currentTimeMillis());
                    JsonObject jsonObject = new JsonObject();
                    jsonObject.addProperty("id", IdUtils.getUUId());
                    jsonObject.addProperty("time_stamp", time);
                    if (HDLLinkConfig.getInstance().getDeviceInfoBean().getOID() == null) {
                        //不走从机入网,通过gatewayId发送
                        if (HDLLinkConfig.getInstance().getGatewayId() == null) {
                            return;
                        }
                        String topic = String.format(TopicConstant.HEARTBEAT, HDLLinkConfig.getInstance().getGatewayId());
                        LinkRequest message = new LinkRequest(topic,
                                jsonObject.toString());
                        sendMsg(message.getSendBytes(), null, null, null);
                    if (HDLLinkConfig.getInstance().getRequestBean() != null) {
                        jsonObject.addProperty("mac", HDLLinkConfig.getInstance().getRequestBean().getMAC());
                    } else {
                        if (HDLLinkConfig.getInstance().getRequestBean() != null) {
                            jsonObject.addProperty("mac", HDLLinkConfig.getInstance().getRequestBean().getMAC());
                        }
                        //走从机入网,通过oid发送
                        String topic = String.format(TopicConstant.HEARTBEAT, HDLLinkConfig.getInstance().getDeviceInfoBean().getOID());
                        LinkRequest message = new LinkRequest(topic,
                                jsonObject.toString());
                        sendMsg(message.getSendBytes(), null, null, null);
                    }
                    String topic = String.format(TopicConstant.HEARTBEAT, HDLLinkConfig.getInstance().getDeviceInfoBean().getOID());
                    LinkRequest message = new LinkRequest(topic,
                            jsonObject.toString());
                    sendMsg(message.getSendBytes(), null, null, null);
                }
            });
        }