首先在ThingsBoard(TB)平台上新建一个网关,复制访问令牌备用 ovy9hT2CHOqODf0Hutvf

测试方案:测试设备->第三方MQTT服务->网关->TB

环境、工具准备
python3
pip
MQTT 服务器 (本地云端都可)
MQTT 调试工具
推荐使用EMQX、MQTT.FX
下载项目到本地,配置、运行
https://github.com/thingsboard/thingsboard-gateway
打开项目,根目录执行python setup.py install 安装python模块
进入thingsboard_gateway\config\tb_gateway.yaml 配置TB服务器地址、令牌

进入thingsboard_gateway\config\mqtt.json 配置第三方MQTT服务器的端口、地址、账号密码等信息

配置完成后,运行项目 python ./thingsboard_gateway/tb_gateway.py
看到以下信息表示,网关已经连接上MQTT服务器了

此时使用MQTT调试工具向网关发送数据进行测试:

注意,如果是从官网复制过来的消息体,json格式是错的(双引号不对)
!.](https://img.haomeiwen.com/i6926181/768121e03f6550b7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
正确如下:
{
"serialNumber": "SN-001",
"sensorType": "Thermometer",
"sensorModel": "T1000",
"temp": 42,
"hum": 58
}
点击发送后,可以在TB上看到日志有新设备被自动创建,在数据库中同样可以看到新建的设备,以及设备上传的数据


网友评论