当前位置: 首页 > news >正文

本地编译运行Thingsboard-gateway之python版本——modbus数据采集

1、ideal 我用的是2020版本,这个关系不大,随便
Thingsboard-gateway之python版本源码拉取(老版本是java写的,新版都是python写的)
地址:git clone https://github.com/thingsboard/thingsboard-gateway.git

python        尽量选取3.9以上,我用的python3.11
地址:Welcome to Python.org

2、在正式开始运行前,先配置好环境变量,主要是python

3、安装python的虚拟环境,以便隔离

# 安装virtualenv

pip install virtualenv

激活virtualenv:

在.\venv\Scripts目录下运行activate,类似下面的进入虚拟环境里

同时按照依赖pip install -r requirements.txt

4、到 thingsboard_gateway 目录下运行python tb_gateway.py

cd到thingsboard_gateway目录,再输入python tb_gateway.py回车执行命令

如遇错误ModuleNotFoundError: No module named 'thingsboard_gateway'

pip install  thingsboard_gateway 

启动出现Cannot load GRPC connector! 错误,目前先不管这个

启动后出现下面错误应该是读取的地址没有,增加相应的地址就可以了

modbus_connector 625 - Reading failed for device Temp Sensor function code 4 address 18 unit id 1

pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] [WinError 10054] 远程主机强迫关闭了一个现有的连接

运行正常后如下

5、配置modbus slave

正常后有下面的遥感数据

6、附tb_gateway.json文件

{"thingsboard": {"host": "localhost","port": 1883,"remoteShell": true,"remoteConfiguration": true,"latencyDebugMode": false,"statistics": {"enable": true,"statsSendPeriodInSeconds": 60,"configuration": null,"commands": []},"deviceFiltering": {"enable": false,"filterFile": "list.json"},"maxPayloadSizeBytes": 8196,"minPackSendDelayMS": 50,"minPackSizeToSend": 500,"checkConnectorsConfigurationInSeconds": 60,"handleDeviceRenaming": true,"security": {"type": "accessToken","accessToken": "fUe9wLhHKikn2rZayxxq"},"qos": 1,"checkingDeviceActivity": {"checkDeviceInactivity": false,"inactivityTimeoutSeconds": 200,"inactivityCheckPeriodSeconds": 500},"rateLimits": "DEFAULT_TELEMETRY_RATE_LIMIT","dpRateLimits": "DEFAULT_TELEMETRY_DP_RATE_LIMIT","messagesRateLimits": "DEFAULT_MESSAGES_RATE_LIMIT","deviceMessagesRateLimits": "DEFAULT_MESSAGES_RATE_LIMIT","deviceRateLimits": "DEFAULT_TELEMETRY_RATE_LIMIT","deviceDpRateLimits": "DEFAULT_TELEMETRY_DP_RATE_LIMIT"},"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},"grpc": {"enabled": true,"serverPort": 9595,"keepAliveTimeMs": 10001,"keepAliveTimeoutMs": 5000,"keepAlivePermitWithoutCalls": true,"maxPingsWithoutData": 0,"minTimeBetweenPingsMs": 10000,"minPingIntervalWithoutDataMs": 5000},"connectors": [{"type": "modbus","name": "test","configuration": "test.json"}]
}

6、附test.json文件

