thingsboard edge attributes update异常 | mqtt发送数据无法同步 且 本地无反应

错误大概长这样

版本:thingsboard edge 3.4.1

 解决:

        数据库中的 queue表内少数据 所以导致初始化失败(后面详细说)

 将以下转换为sql脚本

INSERT INTO "queue" ("id", "created_time", "tenant_id", "name", "topic", "poll_interval", "partitions", "consumer_per_partition", "pack_processing_timeout", "submit_strategy", "processing_strategy", "additional_info") VALUES ('192c9a80-e274-11ec-af68-f9de2e74cff0', 1654174880808, '13814000-1dd2-11b2-8080-808080808080', 'Main', 'tb_rule_engine.main', 25, 24, 't', 2000, '{"type":"BURST","batchSize":1000}', '{"type":"SKIP_ALL_FAILURES","retries":1,"failurePercentage":0.0,"pauseBetweenRetries":0,"maxPauseBetweenRetries":3}', NULL);
INSERT INTO "queue" ("id", "created_time", "tenant_id", "name", "topic", "poll_interval", "partitions", "consumer_per_partition", "pack_processing_timeout", "submit_strategy", "processing_strategy", "additional_info") VALUES ('1958daa0-e274-11ec-af68-f9de2e74cff0', 1654174881098, '13814000-1dd2-11b2-8080-808080808080', 'HighPriority', 'tb_rule_engine.hp', 25, 24, 't', 2000, '{"type":"BURST","batchSize":100}', '{"type":"RETRY_FAILED_AND_TIMED_OUT","retries":0,"failurePercentage":0.0,"pauseBetweenRetries":5,"maxPauseBetweenRetries":5}', NULL);
INSERT INTO "queue" ("id", "created_time", "tenant_id", "name", "topic", "poll_interval", "partitions", "consumer_per_partition", "pack_processing_timeout", "submit_strategy", "processing_strategy", "additional_info") VALUES ('195b2490-e274-11ec-af68-f9de2e74cff0', 1654174881113, '13814000-1dd2-11b2-8080-808080808080', 'SequentialByOriginator', 'tb_rule_engine.sq', 25, 24, 't', 2000, '{"type":"SEQUENTIAL_BY_ORIGINATOR","batchSize":100}', '{"type":"RETRY_FAILED_AND_TIMED_OUT","retries":3,"failurePercentage":0.0,"pauseBetweenRetries":5,"maxPauseBetweenRetries":5}', NULL);

然后再数据库中导入解决。

原因:

报错位置在这里 

        partitionSizesMap 中仅有两条数据 关于 rule-engine的数据都没有 导致出现去寻找rule-engine的内容时 partitionSize为空 之后202行便出现空指针异常。

往里顺藤摸瓜:

        

 中间还有的过程自己跑一下呗 就是一层层往里找

然后就发现肯定是数据库表中少数据了

然后阴间手段拿到数据 填进去解决!

提一嘴 有些版本的thingsboard给edge的规则链是有问题的 这边提供一个 不用谢

一下是json文件

