modbus slave 设备通过 网关thingsboard-gateway 将数据上传到thingsboard云平台

搭建thingsboard物联网云平台花了大量时间,从小白到最后搭建成功,折磨了好几天,也感谢网友的帮助,提供了思路最终成功搞定,特此记录。

一、thingsboard环境搭建(Ubuntu20.04LTS)

参考官方文档,按部就班操作即可

http://www.ithingsboard.com/docs/user-guide/install/ubuntu/

二、thingsboard-gateway环境搭建

也是参考官方文档,直接安装

Step 1. Download the deb file

|------------------------------------------------------------------------------------------------------------------|
| wget https://github.com/thingsboard/thingsboard-gateway/releases/latest/download/python3-thingsboard-gateway.deb |

Step 2. Install the gateway using apt

Install ThingsBoard IoT Gateway as package and run it as daemon use the following command:

|-------------------------------------------------------|
| sudo apt install ./python3-thingsboard-gateway.deb -y |

The deb package will automatically install the necessary libraries for the IOT Gateway to work:

  1. System libraries: libffi-dev, libglib2.0-dev, libxml2-dev, libxslt-dev, libssl-dev, zlib1g-dev, python3-dev, python3-pip.
  2. Python modules: importlib, importlib-metadata, jsonschema, pymodbus, lxml, jsonpath-rw, paho-mqtt, pyserial, PyYAML, simplejson, pyrsistent.

Step 3. Check gateway status

systemctl status thingsboard-gateway

修改配置文件:/etc/thingsboard-gateway/config/tb_gateway.json

bash 复制代码
{
  "thingsboard": {
    "host": "127.0.0.1",
    "port": 1883,
    "remoteShell": false,
    "remoteConfiguration": true,
    "statistics": {
      "enable": true,
      "statsSendPeriodInSeconds": 3600,
      "configuration": null
    },
    "deviceFiltering": {
      "enable": false,
      "filterFile": "list.json"
    },
    "maxPayloadSizeBytes": 1024,
    "minPackSendDelayMS": 200,
    "minPackSizeToSend": 500,
    "checkConnectorsConfigurationInSeconds": 60,
    "handleDeviceRenaming": true,
    "security": {
      "type": "accessToken",
      "accessToken": "ke6h88w6f0fssjaq4s9e"
    },
    "qos": 1,
    "checkingDeviceActivity": {
      "checkDeviceInactivity": false,
      "inactivityTimeoutSeconds": 200,
      "inactivityCheckPeriodSeconds": 500
    },
    "ts": 1721138363329
  },
  "storage": {
    "type": "memory",
    "read_records_count": 100,
    "max_records_count": 100000,
    "data_folder_path": "./data/",
    "max_file_count": 10,
    "max_read_records_count": 10,
    "max_records_per_file": 10000,
    "data_file_path": "./data/data.db",
    "messages_ttl_check_in_hours": 1,
    "messages_ttl_in_days": 7,
    "ts": 1721138363329
  },
  "grpc": {
    "enabled": false,
    "serverPort": 9595,
    "keepaliveTimeMs": 10000,
    "keepaliveTimeoutMs": 5000,
    "keepalivePermitWithoutCalls": true,
    "maxPingsWithoutData": 0,
    "minTimeBetweenPingsMs": 10000,
    "minPingIntervalWithoutDataMs": 5000,
    "keepAliveTimeMs": 10000,
    "keepAliveTimeoutMs": 5000
  },
  "connectors": [
    {
      "type": "modbus",
      "name": "MODBUS CONNECT",
      "configuration": "modbus_serial.json"
    }
  ]
}

mqtt_modbus.json配置

bash 复制代码
{
  "master": {
    "slaves": [
      {
        "type": "serial",
        "method": "rtu",
        "port": "/dev/ttyS1",
        "baudrate": 9600,
        "timeout": 35,
        "stopbits": 1,
        "bytesize": 8,
        "byteOrder": "BIG",
        "wordOrder": "BIG",
        "retries": true,
        "retryOnEmpty": true,
        "retryOnInvalid": true,
        "pollPeriod": 5000,
        "unitId": 1,
        "deviceName": "Modbus Temperature Sensor",
        "sendDataOnlyOnChange": false,
        "connectAttemptTimeMs": 5000,
        "connectAttemptCount": 5,
        "waitAfterFailedAttemptsMs": 300000,
        "attributes": [
          {
            "tag": "16int",
            "type": "16int",
            "functionCode": 4,
            "objectsCount": 2,
            "address": 3
          }
        ],
        "timeseries": [
          {
            "tag": "temperature",
            "type": "16uint",
            "functionCode": 4,
            "objectsCount": 1,
            "address": 1
          },
          {
            "tag": "humidity",
            "type": "16uint",
            "functionCode": 4,
            "objectsCount": 1,
            "address": 2
          }
        ],
        "attributeUpdates": [
          {
            "tag": "shared_attribute_write",
            "type": "32int",
            "functionCode": 6,
            "objectsCount": 2,
            "address": 29
          }
        ],
        "rpc": [
          {
            "tag": "setValue",
            "type": "16int",
            "functionCode": 6,
            "objectsCount": 1,
            "address": 1
          },
          {
            "tag": "getValue",
            "type": "16int",
            "functionCode": 3,
            "objectsCount": 1,
            "address": 2
          }
        ]
      }
    ]
  },
  "id": "19c7e3fa-bfd8-4edb-9590-1fd570902b35"
}

三、modbus slave配置

在命令行重启网关:

sudo systemctl restart thingsboard-gateway.service

云平台就会出现Modbus Temperature Sensor这个设备

四、新建调试界面,对设备进行调试

终于通信成功!!!!!

相关推荐
网易独家音乐人Mike Zhou3 小时前
【卡尔曼滤波】数据预测Prediction观测器的理论推导及应用 C语言、Python实现(Kalman Filter)
c语言·python·单片机·物联网·算法·嵌入式·iot
2401_882727576 小时前
BY组态-低代码web可视化组件
前端·后端·物联网·低代码·数学建模·前端框架
畅联云平台10 小时前
美畅物联丨智能分析,安全管控:视频汇聚平台助力智慧工地建设
人工智能·物联网
东芝、铠侠总代1361006839312 小时前
浅谈TLP184小型平面光耦
单片机·嵌入式硬件·物联网·平面
BY—-组态13 小时前
web组态软件
前端·物联网·工业互联网·web组态·组态
Vodka~16 小时前
物联网——UNIX时间戳、BKP备份寄存器、RTC时钟
物联网·实时音视频
电子科技圈16 小时前
XMOS携手合作伙伴晓龙国际联合推出集成了ASRC等功能的多通道音频板
科技·嵌入式硬件·mcu·物联网·音视频·iot
IT枫斗者18 小时前
如何解决Java EasyExcel 导出报内存溢出
java·服务器·开发语言·网络·分布式·物联网
7yewh18 小时前
嵌入式硬件杂谈(四)-高速板PCB设计 高速信号全面讲解 蛇形线 等长线 差分对 阻抗对
驱动开发·嵌入式硬件·mcu·物联网·硬件工程·pcb工艺·精益工程
南门听露19 小时前
适用于资源受限IoT系统的非对称语义图像压缩技术
深度学习·神经网络·物联网