【问题标题】:Unable to send data to ThingsBoard gateway through MQTT无法通过 MQTT 向 ThingsBoard 网关发送数据
【发布时间】:2020-01-16 12:41:29
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: mqtt thingsboard thingsboard-gateway


    【解决方案1】:

    您需要在 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);
    });
    });
    });
    

    这样的事情可能会对你有所帮助。

    【讨论】:

    • 感谢您的回复,我在您的代码中看到了AWS,我不明白。我在本地安装了ThingsBoard服务器,我的意思是它没有部署在云上。
    猜你喜欢
    • 2021-06-04
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多