Commit 0a845e8d86fa934ec6417981c0f209cd3a732e7a
1 parent
4d77bc21
Exists in
thd
no message
Showing
4 changed files
with
23 additions
and
7 deletions
Show diff stats
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/ApplicationRunnerImpl.java
| ... | ... | @@ -104,6 +104,7 @@ public class ApplicationRunnerImpl implements ApplicationRunner { |
| 104 | 104 | }); |
| 105 | 105 | try { |
| 106 | 106 | mqttClient.connect(connOpts); |
| 107 | + sendMq(); | |
| 107 | 108 | } catch (MqttException e) { |
| 108 | 109 | System.out.println("mqtt:" + e.toString()); |
| 109 | 110 | e.printStackTrace(); |
| ... | ... | @@ -120,6 +121,23 @@ public class ApplicationRunnerImpl implements ApplicationRunner { |
| 120 | 121 | } |
| 121 | 122 | } |
| 122 | 123 | |
| 124 | + private void sendMq() { | |
| 125 | + String recvClientId = groupId + "@@@09EA8EB5142F2964"; | |
| 126 | + final String p2pSendTopic = topic + "/p2p/" + recvClientId; | |
| 127 | + String content = "{\"cmd\":\"37\",\"clientId\":\"\",\"data\": \"6:00-22:00\"}"; | |
| 128 | + MqttMessage message = new MqttMessage(content.getBytes()); | |
| 129 | + message.setQos(qosLevel); | |
| 130 | + System.out.println("发送内容:" + p2pSendTopic); | |
| 131 | + if (null != mqttClient) { | |
| 132 | + try { | |
| 133 | + mqttClient.publish(p2pSendTopic, message); | |
| 134 | + } catch (MqttException e) { | |
| 135 | + e.printStackTrace(); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + | |
| 139 | + } | |
| 140 | + | |
| 123 | 141 | |
| 124 | 142 | /** |
| 125 | 143 | * @param equipmentSN 控制器SN号 | ... | ... |
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/Mqtt2kanbanApplication.java
| ... | ... | @@ -22,7 +22,6 @@ public class Mqtt2kanbanApplication { |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | private String indexPath = "C:\\index.txt";//存放当前取数的记录 |
| 25 | - | |
| 26 | 25 | private String devicePath = "C:\\Users\\Administrator\\Desktop\\device.txt";//存放设备id的路径 |
| 27 | 26 | public static void main(String[] args) { |
| 28 | 27 | SpringApplication.run(Mqtt2kanbanApplication.class, args); | ... | ... |
mq2kb/src/main/java/com/shunzhi/mqtt2kanban/utils/ScheduledTasks.java
| ... | ... | @@ -55,7 +55,7 @@ public class ScheduledTasks { |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | //每隔5秒取一次数据 |
| 58 | - @Scheduled(fixedDelay = 2000) | |
| 58 | + @Scheduled(fixedDelay = 200000) | |
| 59 | 59 | public void reportCurrentTime() { |
| 60 | 60 | System.out.println("任务调度:" + new SimpleDateFormat("HH:mm:ss").format(new Date())); |
| 61 | 61 | try { |
| ... | ... | @@ -63,8 +63,7 @@ public class ScheduledTasks { |
| 63 | 63 | if (ApplicationRunnerImpl.isConnect) //MQ是否连接 |
| 64 | 64 | getVaild(); |
| 65 | 65 | |
| 66 | - readImgs(); | |
| 67 | - // getUser(); | |
| 66 | +// readImgs(); | |
| 68 | 67 | } catch (Exception e) { |
| 69 | 68 | getVaild(); |
| 70 | 69 | System.out.println("eeeeeeee:" + e.toString()); | ... | ... |
mq2kb/src/main/resources/application.properties
| 1 | 1 | server.port=10086 |
| 2 | 2 | |
| 3 | -spring.datasource.url=jdbc:mysql://10.1.16.3:3307/jcacardone?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC | |
| 4 | -spring.datasource.username=thd | |
| 5 | -spring.datasource.password=654321 | |
| 3 | +spring.datasource.url=jdbc:mysql://localhost:3307/jcacardone?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC | |
| 4 | +spring.datasource.username=root | |
| 5 | +spring.datasource.password=123456 | |
| 6 | 6 | #spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC |
| 7 | 7 | #spring.datasource.username=root |
| 8 | 8 | #spring.datasource.password=123456 | ... | ... |