This is probably easy but I could not locate a solution online. I am working on a weather station project with Cylon and MQTT and attempting to pass a variable into an MQTT push but it is passing the literal text. The publish is successful but it just has "msg" instead of the sensor data. Here is the snippet..
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();
Thank you