'use strict';
var mqtt = require('mqtt');
var client = mqtt.connect('mqtt://test.mosquitto.org');
client.on('message', function(topic, data) {
var sender;
if (!!data && (data.length > 0)) {
data = JSON.parse(data);
sender = data.sender;
}
if (sender !== 'self') {
console.log('Topic name ==>', topic);
console.log('Payload ==>', data);
}
});
var payload = JSON.stringify({
sender: 'self',
param1: 'uno'
});
client.subscribe('/myappname/api/robots');
client.publish('/myappname/api/robots', payload);
client.subscribe('/myappname/api/robots/cybot/devices/led/commands/toggle');
setInterval(function() {
client.publish(
'/myappname/api/robots/cybot/devices/led/commands/toggle',
payload);
}, 2000);