From e491cdb48129752324c4e3764f99bd9203c56dec Mon Sep 17 00:00:00 2001
From: lgq <1015864684@qq.com>
Date: 星期二, 31 三月 2026 09:48:44 +0800
Subject: [PATCH] 1.新增VF205门禁机代码

---
 vf205_access/dxmodules/mqttWorker.js |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/vf205_access/dxmodules/mqttWorker.js b/vf205_access/dxmodules/mqttWorker.js
new file mode 100644
index 0000000..bf2083d
--- /dev/null
+++ b/vf205_access/dxmodules/mqttWorker.js
@@ -0,0 +1,64 @@
+//build:20240524
+//鐢ㄤ簬绠�鍖杕qtt缁勪欢寰厜閫氫俊鍗忚鐨勪娇鐢紝鎶妋qtt灏佽鍦ㄨ繖涓獁orker閲岋紝浣跨敤鑰呭彧闇�瑕佽闃卐ventcenter鐨勪簨浠跺氨鍙互鐩戝惉mqtt
+import log from './dxLogger.js'
+import net from './dxNet.js'
+import mqtt from './dxMqtt.js'
+import dxMap from './dxMap.js'
+import std from './dxStd.js'
+import * as os from "os";
+const map = dxMap.get('default')
+const id = "{{id}}"
+const options = map.get("__mqtt__run_init" + id)
+let connected = false
+function run() {
+    mqtt.init(options.mqttAddr, options.clientId, options.username, options.password, options.prefix, options.qos, options.willTopic, options.willMessage, options.id)
+    log.info('mqtt start......,id =', id)
+    os.sleep(2000)//绛夊緟2绉�
+
+    __bus.on(mqtt.RECONNECT, (options) => {
+        mqtt.destroy(options.id)
+        mqtt.init(options.mqttAddr, options.clientId, options.username, options.password, options.prefix, options.qos, options.willTopic, options.willMessage, options.id)
+    })
+
+    std.setInterval(() => {
+        try {
+            if (mqtt.isConnected(options.id) && net.getStatus().connected) {
+                if (!connected) {
+                    _fireChange(true)
+                    if (options.subs) {
+                        mqtt.subscribes(options.subs, options.qos, options.id)
+                    }
+                }
+            } else {
+                if (connected) {
+                    _fireChange(false)
+                }
+                // 閲嶈繛
+                mqtt.reconnect(options.willTopic, options.willMessage, options.id)
+                os.sleep(2000)//閲嶈繛鍚庣瓑寰�2绉�
+            }
+        } catch (error) {
+            log.error(error)
+        }
+    }, 3000)
+    std.setInterval(() => {
+        // 杩炴帴鎴愬姛鍚庤繘鍏ユ秷鎭洃鍚�
+        if (connected) {
+            if (!mqtt.msgIsEmpty(options.id)) {
+                let msg = mqtt.receive(options.id)
+                __bus.fire(mqtt.RECEIVE_MSG + options.id, msg)//bus.newworker鐨勬椂鍊欎細import eventbus as __bus
+            }
+        }
+    }, 10);
+}
+
+try {
+    run()
+} catch (error) {
+    log.error(error)
+}
+
+function _fireChange(status) {
+    __bus.fire(mqtt.CONNECTED_CHANGED + options.id, status ? 'connected' : 'disconnected')//bus.newworker鐨勬椂鍊欎細import eventbus as __bus
+    connected = status
+}

--
Gitblit v1.9.3