IOT Gateway 配置

目录结构

/etc/thingsboard-gateway/config                   - Configuration folder.
    tb_gateway.yaml                               - Main configuration file for Gateway.
    logs.conf                                     - Configuration file for logging.
    modbus.json                                   - Modbus connector configuration.
    mqtt.json                                     - MQTT connector configuration.
    ble.json                                      - BLE connector configuration.
    opcua.json                                    - OPC-UA connector configuration.
    request.json                                  - Request connector configuration.
    can.json                                      - CAN connector configuration. 
    ... 

/var/lib/thingsboard_gateway/extensions           - Folder for custom connectors/converters.                      
    modbus                                        - Folder for Modbus custom connectors/converters.
    mqtt                                          - Folder for MQTT custom connectors/converters.
        __init__.py                               - Default python package file, needed for correct imports.
        custom_uplink_mqtt_converter.py           - Custom Mqtt converter example.
    ...
    opcua                                         - Folder for OPC-UA custom connectors/converters.
    ble                                           - Folder for BLE custom connectors/converters.
    request                                       - Folder for Request custom connectors/converters.
    can                                           - Folder for CAN custom connectors/converters.

/var/log/thingsboard-gateway                      - Logs folder
    connector.log                                 - Connector logs.
    service.log                                   - Main gateway service logs.
    storage.log                                   - Storage logs.
    tb_connection.log                             - Logs for connection to the ThingsBoard instance.

通用配置文件

主配置问及那用于连接到ThingsBoard平台实例和启用/禁用连接器。这配置文件只想ThingsBoard实例并使用配置为存储最多100000条记录的内存文件存储。有4个不同的连接器处于活动状态。如果您只想使用其中之一,只需移除所有其他连接器。

主配置文件样例:

thingsboard:
  host: thingsboard.cloud
  port: 1883
  security:
    accessToken: PUT_YOUR_ACCESS_TOKEN_HERE
storage:
  type: memory
  read_records_count: 100
  max_records_count: 100000
connectors:
  -
    name: MQTT Broker Connector
    type: mqtt
    configuration: mqtt.json

  -
    name: Modbus Connector
    type: modbus
    configuration: modbus.json

  -
    name: Modbus Connector
    type: modbus
    configuration: modbus_serial.json

  -
    name: OPC-UA Connector
    type: opcua
    configuration: opcua.json

  -
    name: BLE Connector
    type: ble
    configuration: ble.json

  -
    name: CAN Connector
    type: can
    configuration: can.json

  -
    name: Custom Serial Connector
    type: serial
    configuration: custom_serial.json
    class: CustomSerialConnector

配置文件中的模块

  • thingsboard - 用于连接到ThingsBoard 平台的配置
  • storage - 用于本地存储来自设备的数据的配置
  • connectors - 连接器数组及其要使用的配置

安全子模块“security”

三种不同的安全配置

访问令牌(Access Token)

登录您的ThingsBoard平台来获取访问令牌。首先进入到设备选项卡(设备为网关的)

参数 默认值 描述
accessToken PUT_YOUR_GW_ACCESS_TOKEN_HEAR 来自ThingsBoard服务器的网关的访问令牌

安全子模块的配置如下所示:

...
  security:
    accessToken: PUT_YOUR_GW_ACCESS_TOKEN_HERE
...

安全传输协议 + 访问令牌(TLS + Access Token)

参数 默认值 描述
accessToken PUT_YOUR_GW_ACCESS_TOKEN_HEAR 来自 ThingsBoard服务器的网关访问令牌
caCert /etc/thingsboard-gateway/mqttserver.pub.pem CA证书文件

安全子模块的配置如下所示:

  security:
    accessToken: PUT_YOUR_GW_ACCESS_TOKEN_HERE
    caCert: /etc/thingsboard-gateway/mqttserver.pub.pem

安全传输协议 + 私钥(TLS + Private Key)

参数 默认值 描述
caCert /etc/thingsboard-gateway/ca.pem CA证书文件
privateKey /etc/thingsboard-gateway/privateKey.pem 私钥文件
cert /etc/thingsboard-gateway/certificate.pem 证书文件

安全子模块的配置如下所示:

  security:
    privateKey: /etc/thingsboard-gateway/privateKey.pem
    caCert: /etc/thingsboard-gateway/ca.pem
    cert: /etc/thingsboard-gateway/certificate.pem

存储配置

存储模块配置提供了在将传入数据发送到ThingsBoard平台之前保存传入数据的相关配置。其中有两种存储方式:内存和文件

1. 内存存储 - 接收到的数据存储到内存中

2. 文件存储 - 接收到的数据存储到硬盘中

内存存储(磁盘空间充足时建议使用该方式)

参数 默认值 描述
type memory 存储类型(存储到内存)
read_records_count 10 从存储中获取并发送到ThingsBoard的消息数量
max_records_count* 100 发送到ThingsBoard之前存储的最大数据量

备注:如果接收到的数据超过最大存储最大值,新的数据将会丢失

存储模块配置如下所示:

storage:
  type: memory
  read_records_count: 10
  max_records_count: 1000

文件存储(需要持久化保存的建议使用该方式)

参数 默认值 描述
type file 存储类型(存储到硬盘)
data_folder_path ./data/ 文件路径
max_file_count 5 将会保存的最大文件数
max_read_records_count* 6 从存储中获取并发送到ThingsBoard的消息数量
max_records_per_file 14 每个文件存储的最大记录数

备注:如果接收到的数据超过最大存储最大值,新的数据将会丢失

存储模块的配置如下所示:

storage
  type: file
  data_folder_path: ./data/
  max_file_count: 5
  max_read_records_count: 6
  max_records_per_file: 14

连接器配置

通过实现不同协议连接到设备的配置,每种连接器的配置参数如下表所示:

参数 默认值 描述
name MQTT Broker Connector 连接到broker的连接器名称
type mqtt 连接器类型
configuration mqtt.json 配置文件的名字
connectors:

  -
    name: MQTT Broker Connector
    type: mqtt
    configuration: mqtt.json

  -
    name: Modbus Connector
    type: modbus
    configuration: modbus.json

  -
    name: Modbus Connector
    type: modbus
    configuration: modbus_serial.json

  -
    name: OPC-UA Connector
    type: opcua
    configuration: opcua.json

  -
    name: BLE Connector
    type: ble
    configuration: ble.json

  -
    name: CAN Connector
    type: can
    configuration: can.json

  -
    name: Custom Serial Connector
    type: serial
    configuration: custom_serial.json
    class: CustomSerialConnector

上一篇:Tomcat架构


下一篇:python构建父类的初始化方法有多种