ThingsBoard端版本信息
系统:Ubuntu 18.04
ThingsBoard:ThingsBoard-3.0.1
PostgreSQL:12.3
TB-Gateway端版本信息
系统:Ubuntu 18.04
TB-Gateway:ThingsBoard IoT gateway version 2.4.0
MySql:Ver 14.14 Distrib 5.7.30
安装步骤参考官网:https://thingsboard.io/docs/iot-gateway/install/deb-installation/
主要步骤:
#下载安装包
wget https://github.com/thingsboard/thingsboard-gateway/releases/latest/download/python3-thingsboard-gateway.deb
#安装启动
sudo apt install ./python3-thingsboard-gateway.deb -y
#查看状态
systemctl status thingsboard-gateway
装好之后启动会有些错误,这个是还没有配置的原因,后面再进行配置
配置步骤参考官网:https://thingsboard.io/docs/iot-gateway/configuration/
安装的tb-gateway一般在 /etc/thingsboard-gateway 下,下面对 /etc/thingsboard-gateway/conf/tb_gateway 进行配置:
thingsboard:
host: 127.0.0.1 #thingsboard的地址
port: 1883 #thingsboard mqtt的服务端口,默认是1883
remoteConfiguration: false #远程配置关闭
security:
accessToken: LnV3ZmPP6lq1cQSq4gkf #token,这个需要在thingsboard新建一个网关设备,复制其令牌
storage:
type: memory
read_records_count: 100
max_records_count: 100000
# type: file
# data_folder_path: ./data/
# max_file_count: 10
# max_read_records_count: 10
# max_records_per_file: 10000
connectors: #配置了2个odbc的Connector,如果你是一个也可以只配置一个
-
name: ODBC Connector
type: odbc
configuration: odbc.json
-
name: ODBC Connector2
type: odbc
configuration: odbc_gzy.json
参考官网:https://thingsboard.io/docs/iot-gateway/config/odbc/
odbc 的先决条件:
tb-gateway使用pyodbc来操作odbc,pyodbc是ODBC的一个python封装,它允许任何平台上的python具有使用ODBC API的能力
#如果装过python的话可以不执行安装python的命令了
sudo apt install python3-pip
sudo apt install python3-dev
sudo apt install unixodbc-dev
pip3 install --user pyodbc
apt-get install libmyodbc
可能报错:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package libmyodbc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'libmyodbc' has no installation candidate
那么我们可以手动下载安装包
下载地址:https://dev.mysql.com/downloads/connector/odbc/
执行命令:
dpkg -i mysql-connector-odbc_8.0.20-1ubuntu18.04_amd64.deb
修改文件 /etc/odbcinst.ini:
[MySQL ODBC 8.0 Unicode Driver]
Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so
UsageCount=1
[MySQL ODBC 8.0 ANSI Driver]
Driver=/usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so
UsageCount=1
记住上面的名字:MySQL ODBC 8.0 Unicode Driver
{
"connection": {
"str": "Driver={MySQL ODBC 8.0 Unicode Driver};Server=localhost;Port=3306;Database=xx;Uid=root;Pwd=xx;",
"attributes": {
"autocommit": true,
"timeout": 0
},
"encoding": "utf-8",
"decoding": {
"char": "utf-8",
"wchar": "utf-8",
"metadata": "utf-16le"
},
"reconnect": true,
"reconnectPeriod": 60
},
"pyodbc": {
"pooling": false
},
"polling": {
"query": "SELECT u_id, v_r, v_avg, v_max, v_min, v_std, temperature_r, temperature_avg, temperature_max, temperature_min, temperature_std, poa_r, poa_avg, poa_max, poa_min, poa_std, poa_sum, poa_interval_sum FROM cr1000data.`1mindatas` WHERE u_id > ? ORDER BY u_id ASC LIMIT 1",
"period": 20,
"iterator": {
"column": "u_id",
"query": "SELECT Max(u_id) FROM cr1000data.1mindatas",
"persistent": false
}
},
"mapping": {
"device": {
"type": "odbc",
"name": "'gateway_ecs'"
},
"sendDataOnlyOnChange": false,
"timeseries": "*"
},
"serverSideRpc": {
"enableUnknownRpc": false,
"overrideRpcConfig": false,
"methods": [
]
}
}
其中:
开启tb-gateway:
service thingsboard-gateway start #开启
service thingsboard-gateway stop #关闭
service thingsboard-gateway status #状态