Thingsboardgatewaypython版本的安装配置和使用说明.docx
- 文档编号:28826717
- 上传时间:2023-07-20
- 格式:DOCX
- 页数:18
- 大小:19.63KB
Thingsboardgatewaypython版本的安装配置和使用说明.docx
《Thingsboardgatewaypython版本的安装配置和使用说明.docx》由会员分享,可在线阅读,更多相关《Thingsboardgatewaypython版本的安装配置和使用说明.docx(18页珍藏版)》请在冰豆网上搜索。
Thingsboardgatewaypython版本的安装配置和使用说明
TB-Gateway版本安装及使用说明
----python版本
一、安装指南
从源代码安装ThingsBoardGateway,遵循以下步骤:
1.Windows上安装python3,然后配置环境变量:
2.从Github下载存储库:
gitclone
3.移至下载目录:
cdthingsboard-gateway
4.使用setup.py脚本安装python模块:
python3setup.pyinstall
5.创建“日志”文件夹:
mkdirlogs
6.配置网关使其与ThingsBoard平台实例一起使用,接下来会介绍配置文件。
7.运行网关,检查安装结果:
python3./thingsboard_gateway/tb_gateway.py
二、配置文件
配置文件的目录
/etc/thingsboard-gateway/config
tb_gateway.yaml-网关主配置文件
logs.conf-日志配置文件
modbus.json-MODBUS配置文档
mqtt.json-MQTT配置文档
ble.json-BLE配置文档
opcua.json-OPC-UA配置文档
主配置文件结构
用于连接到ThingsBoard平台实例和启用/禁用连接器的主要配置文件。
此配置指向ThingsBoard实例demo.thingsboard.io并使用配置为最多存储100,000条记录的内存文件存储。
有4个不同的活动连接器。
如果您只想使用其中之一-只需移除所有其他连接器即可。
thingsboard:
host:
demo.thingsboard.io//mqttbrokeIP地址
port:
1883//mqttbroker端口号
security:
accessToken:
PUT_YOUR_ACCESS_TOKEN_HERE//tb平台一个网关设备的token
storage:
type:
memory
read_records_count:
100
max_records_count:
100000
connectors:
-
name:
MQTTBrokerConnector
type:
mqtt
configuration:
mqtt.json
-
name:
ModbusConnector
type:
modbus
configuration:
modbus.json
-
name:
OPC-UAConnector
type:
opcua
configuration:
opcua.json
-
name:
BLEConnector
type:
ble
configuration:
ble.json
三、MQTT连接器配置
连接器配置:
mqtt.json
连接器配置是一个JSON文件,其中包含有关如何连接到外部MQTT代理,订阅数据馈送时使用哪些主题以及如何处理数据的信息。
让我们使用以下示例来查看配置文件的格式。
MQTT连接器配置文件示例。
下面列出的示例将连接到IP192.168.1.100服务器上部署的本地网络中的MQTT代理。
连接器将使用用户名和密码使用基本的MQTT身份验证。
然后,连接器将使用“映射”部分中的主题过滤器订阅主题列表。
在下面的说明中查看更多信息。
{
"broker":
{
"name":
"DefaultLocalBroker",
"host":
"192.168.1.100",
"port":
1883,
"security":
{
"type":
"basic",
"username":
"user",
"password":
"password"
}
},
"mapping":
[
{
"topicFilter":
"/sensor/data",
"converter":
{
"type":
"json",
"deviceNameJsonExpression":
"${serialNumber}",
"deviceTypeJsonExpression":
"${sensorType}",
"timeout":
60000,
"attributes":
[
{
"type":
"string",
"key":
"model",
"value":
"${sensorModel}"
}
],
"timeseries":
[
{
"type":
"double",
"key":
"temperature",
"value":
"${temp}"
},
{
"type":
"double",
"key":
"humidity",
"value":
"${hum}"
}
]
}
},
{
"topicFilter":
"/sensor/+/data",
"converter":
{
"type":
"json",
"deviceNameTopicExpression":
"(?
<=sensor\/)(.*?
)(?
=\/data)",
"deviceTypeTopicExpression":
"Thermometer",
"timeout":
60000,
"attributes":
[
{
"type":
"string",
"key":
"model",
"value":
"${sensorModel}"
}
],
"timeseries":
[
{
"type":
"double",
"key":
"temperature",
"value":
"${temp}"
},
{
"type":
"double",
"key":
"humidity",
"value":
"${hum}"
}
]
}
},
{
"topicFilter":
"/custom/sensors/+",
"converter":
{
"type":
"custom",
"extension":
"CustomMqttUplinkConverter",
"extension-config":
{
"temperatureBytes":
2,
"humidityBytes":
2,
"batteryLevelBytes":
1
}
}
}
],
"connectRequests":
[
{
"topicFilter":
"sensor/connect",
"deviceNameJsonExpression":
"${SerialNumber}"
},
{
"topicFilter":
"sensor/+/connect",
"deviceNameTopicExpression":
"(?
<=sensor\/)(.*?
)(?
=\/connect)"
}
],
"disconnectRequests":
[
{
"topicFilter":
"sensor/disconnect",
"deviceNameJsonExpression":
"${SerialNumber}"
},
{
"topicFilter":
"sensor/+/disconnect",
"deviceNameTopicExpression":
"(?
<=sensor\/)(.*?
)(?
=\/disconnect)"
}
],
"attributeUpdates":
[
{
"deviceNameFilter":
"SmartMeter.*",
"attributeFilter":
"uploadFrequency",
"topicExpression":
"sensor/${deviceName}/${attributeKey}",
"valueExpression":
"{\"${attributeKey}\":
\"${attributeValue}\"}"
}
],
"serverSideRpc":
[
{
"deviceNameFilter":
".*",
"methodFilter":
"echo",
"requestTopicExpression":
"sensor/${deviceName}/request/${methodName}/${requestId}",
"responseTopicExpression":
"sensor/${deviceName}/response/${methodName}/${requestId}",
"responseTimeout":
10000,
"valueExpression":
"${params}"
},
{
"deviceNameFilter":
".*",
"methodFilter":
"no-reply",
"requestTopicExpression":
"sensor/${deviceName}/request/${methodName}/${requestId}",
"valueExpression":
"${params}"
}
]}
Broker部分
参数
默认值
描述
name
DefaultBroker
自定义名称
host
localhost
Mqttbroker域名或IP.
port
1883
Mqttport端口号.
安全部分,一般选择Basic模式
参数
默认值
描述
type
basic
授权类型.
username
username
用户名.
password
password
密码.
“映射”部分
主题还支持特殊的符号如“#””+”,这样可以订阅更多的主题
参数
默认值
描述
主题过滤
/sensor/data
网关订阅的主题
推送的数据结构
例子名称
主题
主题过滤器
数据包
备注
Example1
/sensor/data
/sensor/data
{“serialNumber”:
“SN-001”,“sensorType”:
“Thermometer”,“sensorModel”:
“T1000”,“temp”:
42,“hum”:
58}
设备名称作为数据包的一部分
Example2
/sensor/SN-001/data
/sensor/+/data
{“sensorType”:
“Thermometer”,“sensorModel”:
“T1000”,“temp”:
42,“hum”:
58}
设备名称作为主题一部分
数据转化器
参数
默认值
描述
type
json
提供给转换器的数据格式
deviceNameJsonExpression
${serialNumber}
从json数据包中提取key为serialNumber的值,作为设备名称
deviceTypeJsonExpression
${sensorType}
从json数据包中提取key为sensorType的值,作为设备类型
timeout
60000
“设备断开连接”事件超时时间
attributes
设备属性
…type
string
属性数据类型
…key
model
属性名称
…value
${sensorModel}
从json数据包中提取key为sensorModel的值,作为属性值
timeseries
时序数据
…type
double
时序数据的数据类型
…key
temperature
时序数据的key
…value
${temp}
从json数据包中提取key为temp的值,作为时序值
服务端发送rpc到设备端
参数
默认值
描述
设备名称过滤表达式
.*
正则表达式,用于标识设备名称
方法名过滤器
echo
正则表达式方法名筛选器,用于确定要执行的函数。
请求主题表达式
sensor/${deviceName}/request/${methodName}/${requestId}
JSON-PATH表达式,用于创建主题用以发送RPC请求。
响应主题表达式
sensor/${deviceName}/response/${methodName}/${requestId}
JSON-PATH表达式,用于创建主题用以订阅响应消息。
responseTimeout
10000
响应延时时间(以毫秒为单位),如果发送请求后在此期间内没有响应,则网关将从响应主题中取消订阅。
valueExpression
${params}
JSON-PATH表达式,用于创建发送到代理的数据。
您可以使用deviceNameFilter和methodFilter为不同的设备/方法应用不同的映射规则。
一旦网关从服务器接收到设备的RPC请求,它将基于requestTopicExpression和valueExpression发布相应的消息。
如果希望设备回复请求,还应指定responseTopicExpression和responseTimeout。
网关将订阅“响应”主题并等待设备回复,直到检测到“响应超时”(以毫秒为单位)。
例如:
需要从服务器发送的RPC请求(RPCrequest.json)示例:
{
"method":
"echo",
"params":
{
"message":
"Hello!
"
}
}
四、MODBUS连接器配置
本指南将帮助您熟悉用于ThingsBoard物联网网关的Modbus连接器配置。
使用常规配置启用此连接器。
我们将在下面描述连接器配置文件。
ModbusConnectorconfigfile
{
"server":
{
"name":
"ModbusDefaultServer",
"type":
"tcp",
"host":
"127.0.0.1",
"port":
5020,
"timeout":
35,
"method":
"rtu",
"devices":
[
{
"unitId":
1,
"deviceName":
"TempSensor",
"attributesPollPeriod":
5000,
"timeseriesPollPeriod":
5000,
"sendDataOnlyOnChange":
true,
"attributes":
[
{
"byteOrder":
"BIG",
"tag":
"test",
"type":
"long",
"functionCode":
4,
"registerCount":
1,
"address":
0
}
],
"timeseries":
[
{
"byteOrder":
"BIG",
"tag":
"test",
"type":
"long",
"functionCode":
4,
"registerCount":
1,
"address":
0
}
],
"rpc":
{
"turnLightOn":
{
"address":
4,
"bit":
2,
"value":
true
},
"turnLightOff":
{
"address":
4,
"bit":
2,
"value":
false
},
"getCPULoad":
{
"tag":
"Integer",
"value":
42,
"functionCode":
16,
"address":
0,
"unitId":
1,
"byteOrder":
"BIG",
"registerCount":
1
}
}
}
]
}}
Server部分说明
TCP/UDP协议
参数
默认值
描述
name
ModbusDefaultServer
连接器名称
type
tcp
连接类型,可以是:
tcp, udp or serial.
host
127.0.0.1
Modbusserver的IP
port
5020
Modbusserver的端口号
timeout
35
连接到Modbus服务器超时(秒)时间.
method
socket
连接形式 socket or rtu
串口连接
参数
默认值
描述
name
ModbusDefaultServer
连接器名称
type
serial
连接类型,可以是:
tcp, udp or serial.
port
/dev/ttyUSB0
设备串口名称
timeout
35
连接到Modbus服务器超时(秒)时间.
method
rtu
数据单元类型 rtu or ascii
设备参数
此配置部分提供设备连接和数据处理的配置。
参数
默认值
描述
unitId
1
Modbus当前设备的Id
deviceName
TempSensor
设备名称
attributesPollPeriod
5000
检查设备上属性的时间(毫秒).
timeseriesPollPeriod
5000
检查设备上的遥测的时间(毫秒)。
sendDataOnlyOnChange
true
仅在上次检查数据更改时发送
设备属性
本小节中的配置提供了在Modbus服务器上处理数据的设置,这些设置将在ThingsBoard平台实例中解释为设备的属性
参数
默认值
描述
byteOrder
BIG
要读取的字节顺序
tag
test
Tb平台设备的标签域
type
long
属性数据类型(long, integer, string, double, bit)
functionCode
4
Modbus的功能码
registerCount
1
要读取的寄存器计数
address
0
寄存器起始地址。
设备时序
本小节中的配置提供了在Modbus服务器上处理数据的设置,该设置将在ThingsBoard平台实例中解释为设备遥测。
参数
默认值
描述
byteOrder
BIG
要读取的字节顺序。
可以是大端或者小端,取决于硬件
tag
test
Tb平台设备的标签域
type
long
时序数据类型(long, integer, string, double, bit)
functionCode
4
Modbus的功能码
registerCount
1
要读取的寄存器计数
address
0
寄存器起始地址。
Modbus连接器支持以下Modbus功能:
读取线圈(功能代码1)
读取离散输入(功能代码2)
读取多个保持寄存器(功能代码3)
读取输入寄存器(功能代码4)
硬件制造商可以实现各种数据类型。
以下是有助于将常见硬件数据类型转换为Thingsboard键值格式的映射规则:
硬件端数据类型
TB端的数据类型
Function编码
寄存器个数
备注
Bool
boolean
1-4
1
Word
long
3-4
1
DWord/Integer
long
3-4
2
Integer64
long
3-4
4
Float
double
3-4
2
Double
double
3-4
4
String
string
3-4
1-…
服务端发送RPC到modbus设备
本小节中的配置提供从ThingsBoard平台实例到设备的RPC请求的设置。
参数
默认值
描述
turnLightOn
RPC函数的名称。
address
4
寄存器起始地址
bit
2
要设置/读取的位地址。
value
true
待写入的数据值
registerCount
1
设置/读取的寄存器个数
unitId
1
执行rpc请求的设备单元的标识符
byteOrder
BIG
字节顺序,将值写入寄存器
tag
Integer
数值类型.(long, integer, string, double, bit)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Thingsboard gateway python版本的安装配置和使用说明 python 版本 安装 配置 使用说明