فهرست منبع

Signed-off-by: zhaobao <528046418@qq.com>

zhaobao 3 سال پیش
والد
کامیت
6592e19b65
3فایلهای تغییر یافته به همراه12 افزوده شده و 2 حذف شده
  1. 12 2
      src/mixin/mqtt.js
  2. BIN
      src/views/aqpt/visualEditor/images/bg.png
  3. BIN
      src/views/aqpt/visualEditor/images/layout_cont.png

+ 12 - 2
src/mixin/mqtt.js

@@ -19,12 +19,19 @@ export default {
         mqttResponse: () => {}
       }
     ) {
+      const clientId = new Date().getTime()
       const options = {
         clean: true,
         connectTimeout: 4000,
-        clientId: new Date().getTime(),
+        clientId: clientId,
         username: 'admin',
-        password: 'houyaf1!'
+        password: 'houyaf1!',
+        will: {
+          topic: 'willTopic',
+          payload: clientId + '与服务器断开连接',
+          retain: false,
+          qos: 0
+        }
       }
       const client = mqtt.connect(mqttUrl, options)
       client.on('connect', function() {
@@ -48,6 +55,9 @@ export default {
       client.on('error', (error) => {
         console.log('连接失败:', error)
       })
+      client.on('close', function() {
+        console.log('Disconnected')
+      })
       client.on('offline', function() {
         console.log('offline')
       })

BIN
src/views/aqpt/visualEditor/images/bg.png


BIN
src/views/aqpt/visualEditor/images/layout_cont.png