如何使用thingsboard Iot网关更新设备属性

时间:2018-03-16 09:38:55

标签: iot gateway thingsboard

我想使用Thingsboard IoT Gateway从设备更新属性,但它不起作用。

Thingsboard 1.4.0 物联网物联网网关1.2 Mosqquito(经纪) Node.js的(客户端)

这一切都启动并调用设备的属性更新API,但网关日志没有出现,似乎没有到达。

客户端 - >(OK)Mosqquito - >(???无日志)网关 - > Thingsboard

mqtt-config.json按原样使用它。 https://github.com/thingsboard/thingsboard-gateway/blob/master/src/main/resources/mqtt-config.json

teremetoryAPI正在运行(值已更新,如控制台中所示) 请告诉我应该更新设备属性的设置。

var mqtt = require('mqtt');
var os = require("os");
require('date-utils');
var device = 'T-001';

const thingsboardHost = "mqtt://127.0.0.1:1883";

console.log('Connecting to: %s', thingsboardHost);
var client  = mqtt.connect(thingsboardHost, {
    will: {topic: device + '/disconnect', payload: '', qos: 1}
});

var appState;

client.on('connect', function () {
    publish(device + '/connect', "");
    console.log('Client connected!');

    // teremetory OK
    publish('sensor/' + device + '/temperature', JSON.stringify({"firmware_version":"1.0.2", "value":"37.7"}));

    // attribute NG ?????
    publish("sensor/" + device + "/appState", JSON.stringify({"appState":"123"}));
});

client.on('message', function (topic, message) {
    console.log('Received attribute topic: %s, message: %s', topic, message.toString());
})

function publish (topic, json) {
    client.publish(topic, json);
    console.log('Client publish. topic[' + topic + "] [" + json + "]");
}

0 个答案:

没有答案