Skip to content

Option to disable LWT #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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