From 5b07d87eecb54651be1cd2db9a3024728a1ade11 Mon Sep 17 00:00:00 2001 From: "St. John Johnson" Date: Sun, 7 Feb 2016 09:59:50 -0800 Subject: [PATCH] Allow duplicate messages from SmartThings and reduce verbosity on duplicate MQTT messages --- server.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/server.js b/server.js index 9612457..491fbe8 100644 --- a/server.js +++ b/server.js @@ -59,15 +59,7 @@ function handlePushEvent(req, res) { var topic = ['', 'smartthings', req.body.name, req.body.type].join('/'), value = req.body.value; - winston.info('Incoming message from SmartThings to ' + topic + ' ' + value); - - if (history[topic] === value) { - winston.info('Skipping duplicate message'); - - return res.send({ - 'status': 'DUPLICATE' - }); - } + winston.info('Incoming message from SmartThings: %s = %s', topic, value); history[topic] = value; client.publish(topic, value, { @@ -125,13 +117,13 @@ function handleSubscribeEvent(req, res) { * @param {String} message Contents of the event */ function parseMQTTMessage (topic, message) { - winston.info('Incoming message from: ' + topic, message.toString()); - - if (history[topic] === message.toString()) { - winston.info('Skipping duplicate message'); + var contents = message.toString(); + if (history[topic] === contents) { + winston.debug('Skipping duplicate message from: %s = %s', topic, contents); return; } - history[topic] = message.toString(); + winston.info('Incoming message from MQTT: %s = %s', topic, contents); + history[topic] = contents; var pieces = topic.split('/'), name = pieces[2], @@ -142,7 +134,7 @@ function parseMQTTMessage (topic, message) { json: { name: name, type: type, - value: message.toString() + value: contents } }, function (error, resp) { if (error) {