cool-iot – Diff between revs 5 and 6
?pathlinks?
Rev 5 | Rev 6 | |||
---|---|---|---|---|
Line 27... | Line 27... | |||
27 | |
27 | |
|
28 | // Set up logger. |
28 | // Set up logger. |
|
Line 29... | Line 29... | |||
29 | winston.add(winston.transports.File, {filename: config.log}) |
29 | winston.add(winston.transports.File, {filename: config.log}) |
|
30 | |
30 | |
|
Line 31... | Line 31... | |||
31 | // Initiate connection to MQTT. |
31 | // Initiate connection to MQTT. |
|
32 | const client = mqtt.connect(config.mqtt.url) |
32 | const client = mqtt.connect(config.mqtt.url, {queueQoSZero: false}) |
|
33 | |
33 | |
|
34 | client.on('connect', function () { |
- | ||
35 | winston.info('Connected to MQTT server') |
34 | client.on('connect', function () { |
|
Line 36... | Line 35... | |||
36 | client.subscribe(config.mqtt.topic) |
35 | winston.info('Connected to MQTT server') |
|
37 | //client.publish('presence', 'Hello mqtt') |
36 | client.subscribe(config.mqtt.topic) |
|
- | 37 | }) |
||
- | 38 | |
||
- | 39 | client.on('message', function (topic, message) { |
||
- | 40 | if(message.length === 0) |
||
- | 41 | return; |
||
38 | }) |
42 | |
|
39 | |
43 | // Remove any retained message. |
|
40 | client.on('message', function (topic, message) { |
44 | client.publish(topic, "", {retain: true}) |
|
41 | // message is Buffer |
45 | |
|
42 | message = message.toString() |
46 | message = message.toString() |