无法通过MQTT将数据发送到ThingsBoard网关

时间:2020-01-16 12:41:29

标签: mqtt thingsboard thingsboard-gateway

我已经在一台PC(UBUNTU16.04)上安装了ThingsBoard服务器,在另一台PC(UBUNTU18.04)上安装了ThingsBoard Gateway,为了将数据发送到ThingsBoard Gateway,我在另一台PC上安装了Mosquitto MQTT代理。我按照配置指南进行操作将代理连接到网关以及服务器(使用访问令牌和主机ip)。

我将温度传感器连接到ESP32。当我尝试通过MQTT将数据发送到网关时,数据并没有到达网关。我在这里使用的主题是“ v1 / gateway / telemetry”,以便发布数据。

我们可以使用网关设备ID发送数据吗? 如何通过主题,设备ID或设备访问令牌发送数据?(来自设备)

所有PC都连接到同一网络(专用网络)。

我正面临这个问题,有人可以解决...

1 个答案:

答案 0 :(得分:0)

您需要在MQTT Broker和您的服务器之间创建一个代理层。

var mqtt = require('mqtt'), url = require('url');
var client = mqtt.connect('mqtt://localhost:1883',
{
username: '<username>',
password: '<password>'
});

console.log("Connected to MQTT Broker:- localhost” + client.toString());
var awsIot = require('aws-iot-device-sdk');
var device = awsIot.device({

keyPath:  Certificate key file path,
certPath: Certificate file path,
caPath:   Certificate root file path,
clientId: AWS Thing Name,
region:   AWS IoT Broker region,
});

device.on('connect', function ()
{
console.log("Connected to AWS IoT Broker:- " + device.toString());
});

client.on('connect', function()
{
//subscribe to a topic (#)
client.subscribe('#', function ()
{
client.on('message', function (topic, message, packet) {
console.log("Received :-" + message + " on " + topic);
device.publish(topic, message);
console.log("Sent :-" + message + " on " + topic);
});
});
});

类似的事情可能会对您有所帮助。