zoukankan      html  css  js  c++  java
  • thingsboard学习笔记

    安装指南:
    https://thingsboard.io/docs/user-guide/install/installation-options/
    1.初识
    thingsboard安装在服务器中后,已经自带了mqtt服务器,不要在安装mqtt服务器
    设备:设备凭证中使用access token
    真实设备采集数据后,可以通过mqtt上传至此设备,通过access token识别。例如我们通过Mqtt fx客户端发送数据模拟的时候user name就是这个access token,密码不需要。

    2.测试
    thingsboard一般需要配合thingsboard-gateway网关
    安装:https://github.com/thingsboard/thingsboard-gateway/releases/tag/2.7

    网关中MQTT配置,broker代表自己部署的MQTT服务器,不是thingsboard中的MQTT

    {
      "broker": {
        "name":"MQTT Broker Connector",
        "host":"192.168.1.99",
        "port":1883,
        "clientId": "ThingsBoard_gateway",
        "security": {
          "type": "basic",
          "username": "flight",
          "password": "flight"
        }
      },
      "mapping": [
        {
          "topicFilter": "/sensor/data",
          "converter": {
            "type": "json",
            "deviceNameJsonExpression": "${serialNumber}",
            "deviceTypeJsonExpression": "${sensorType}",
            "timeout": 60000,
            "attributes": [
              {
                "type": "string",
                "key": "model",
                "value": "${sensorModel}"
              },
              {
                "type": "string",
                "key": "${sensorModel}",
                "value": "on"
              }
            ],
            "timeseries": [
              {
                "type": "double",
                "key": "temperature",
                "value": "${temp}"
              },
              {
                "type": "double",
                "key": "humidity",
                "value": "${hum}"
              }
            ]
          }
        },
        {
          "topicFilter": "/sensor/+/data",
          "converter": {
            "type": "json",
            "deviceNameTopicExpression": "(?<=sensor\/)(.*?)(?=\/data)",
            "deviceTypeTopicExpression": "Thermometer",
            "timeout": 60000,
            "attributes": [
              {
                "type": "string",
                "key": "model",
                "value": "${sensorModel}"
              }
            ],
            "timeseries": [
              {
                "type": "double",
                "key": "temperature",
                "value": "${temp}"
              },
              {
                "type": "double",
                "key": "humidity",
                "value": "${hum}"
              }
            ]
          }
        },
        {
          "topicFilter": "/custom/sensors/+",
          "converter": {
            "type": "custom",
            "extension": "CustomMqttUplinkConverter",
            "extension-config": {
                "temperatureBytes" : 2,
                "humidityBytes" :  2,
                "batteryLevelBytes" : 1
            }
          }
        }
      ],
      "connectRequests": [
        {
          "topicFilter": "sensor/connect",
          "deviceNameJsonExpression": "${SerialNumber}"
        },
        {
          "topicFilter": "sensor/+/connect",
          "deviceNameTopicExpression": "(?<=sensor\/)(.*?)(?=\/connect)"
        }
      ],
      "disconnectRequests": [
        {
          "topicFilter": "sensor/disconnect",
          "deviceNameJsonExpression": "${SerialNumber}"
        },
        {
          "topicFilter": "sensor/+/disconnect",
          "deviceNameTopicExpression": "(?<=sensor\/)(.*?)(?=\/disconnect)"
        }
      ],
      "attributeUpdates": [
        {
          "deviceNameFilter": "SmartMeter.*",
          "attributeFilter": "uploadFrequency",
          "topicExpression": "sensor/${deviceName}/${attributeKey}",
          "valueExpression": "{\"${attributeKey}\":\"${attributeValue}\"}"
        }
      ],
      "serverSideRpc": [
        {
          "deviceNameFilter": ".*",
          "methodFilter": "echo",
          "requestTopicExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
          "responseTopicExpression": "sensor/${deviceName}/response/${methodName}/${requestId}",
          "responseTimeout": 10000,
          "valueExpression": "${params}"
        },
        {
          "deviceNameFilter": ".*",
          "methodFilter": "no-reply",
          "requestTopicExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
          "valueExpression": "${params}"
        }
      ]
    }
    
    

    3.Topic主题映射过滤器
    例如:主题为/sensor/TestDevice/data,实际在java中测试发送的主题(.替换/)Topic:.sensor.TestDevice.data
    发送数据
    { “sensorType”: “Thermometer”,“sensorModel”:“T1000”, “temp”:75256,“hum”:75257}
    设备发送数据到MQTT服务器后,在仪表板可以看到数据如下
    在这里插入图片描述

  • 相关阅读:
    A1023 Have Fun with Numbers (20分)(大整数四则运算)
    A1096 Consecutive Factors (20分)(质数分解)
    A1078 Hashing (25分)(哈希表、平方探测法)
    A1015 Reversible Primes (20分)(素数判断,进制转换)
    A1081 Rational Sum (20分)
    A1088 Rational Arithmetic (20分)
    A1049 Counting Ones (30分)
    A1008 Elevator (20分)
    A1059 Prime Factors (25分)
    A1155 Heap Paths (30分)
  • 原文地址:https://www.cnblogs.com/InternetJava/p/15731304.html
Copyright © 2011-2022 走看看