|
@@ -70,27 +70,29 @@ public class MqttServiceImpl implements MqttService {
|
|
|
MqttObj mqttObj = new MqttObj();
|
|
MqttObj mqttObj = new MqttObj();
|
|
|
mqttObj.setEquipmentId(deviceId);
|
|
mqttObj.setEquipmentId(deviceId);
|
|
|
List<MqttObj> mqttObjList = tblEquipmentMqttMapper.selectMqttListByDeviceId(mqttObj);
|
|
List<MqttObj> mqttObjList = tblEquipmentMqttMapper.selectMqttListByDeviceId(mqttObj);
|
|
|
|
|
+ TblRecord tblRecord = new TblRecord();
|
|
|
|
|
+ tblRecord.setEquipmentId(deviceId);
|
|
|
|
|
+ tblRecord.setJson(mqttStr);
|
|
|
|
|
+ tblRecord.setCreateBy("admin");
|
|
|
|
|
+ tblRecord.setUpdateBy("admin");
|
|
|
|
|
+ tblRecordMapper.insert(tblRecord);
|
|
|
for(MqttObj obj:mqttObjList){
|
|
for(MqttObj obj:mqttObjList){
|
|
|
- JSONObject topicObj = obj.getTopicQos("tcp");
|
|
|
|
|
- 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,jsonObject.toString(),Integer.valueOf((String) topicObj.get("qos")));
|
|
|
|
|
- }else{
|
|
|
|
|
- String topic = "sensor/modbustcp/"+deviceId;
|
|
|
|
|
- mqttConnect.pub(topic,jsonObject.toString(),0);
|
|
|
|
|
- }
|
|
|
|
|
- TblRecord tblRecord = new TblRecord();
|
|
|
|
|
- tblRecord.setEquipmentId(deviceId);
|
|
|
|
|
- tblRecord.setJson(mqttStr);
|
|
|
|
|
- tblRecord.setCreateBy("admin");
|
|
|
|
|
- tblRecord.setUpdateBy("admin");
|
|
|
|
|
- tblRecordMapper.insert(tblRecord);
|
|
|
|
|
- }catch (Exception e){
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if(obj.getStatus() == 1) {
|
|
|
|
|
+ JSONObject topicObj = obj.getTopicQos("tcp");
|
|
|
|
|
+ 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, jsonObject.toString(), Integer.valueOf((String) topicObj.get("qos")));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ String topic = "sensor/modbustcp/" + deviceId;
|
|
|
|
|
+ mqttConnect.pub(topic, jsonObject.toString(), 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|