Skip to content

Commit

Permalink
Merge branch 'readonlymode'
Browse files Browse the repository at this point in the history
  • Loading branch information
micw committed Mar 14, 2021
2 parents 26f678a + c0e3287 commit 55638f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Options:
[default: "info"]
-w, --disable-watch disable file watching (don't exit process on file
changes) [default: false]
--disable-lwt disable last-will-and-testament (usefull if the
remote broker is read-only) [default: false]
-l, --latitude [default: 48.7408]
-m, --longitude [default: 9.1778]
</pre>
Expand Down
5 changes: 3 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const config = require('yargs')
.describe('help', 'show help')
.describe('dir', 'directory to scan for .js and .coffee files. can be used multiple times.')
.describe('disable-watch', 'disable file watching (don\'t exit process on file changes)')
.describe('disable-lwt', 'disable last-will-and-testament (usefull if the remote broker is read-only)')
.alias({
c: 'config',
d: 'dir',
Expand All @@ -21,7 +22,6 @@ const config = require('yargs')
u: 'url',
v: 'verbosity',
w: 'disable-watch'

})
.default({
url: 'mqtt://127.0.0.1',
Expand All @@ -31,7 +31,8 @@ const config = require('yargs')
'variable-prefix': 'var',
verbosity: 'info',
'disable-variables': false,
'disable-watch': false
'disable-watch': false,
'disable-lwt': false
})
.config('config')
.version()
Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@ function sunScheduleEvent(obj, shift) {
}

// MQTT
const mqtt = modules.mqtt.connect(config.url, {will: {topic: config.name + '/connected', payload: '0', retain: true}});
mqtt.publish(config.name + '/connected', '2', {retain: true});
function connect(config) {
var mqtt;
if (config.disableLwt) {
mqtt = modules.mqtt.connect(config.url);
} else {
mqtt = modules.mqtt.connect(config.url, {will: {topic: config.name + '/connected', payload: '0', retain: true}});
mqtt.publish(config.name + '/connected', '2', {retain: true});
}
return mqtt;
}
const mqtt = connect(config);

let firstConnect = true;
let startTimeout;
Expand Down

0 comments on commit 55638f5

Please sign in to comment.