这可能很容易,但我无法在线找到解决方案。我正在使用 Cylon 和 MQTT 开展气象站项目,并尝试将变量传递到 MQTT 推送中,但它正在传递文字文本。发布成功,但它只有“味精”而不是传感器数据。这是片段..
Cylon.robot({
connections: {
edison: { adaptor: 'intel-iot' }
},
devices: {
bmp180: { driver: 'bmp180' }
},
work: function(my) {
my.bmp180.getTemperature(function(err, val) {
if (err) {
console.log(err);
return;
}
console.log("\tTemp: " + val.temp + " C");
var msg = { "temperature" : val.temp,
"pressure" : val.press,
"altitude" : val.alt
};
var msgPressure = { "pressure" : val.press };
var msgAltitude = { "altitude" : val.alt };
device
.on('connect', function() {
console.log('connect');
device.subscribe('weather/push');
device.publish('weather/push', JSON.stringify({ msg: 1}));
});
device
.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});
});
}
}).start();
谢谢