From fcce4a840deabd84a3eb7fa4f5c3bd979e360aef Mon Sep 17 00:00:00 2001 From: Martin Kleine Date: Wed, 31 May 2017 20:06:02 +0200 Subject: [PATCH] Enhanced cmd with arguments (also reflected in config.example.json) --- config/config.example.json | 9 +++++++++ lib/dasher.js | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config/config.example.json b/config/config.example.json index bb92d79..d2b1f97 100644 --- a/config/config.example.json +++ b/config/config.example.json @@ -49,5 +49,14 @@ "name": "Command Exec Button", "address": "41:02:dc:b2:10:12", "cmd": "/home/user/dash_button.sh" + }, + { + "name": "WOL Button", + "address": "41:02:dc:b2:10:1f", + "cmd": "etherwake", + "args": [ + "AA:AA:AA:BB:BB:BB", + "CC:CC:CC:DD:DD:DD" + ] } ]} diff --git a/lib/dasher.js b/lib/dasher.js index 3dabfe9..53a81cf 100644 --- a/lib/dasher.js +++ b/lib/dasher.js @@ -26,7 +26,7 @@ function DasherButton(button) { doLog("Debug mode, skipping request."); console.log(button); } else if (typeof button.cmd !== 'undefined' && button.cmd != "") { - doCommand(button.cmd, button.name) + doCommand(button.cmd, button.args) } else { doRequest(button.url, button.method, options) } @@ -35,12 +35,12 @@ function DasherButton(button) { doLog(button.name + " added.") } -function doCommand(command, name, callback) { - const child = execFile(command, [name], (error, stdout, stderr) => { +function doCommand(command, args, callback) { + const child = execFile(command, args, (error, stdout, stderr) => { if (error) { // Stripping a trailing new line output = stderr.replace (/\s+$/g, ""); - doLog(`There was an error: ${output}`); + doLog(`There was an error: ${output}`); } if (stdout != "") {