Skip to content
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

message is a Buffer, so needs toString. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 19 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,36 @@ if (config.output) {
if (config.output.indexOf(id) !== -1) {
let val;
try {
tmp = JSON.parse(message);
let tmp = JSON.parse(message);
if (typeof tmp.val === 'undefined') {
throw new TypeError('attribute val missing');
} else {
val = Boolean(tmp.val);
}
} catch (err) {
if (message === 'false') {
log.debug('message does not look like json: ' + err);
}

if (typeof val === 'undefined') {
let tmp = message.toString();
if (tmp === 'false') {
val = false;
} else if (message === 'true') {
} else if (tmp === 'true') {
val = true;
} else if (typeof message === 'string') {
val = parseInt(message, 10) || false;
} else {
val = Boolean(message);
let int = parseInt(tmp, 10);
if (!isNaN(int))
val = int
}
}
val = val ? 1 : 0;
io[id].writeSync(val);

if (typeof val !== 'undefined') {
val = val ? 1 : 0;
log.debug('setting gpio ' + id + ' to ' + val);
io[id].writeSync(val);
} else {
log.debug('could not parse gpio value');
}
}
}
});
Expand Down