Thingsboard ThingsBoard IoT Gateway 2.3.1 (Python 版本) 调试记录

samismy · 2020年05月22日 · 最后由 sn_lele 回复于 2020年06月05日 · 248 次阅读
本帖已被设为精华帖!

前序

本手册数据来源为百度 Google 搜索,官方 issues,以及本人的实验所得进行记录扩充

环境要求:python3.5+,windows,mqtt 服务端

1. 拉取代码

git clone https://github.com/thingsboard/thingsboard-gateway.git

(实验使用的是 2.3.1)

安装

python setup.py

2. 配置文件

config 目录下找到两个文件: tb_gateway.yaml

thingsboard:
  host: 127.0.0.1  (ThingsBoard 的地址)
  port: 1883  (ThingsBoard 的端口)
  remoteConfiguration: false
  security:
    accessToken: 3nerZPVwh4gdSKor5epq  (此处替换成ThingsBoard 上设置的网关访问令牌)

和 mqtt.json

"broker": {
  "name":"Default Local Broker",
  "host":"127.0.0.1",   (mqtt的服务器地址,切忌不是ThingsBoard 的地址)
  "port":1884,(mqtt的服务器端口,切忌不是ThingsBoard 的端口)
  "security": {
    "type": "basic",
    "username": "thingsboard",  (mqtt的服务器的用户名)
    "password": "thingsboard"  (mqtt的服务器的密码)
  }
},

3. 运行

切换到 thingsboard_gateway/下

python tb_gateway.py
C:\IOT\thingsboard-gateway-python3\thingsboard_gateway>pytho
n tb_gateway.py
""2020-05-21 15:53:05" - INFO - [tb_gateway_service.py] - tb_gateway_service - 6
5 - Gateway starting..."
""2020-05-21 15:53:05" - INFO - [tb_gateway_service.py] - tb_gateway_service - 7
0 - ThingsBoard IoT gateway version: 2.3.1"
""2020-05-21 15:53:05" - INFO - [tb_gateway_mqtt.py] - tb_gateway_mqtt - 175 - S
ubscribed to *|* with id 1"
('F:\\py\\py3\\lib\\site-packages\\thingsboard_gateway-2.3.1-py3.5.egg\\thingsbo
ard_gateway\\connectors\\mqtt', '\\var\\lib\\thingsboard_gateway\\extensions\\mq
tt', 'F:\\py\\py3\\lib\\site-packages\\thingsboard_gateway-2.3.1-py3.5.egg\\thin
gsboard_gateway\\extensions\\mqtt')
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 155 - Num
ber of accepted mapping handlers: 3"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 159 - Num
ber of rejected mapping handlers: 0"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 155 - Num
ber of accepted serverSideRpc handlers: 2"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 159 - Num
ber of rejected serverSideRpc handlers: 0"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 155 - Num
ber of accepted connectRequests handlers: 2"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 159 - Num
ber of rejected connectRequests handlers: 0"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 155 - Num
ber of accepted disconnectRequests handlers: 2"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 159 - Num
ber of rejected disconnectRequests handlers: 0"
""2020-05-21 15:53:05" - ERROR - [mqtt_connector.py] - mqtt_connector - 130 - 'a
ttributeRequests' section missing from configuration"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 155 - Num
ber of accepted attributeUpdates handlers: 1"
""2020-05-21 15:53:05" - INFO - [mqtt_connector.py] - mqtt_connector - 159 - Num
ber of rejected attributeUpdates handlers: 0"

4. MQTTBox 发送测试数据

MQTT 主题:/sensor/data

内容:

{"serialNumber": "SN-004", "sensorType": "Thermometer", "sensorModel": "T1000", "temp": 111, "hum": 99} 

5. 验证

会在 ThingsBoard 上自动创建命名 SN-004 的设备。

网关处会关联表明从网关过来的

# 参考文献:

  1. https://thingsboard.io/docs/iot-gateway/getting-started/ 在 ThingsBoard 上配置网关
  2. https://thingsboard.io/docs/iot-gateway/configuration/#section-connectors 网关配置解说
  3. https://www.cnblogs.com/weschen/p/11589181.html ThingsBoard GateWay Java 版本的教程
  4. http://workswithweb.com/mqttbox.html mqttbox 下载
sds 将本帖设为了精华贴 05月22日 10:07

专业!!

谢谢

安装的命令为: python setup.py install

老哥,运行 python setup.py install 后出现 “libxml/xmlversion.h”: No such file or directory 这个问题,是依赖没有下载完成吗

您好,看过了官网和您的教程 在连接的时候还是有点问题

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册