Skip to content

Commit 55638f5

Browse files
committed
Merge branch 'readonlymode'
2 parents 26f678a + c0e3287 commit 55638f5

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Options:
107107
[default: "info"]
108108
-w, --disable-watch disable file watching (don't exit process on file
109109
changes) [default: false]
110+
--disable-lwt disable last-will-and-testament (usefull if the
111+
remote broker is read-only) [default: false]
110112
-l, --latitude [default: 48.7408]
111113
-m, --longitude [default: 9.1778]
112114
</pre>

config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const config = require('yargs')
99
.describe('help', 'show help')
1010
.describe('dir', 'directory to scan for .js and .coffee files. can be used multiple times.')
1111
.describe('disable-watch', 'disable file watching (don\'t exit process on file changes)')
12+
.describe('disable-lwt', 'disable last-will-and-testament (usefull if the remote broker is read-only)')
1213
.alias({
1314
c: 'config',
1415
d: 'dir',
@@ -21,7 +22,6 @@ const config = require('yargs')
2122
u: 'url',
2223
v: 'verbosity',
2324
w: 'disable-watch'
24-
2525
})
2626
.default({
2727
url: 'mqtt://127.0.0.1',
@@ -31,7 +31,8 @@ const config = require('yargs')
3131
'variable-prefix': 'var',
3232
verbosity: 'info',
3333
'disable-variables': false,
34-
'disable-watch': false
34+
'disable-watch': false,
35+
'disable-lwt': false
3536
})
3637
.config('config')
3738
.version()

index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,17 @@ function sunScheduleEvent(obj, shift) {
117117
}
118118

119119
// MQTT
120-
const mqtt = modules.mqtt.connect(config.url, {will: {topic: config.name + '/connected', payload: '0', retain: true}});
121-
mqtt.publish(config.name + '/connected', '2', {retain: true});
120+
function connect(config) {
121+
var mqtt;
122+
if (config.disableLwt) {
123+
mqtt = modules.mqtt.connect(config.url);
124+
} else {
125+
mqtt = modules.mqtt.connect(config.url, {will: {topic: config.name + '/connected', payload: '0', retain: true}});
126+
mqtt.publish(config.name + '/connected', '2', {retain: true});
127+
}
128+
return mqtt;
129+
}
130+
const mqtt = connect(config);
122131

123132
let firstConnect = true;
124133
let startTimeout;

0 commit comments

Comments
 (0)