• 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服务器后,在仪表板可以看到数据如下
    在这里插入图片描述

  • 相关阅读:
    LeetCode105. 从前序与中序遍历序列构造二叉树
    Flask 基础
    24个常用 Python 实现
    大佬的编码建议,让你的代码更pythonic
    rest-framework框架之序列化
    路飞学城项目之加入结算中心接口
    java异常与spring事务关系的知识点查漏补缺
    iserver-数据库型数据源导入后原dataset名称和数据库表名不一致的问题
    解决数据读取的负载均衡的问题
    Nginx反向代理、CORS、JSONP等跨域请求解决方法总结
  • 原文地址:https://www.cnblogs.com/InternetJava/p/15731304.html
Copyright © 2020-2023  润新知