前序
本手册由一个俗人(wechat:dotzcv)整理,数据来源为百度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的设备。
网关处会关联表明从网关过来的
#参考文献:
- https://thingsboard.io/docs/iot-gateway/getting-started/ 在ThingsBoard上配置网关
- https://thingsboard.io/docs/iot-gateway/configuration/#section-connectors 网关配置解说
- https://www.cnblogs.com/weschen/p/11589181.html ThingsBoard GateWay Java版本的教程
- http://workswithweb.com/mqttbox.html mqttbox下载
来源:oschina
链接:https://my.oschina.net/u/169565/blog/4286488