{"master": {"slaves": [{"host": "127.0.0.1","port": 502,"type": "tcp","method": "socket","timeout": 35,"byteOrder": "LITTLE","wordOrder": "LITTLE","retries": true,"retryOnEmpty": true,"retryOnInvalid": true,"pollPeriod": 5000,"unitId": 1,"deviceName": "Temp Sensor","sendDataOnlyOnChange": true,"connectAttemptTimeMs": 5000,"connectAttemptCount": 5,"waitAfterFailedAttemptsMs": 300000,"attributes": [{"tag": "string_read","type": "string","functionCode": 4,"objectsCount": 4,"address": 1},{"tag": "bits_read","type": "bits","functionCode": 4,"objectsCount": 1,"address": 5},{"tag": "16int_read","type": "16int","functionCode": 4,"objectsCount": 1,"address": 7},{"tag": "32int_read_divider","type": "32int","functionCode": 4,"objectsCount": 2,"address": 8,"divider": 10},{"tag": "32int_read","type": "32int","functionCode": 4,"objectsCount": 2,"address": 11},{"tag": "64int_read","type": "64int","functionCode": 4,"objectsCount": 4,"address": 13}],"timeseries": [{"tag": "16uint_read","type": "16uint","functionCode": 4,"objectsCount": 2,"address": 18},{"tag": "32uint_read","type": "32uint","functionCode": 4,"objectsCount": 4,"address": 20},{"tag": "64uint_read","type": "64uint","functionCode": 4,"objectsCount": 1,"address": 24},{"tag": "16float_read","type": "16float","functionCode": 4,"objectsCount": 1,"address": 25},{"tag": "32float_read","type": "32float","functionCode": 4,"objectsCount": 2,"address": 26},{"tag": "64float_read","type": "64float","functionCode": 4,"objectsCount": 4,"address": 28}],"attributeUpdates": [{"tag": "shared_attribute_write","type": "32int","functionCode": 6,"objectsCount": 2,"address": 29}],"rpc": [{"tag": "setValue","type": "bits","functionCode": 5,"objectsCount": 1,"address": 31},{"tag": "getValue","type": "bits","functionCode": 1,"objectsCount": 1,"address": 31},{"tag": "setCPUFanSpeed","type": "32int","functionCode": 16,"objectsCount": 2,"address": 33},{"tag": "getCPULoad","type": "32int","functionCode": 4,"objectsCount": 2,"address": 35}]}]},"slave": {"type": "tcp","host": "127.0.0.1","port": 502,"method": "socket","deviceName": "Modbus Slave Example","deviceType": "default","pollPeriod": 5000,"sendDataToThingsBoard": false,"byteOrder": "LITTLE","wordOrder": "LITTLE","unitId": 0,"values": {"holding_registers": {"attributes": [{"address": 1,"type": "string","tag": "sm","objectsCount": 1,"value": "ON"}],"timeseries": [{"address": 2,"type": "16int","tag": "smm","objectsCount": 1,"value": 12334}],"attributeUpdates": [{"tag": "shared_attribute_write","type": "32int","functionCode": 6,"objectsCount": 2,"address": 29,"value": 1243}],"rpc": [{"tag": "setValue","type": "16int","functionCode": 5,"objectsCount": 1,"address": 31,"value": 22}]},"coils_initializer": {"attributes": [{"address": 5,"type": "8int","tag": "coil","objectsCount": 1,"value": 0}],"timeseries": [],"attributeUpdates": [],"rpc": []}}},"id": "d6e9ec17-f8ef-46f9-ab4b-7ec671ae01df"
}

http://www.lryc.cn/news/466784.html

相关文章:

  • 京东笔试题
  • URP学习(一)
  • Linux中修改和查看Redis的内存大小
  • uniapp中的页面跳转
  • Redis|延迟双删策略的优点和缺点是什么?
  • 【计算机网络 - 基础问题】每日 3 题(五十二)
  • LogStash架构分析
  • 2024最新最全【大模型学习路线规划】零基础入门到精通!,大模型学习干货分享,总结的太详细了
  • QT界面开发:图形化设计、资源文件添加
  • 科大讯飞:成本降低 60%,性能提升 10 倍,从 ES Loki 到 Apache Doris 可观测性存储底座升级
  • ISO26262在汽车领域的意义
  • 11. 事件机制
  • MySQL 本地社区版安装(不登录) mysql官网链接
  • Redis Search系列 - 第三讲 拼写检查
  • Golang | Leetcode Golang题解之第492题构造矩形
  • Axure重要元件三——中继器函数
  • MySQL8.0.40编译安装
  • JavaScript 第23章:WebSocket 与实时通讯
  • 简单汇编教程10 数组
  • Jsoup在Java中:解析京东网站数据
  • SQL 干货 | SQL 反连接
  • JSON 反对序列化 public final class LocalDateTime 日期格式错误
  • Java 集合
  • 爬虫日常实战
  • 复写零--双指针
  • 跟着小土堆学习pytorch(二)——TensorBoard和Transform
  • 自由学习记录(10)
  • Redis提供了专门的命令来实现自增操作
  • uniapp修改input中placeholder样式
  • GenerativeU:生成式开放目标检测