cool-iot
/trunk/main.js |
@@ -29,16 +29,20 @@ |
winston.add(winston.transports.File, {filename: config.log}) |
|
// Initiate connection to MQTT. |
const client = mqtt.connect(config.mqtt.url) |
const client = mqtt.connect(config.mqtt.url, {queueQoSZero: false}) |
|
client.on('connect', function () { |
winston.info('Connected to MQTT server') |
client.subscribe(config.mqtt.topic) |
//client.publish('presence', 'Hello mqtt') |
}) |
|
client.on('message', function (topic, message) { |
// message is Buffer |
if(message.length === 0) |
return; |
|
// Remove any retained message. |
client.publish(topic, "", {retain: true}) |
|
message = message.toString() |
winston.info('Received message: ' + message) |
if(!(message in config.GPIO)) { |