From a78bcfdccd096827248d87a029ab8129105af9d6 Mon Sep 17 00:00:00 2001 From: jay <75509151@qq.com> Date: Tue, 8 Aug 2023 16:33:55 +0800 Subject: [PATCH] =?UTF-8?q?update:=20nb=E7=BB=84=E4=BB=B6=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E4=B8=8A=E4=B8=8B=E7=BA=BF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component.js | 32 +++++++++++++++---- .../java/cc/iotkit/comp/nb/NBVerticle.java | 2 ++ .../src/main/resources/component.js | 32 +++++++++++++++---- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/data/components/750da259-ff77-4869-a5a5-12a5433b0e4c/component.js b/data/components/750da259-ff77-4869-a5a5-12a5433b0e4c/component.js index ad429c3c..082f59fa 100644 --- a/data/components/750da259-ff77-4869-a5a5-12a5433b0e4c/component.js +++ b/data/components/750da259-ff77-4869-a5a5-12a5433b0e4c/component.js @@ -177,6 +177,20 @@ function subRegister(topic, parent, payload) { }; } +function deviceStateChangeByClientId(head, clientId, state) { + + var device = getPkDn(clientId); + + return { + type: "state", + data: { + productKey: device.pk, + deviceName: device.dn, + state: state + } + } +} + function deviceStateChange(head, clientId, state) { var topic = head.topic; var device = getPkDn(clientId); @@ -243,20 +257,24 @@ this.onReceive = function (head, type, payload) { if (type == 'auth') { return register(payload); } - - if (type == 'subscribe') { - return deviceStateChange(head, payload, 'online'); + else if (type == 'online') { + return deviceStateChangeByClientId(head, payload, 'online'); + } + else if (type == 'subscribe') { + // 此产品无需通过订阅来确认是否上线 + return {}; } - if (type == 'unsubscribe') { - return deviceStateChange(head, payload, 'offline'); + else if (type == 'unsubscribe') { + // 此产品无需通过订阅来确认是否下线 + return {}; } - if (type == 'disconnect') { + else if (type == 'disconnect') { return disconnect(payload); } - if (type == 'ota') { + else if (type == 'ota') { return ota(head, payload); } diff --git a/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBVerticle.java b/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBVerticle.java index 8dafd763..f3523f42 100644 --- a/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBVerticle.java +++ b/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBVerticle.java @@ -90,6 +90,8 @@ public class NBVerticle extends AbstractVerticle { endpoint.reject(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED); return; } + // 固定协议,不需要订阅,直接认为上线 + executor.onReceive(null, "online", clientId); //保存设备与连接关系 endpointMap.put(getEndpointKey(r), endpoint); mqttConnectPool.put(clientId, true); diff --git a/iot-components/iot-nb-component/src/main/resources/component.js b/iot-components/iot-nb-component/src/main/resources/component.js index ad429c3c..082f59fa 100644 --- a/iot-components/iot-nb-component/src/main/resources/component.js +++ b/iot-components/iot-nb-component/src/main/resources/component.js @@ -177,6 +177,20 @@ function subRegister(topic, parent, payload) { }; } +function deviceStateChangeByClientId(head, clientId, state) { + + var device = getPkDn(clientId); + + return { + type: "state", + data: { + productKey: device.pk, + deviceName: device.dn, + state: state + } + } +} + function deviceStateChange(head, clientId, state) { var topic = head.topic; var device = getPkDn(clientId); @@ -243,20 +257,24 @@ this.onReceive = function (head, type, payload) { if (type == 'auth') { return register(payload); } - - if (type == 'subscribe') { - return deviceStateChange(head, payload, 'online'); + else if (type == 'online') { + return deviceStateChangeByClientId(head, payload, 'online'); + } + else if (type == 'subscribe') { + // 此产品无需通过订阅来确认是否上线 + return {}; } - if (type == 'unsubscribe') { - return deviceStateChange(head, payload, 'offline'); + else if (type == 'unsubscribe') { + // 此产品无需通过订阅来确认是否下线 + return {}; } - if (type == 'disconnect') { + else if (type == 'disconnect') { return disconnect(payload); } - if (type == 'ota') { + else if (type == 'ota') { return ota(head, payload); }