|
|
@@ -121,24 +121,24 @@ public class MqttServiceImpl implements MqttService {
|
|
|
protocolType = sysDictData.getDictLabel();
|
|
|
}
|
|
|
}
|
|
|
-// for(MqttObj obj:mqttObjList){
|
|
|
-// if(obj.getStatus() == 1) {
|
|
|
-// JSONObject topicObj = obj.getTopicQos(protocolType);
|
|
|
-// MQTTConnect mqttConnect = new MQTTConnect();
|
|
|
-// try {
|
|
|
-// mqttConnect.createMqttClient(obj.getServerAddress(), obj.getUuid(), obj.getAccount(), obj.getPassword(), new Callback());
|
|
|
-// if (topicObj != null) {
|
|
|
-// String topic = topicObj.get("name").toString().replace("#", "");
|
|
|
-// mqttConnect.pub(topic, mqttMsg.toString(), Integer.valueOf((String) topicObj.get("qos")));
|
|
|
-// } else {
|
|
|
-// String topic = "sensor/"+protocolType+"/" + sensorId;
|
|
|
-// mqttConnect.pub(topic, mqttMsg.toString(), 0);
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ for(MqttObj obj:mqttObjList){
|
|
|
+ if(obj.getStatus() == 1) {
|
|
|
+ JSONObject topicObj = obj.getTopicQos(protocolType);
|
|
|
+ MQTTConnect mqttConnect = new MQTTConnect();
|
|
|
+ try {
|
|
|
+ mqttConnect.createMqttClient(obj.getServerAddress(), obj.getUuid(), obj.getAccount(), obj.getPassword(), new Callback());
|
|
|
+ if (topicObj != null) {
|
|
|
+ String topic = topicObj.get("name").toString().replace("#", "");
|
|
|
+ mqttConnect.pub(topic, mqttMsg.toString(), Integer.valueOf((String) topicObj.get("qos")));
|
|
|
+ } else {
|
|
|
+ String topic = "sensor/"+protocolType+"/" + sensorId;
|
|
|
+ mqttConnect.pub(topic, mqttMsg.toString(), 0);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|