{

  "ruleChain": {

    "additionalInfo": null,

    "name": "Edge Root Rule Chain",

    "type": "EDGE",

    "firstRuleNodeId": null,

    "root": false,

    "debugMode": false,

    "configuration": null

  },

  "metadata": {

    "firstNodeIndex": 0,

    "nodes": [

      {

        "additionalInfo": {

          "description": "Process incoming messages from devices with the alarm rules defined in the device profile. Dispatch all incoming messages with \"Success\" relation type.",

          "layoutX": 187,

          "layoutY": 468

        },

        "type": "org.thingsboard.rule.engine.profile.TbDeviceProfileNode",

        "name": "Device Profile Node",

        "debugMode": false,

        "configuration": {

          "persistAlarmRulesState": false,

          "fetchAlarmRulesStateOnStart": false

        }

      },

      {

        "additionalInfo": {

          "layoutX": 820,

          "layoutY": 289

        },

        "type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode",

        "name": "Save Timeseries",

        "debugMode": false,

        "configuration": {

          "defaultTTL": 0

        }

      },

      {

        "additionalInfo": {

          "layoutX": 594,

          "layoutY": 34

        },

        "type": "org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode",

        "name": "Save Client Attributes",

        "debugMode": false,

        "configuration": {

          "scope": "CLIENT_SCOPE"

        }

      },

      {

        "additionalInfo": {

          "layoutX": 347,

          "layoutY": 149

        },

        "type": "org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode",

        "name": "Message Type Switch",

        "debugMode": false,

        "configuration": {

          "version": 0

        }

      },

      {

        "additionalInfo": {

          "layoutX": 809,

          "layoutY": 410

        },

        "type": "org.thingsboard.rule.engine.action.TbLogNode",

        "name": "Log RPC from Device",

        "debugMode": false,

        "configuration": {

          "jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);"

        }

      },

      {

        "additionalInfo": {

          "layoutX": 776,

          "layoutY": 512

        },

        "type": "org.thingsboard.rule.engine.action.TbLogNode",

        "name": "Log Other",

        "debugMode": false,

        "configuration": {

          "jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);"

        }

      },

      {

        "additionalInfo": {

          "layoutX": 434,

          "layoutY": 538

        },

        "type": "org.thingsboard.rule.engine.rpc.TbSendRPCRequestNode",

        "name": "RPC Call Request",

        "debugMode": false,

        "configuration": {

          "timeoutInSeconds": 60

        }

      },

      {

        "additionalInfo": {

          "layoutX": 1204,

          "layoutY": 183

        },

        "type": "org.thingsboard.rule.engine.edge.TbMsgPushToCloudNode",

        "name": "Push to cloud",

        "debugMode": false,

        "configuration": {

          "scope": "SERVER_SCOPE"

        }

      }

    ],

    "connections": [

      {

        "fromIndex": 0,

        "toIndex": 3,

        "type": "Success"

      },

      {

        "fromIndex": 1,

        "toIndex": 7,

        "type": "Success"

      },

      {

        "fromIndex": 2,

        "toIndex": 7,

        "type": "Success"

      },

      {

        "fromIndex": 3,

        "toIndex": 1,

        "type": "Post telemetry"

      },

      {

        "fromIndex": 3,

        "toIndex": 2,

        "type": "Post attributes"

      },

      {

        "fromIndex": 3,

        "toIndex": 4,

        "type": "RPC Request from Device"

      },

      {

        "fromIndex": 3,

        "toIndex": 5,

        "type": "Other"

      },

      {

        "fromIndex": 3,

        "toIndex": 6,

        "type": "RPC Request to Device"

      },

      {

        "fromIndex": 3,

        "toIndex": 7,

        "type": "Attributes Deleted"

      },

      {

        "fromIndex": 3,

        "toIndex": 7,

        "type": "Attributes Updated"

      },

      {

        "fromIndex": 3,

        "toIndex": 7,

        "type": "Timeseries Deleted"

      },

      {

        "fromIndex": 3,

        "toIndex": 7,

        "type": "Timeseries Updated"

      },

      {

        "fromIndex": 4,

        "toIndex": 7,

        "type": "Success"

      }

    ],

    "ruleChainConnections": null

  }

}

 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
ThingsBoard使用Eclipse Paho MQTT客户端库来实现MQTT协议,以下是ThingsBoard实现MQTT协议的核心代码和逻辑: 1. 创建MQTT客户端并连接到消息代理服务器: ```java MqttClient client = new MqttClient(mqttBroker, clientId, persistence); MqttConnectOptions options = new MqttConnectOptions(); options.setUserName(deviceToken); options.setPassword("".toCharArray()); client.connect(options); ``` 2. 订阅MQTT主题,以接收平台发送的命令和配置更新: ```java String subscribeTopic = String.format("v1/devices/me/rpc/request/+"); client.subscribe(subscribeTopic, qos); ``` 3. 发布遥测数据和属性更新到平台: ```java String telemetryTopic = String.format("v1/devices/me/telemetry"); String payload = "{\"temperature\":25.5, \"humidity\":50.0}"; MqttMessage msg = new MqttMessage(payload.getBytes()); msg.setQos(qos); client.publish(telemetryTopic, msg); String attributesTopic = String.format("v1/devices/me/attributes"); payload = "{\"attribute1\":\"value1\", \"attribute2\":\"value2\"}"; msg = new MqttMessage(payload.getBytes()); msg.setQos(qos); client.publish(attributesTopic, msg); ``` 4. 处理平台发送的命令和配置更新: ```java client.setCallback(new MqttCallback() { public void messageArrived(String topic, MqttMessage message) throws Exception { if (topic.startsWith("v1/devices/me/rpc/request/")) { // 处理平台发送的命令 String requestId = topic.substring("v1/devices/me/rpc/request/".length()); String payload = message.toString(); JSONObject json = new JSONObject(payload); String method = json.getString("method"); JSONObject params = json.getJSONObject("params"); String responseTopic = String.format("v1/devices/me/rpc/response/%s", requestId); String responseData = "{\"result\":\"ok\"}"; client.publish(responseTopic, new MqttMessage(responseData.getBytes())); } else if (topic.equals("v1/devices/me/attributes")) { // 处理平台发送的配置更新 String payload = message.toString(); JSONObject json = new JSONObject(payload); String attribute1 = json.getString("attribute1"); String attribute2 = json.getString("attribute2"); // 更新设备配置 } } }); ``` 总之,以上代码演示了ThingsBoard如何使用Eclipse Paho MQTT客户端库实现MQTT协议的核心逻辑,包括创建MQTT客户端、连接到消息代理服务器、订阅MQTT主题、发布遥测数据和属性更新、处理平台发送的命令和配置更新等。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值