树莓派安装Thingsboard-gateway中遇到的问题

钱峻
2023-12-01

1、下载安装包

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

2、使用apt安装网关

以软件包形式安装ThingsBoard网关并以守护程序身份运行,请使用以下命令:

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

deb软件包将自动安装必要的库,以使IOT网关正常工作:

  1. 系统库:libffi-dev,libglib2.0-dev,libxml2-dev,libxslt-dev,libssl-dev,zlib1g-dev,python3-dev,python3-pip

  2. Python模块:importlib,importlib-metadata,jsonschema,pymodbus,lxml,jsonpath-rw,paho-mqtt,pyserial,PyYAML,simplejson,pysistent

3、检查网关状态

systemctl status thingsboard-gateway

出现如下信息则表示没有配置网关和ThingsBoard连接:

5月 02 17:09:12 raspberrypi python3[15068]: ""2022-05-02 17:09:12" - |ERROR| - [mqtt_connector.py] - mqtt_connector - load_handlers - 159 - attributeRequests handler is missing some mandatory keys => rejected: {"retain": false, "topicFilt
5月 02 17:09:12 raspberrypi python3[15068]: ""2022-05-02 17:09:12" - |INFO| - [mqtt_connector.py] - mqtt_connector - load_handlers - 167 - Number of accepted attributeRequests handlers: 0"

**在这一步我出现了与安装步骤不同的问题:

root@raspberrypi:/etc/thingsboard-gateway/config# systemctl status thingsboard-gateway
● thingsboard-gateway.service - ThingsBoard Gateway
   Loaded: loaded (/etc/systemd/system/thingsboard-gateway.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2022-05-02 16:54:19 CST; 1min 12s ago
  Process: 13379 ExecStart=/usr/bin/python3 -c from thingsboard_gateway.tb_gateway import daemon; daemon() (code=exi
 Main PID: 13379 (code=exited, status=1/FAILURE)
​
5月 02 16:54:19 raspberrypi systemd[1]: thingsboard-gateway.service: Service RestartSec=100ms expired, scheduling re
5月 02 16:54:19 raspberrypi systemd[1]: thingsboard-gateway.service: Scheduled restart job, restart counter is at 5.
5月 02 16:54:19 raspberrypi systemd[1]: Stopped ThingsBoard Gateway.
5月 02 16:54:19 raspberrypi systemd[1]: thingsboard-gateway.service: Start request repeated too quickly.
5月 02 16:54:19 raspberrypi systemd[1]: thingsboard-gateway.service: Failed with result 'exit-code'.
5月 02 16:54:19 raspberrypi systemd[1]: Failed to start ThingsBoard Gateway.
lines 1-12/12 (END)...skipping...

thingsboard-gateway重启后,状态总是失败,解决办法如下:

1、查看thingsboard-gateway日志

journalctl -u thingsboard-gateway.service

journalctl 是查看日志命令,-u则是指定单元。上述命令查看thingsboard-gateway单元日志

日志中发现

5月 02 16:17:24 raspberrypi python3[1675]: Traceback (most recent call last):
5月 02 16:17:24 raspberrypi python3[1675]:   File "<string>", line 1, in <module>
5月 02 16:17:24 raspberrypi python3[1675]:   File "/usr/local/lib/python3.7/dist-packages/thingsboard_gateway-3.0
5月 02 16:17:24 raspberrypi python3[1675]:     from thingsboard_gateway.gateway.tb_gateway_service import TBGatew
5月 02 16:17:24 raspberrypi python3[1675]:   File "/usr/local/lib/python3.7/dist-packages/thingsboard_gateway-3.0
5月 02 16:17:24 raspberrypi python3[1675]:     from thingsboard_gateway.gateway.grpc_service.grpc_connector impor
5月 02 16:17:24 raspberrypi python3[1675]:   File "/usr/local/lib/python3.7/dist-packages/thingsboard_gateway-3.0
5月 02 16:17:24 raspberrypi python3[1675]:     from thingsboard_gateway.gateway.grpc_service.tb_grpc_manager impo
5月 02 16:17:24 raspberrypi python3[1675]:   File "/usr/local/lib/python3.7/dist-packages/thingsboard_gateway-3.0
5月 02 16:17:24 raspberrypi python3[1675]:     from thingsboard_gateway.gateway.grpc_service.grpc_downlink_conver
5月 02 16:17:24 raspberrypi python3[1675]:   File "/usr/local/lib/python3.7/dist-packages/thingsboard_gateway-3.0
5月 02 16:17:24 raspberrypi python3[1675]:     from thingsboard_gateway.gateway.proto.messages_pb2 import *
5月 02 16:17:24 raspberrypi python3[1675]:   File "/usr/local/lib/python3.7/dist-packages/thingsboard_gateway-3.0
5月 02 16:17:24 raspberrypi python3[1675]:     create_key=_descriptor._internal_create_key,
5月 02 16:17:24 raspberrypi python3[1675]: AttributeError: module 'google.protobuf.descriptor' has no attribute '
 

到最后一步报错,网上查询解决办法,是要将protoc和porobuf版本一致,但是用protoc --version无法查看版本。

使用以下命令:

pip install --upgrade protobuf

更新protobuf后,重启thingsboard-gateway

thingsboard-gateway正常

启动如下:

root@raspberrypi:/etc/thingsboard-gateway/config# systemctl status thingsboard-gateway
● thingsboard-gateway.service - ThingsBoard Gateway
   Loaded: loaded (/etc/systemd/system/thingsboard-gateway.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2022-05-02 17:08:38 CST; 8s ago
 Main PID: 15068 (python3)
    Tasks: 8 (limit: 4915)
   CGroup: /system.slice/thingsboard-gateway.service
           ├─15068 /usr/bin/python3 -c from thingsboard_gateway.tb_gateway import daemon; daemon()
           └─15080 /usr/bin/python3 -m pip install pymodbus>=2.3.0 --user

因为我使用CH340,USB转串口工具,后面tb-gateway还会有另外一个报错,后面的文章再说

 类似资料: