|
|
@@ -1,6 +1,7 @@
|
|
|
package com.ruoyi.data.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSON;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
@@ -196,7 +197,7 @@ public class MqttServiceImpl implements MqttService {
|
|
|
JSONArray topicObj1 = JSONUtil.parseArray(obj.getServerTopic());
|
|
|
MQTTConnect mqttConnect = new MQTTConnect();
|
|
|
try {
|
|
|
- mqttConnect.createMqttClient(obj.getServerAddress(), obj.getUuid(), obj.getAccount(), obj.getPassword(), new Callback());
|
|
|
+ mqttConnect.createMqttClient(obj.getServerAddress(), IdUtil.fastUUID().toString(), obj.getAccount(), obj.getPassword(), new Callback());
|
|
|
if (topicObj1.size() > 0) {
|
|
|
String finalProtocolType = protocolType;
|
|
|
topicObj1.forEach(i -> {
|
|
|
@@ -207,7 +208,9 @@ public class MqttServiceImpl implements MqttService {
|
|
|
try {
|
|
|
mqttConnect.pub(topic, mqttstr.toString(), (Integer) p.get("qos"));
|
|
|
} catch (MqttException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ log.error(topic);
|
|
|
+ log.error(obj.getServerAddress());
|
|
|
+ log.error(obj.getAccount());
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
@@ -229,15 +232,26 @@ public class MqttServiceImpl implements MqttService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void createMqttMain(TblMqttBo bo){
|
|
|
+ public void createMqttMain(TblMqttBo bo) {
|
|
|
+ try {
|
|
|
+ while (!connecttoserver()){
|
|
|
+ Thread.sleep(1000);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean connecttoserver(){
|
|
|
MQTTConnect mqttConnect = new MQTTConnect();
|
|
|
try {
|
|
|
System.out.println(mqttUrl);
|
|
|
mqttConnect.createMqttClient(mqttUrl, UUID.fastUUID().toString(),mqttUser,mqttPassword,new Callback("main"));
|
|
|
mqttConnect.sub(mqttTopic);
|
|
|
}catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
+ return false;
|
|
|
}
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
public void filterData(MqttSensorDataBo dataBo,TblSensor tblSensor){
|