I am trying to pass parameters to a JavaScript file which will be executed using NodeJS.
The JavaScript file contains following function:
function handleEvent() {
var options = { method: 'POST',
url: 'http://'+LOCAL_PC_ADDRESS+'/events/job/started',
qs:
{ filename: 'example/file.gcode',
testArguments: process.argv },
headers:
{
'cache-control': 'no-cache' } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
}
In which a field testArguments
is used to check the arguments passed to this file.
If I run:
node myscript.js "foo" "bar"
Into returned POST I get what I expect:
{ filename: 'example/file.gcode',
testArguments:
[ '/usr/bin/node',
'/home/pi/prototype-rasp/myfile.js',
'foo',
'bar'
] }
And until now it is all okay.
The problems come when I use OctoPrint API event hooks, I configure events into config.yaml as shown in the docs. Part of this config.yaml is reported here:
events:
enabled: True
subscriptions:
- event: Connected
command: /usr/bin/node /home/pi/prototype-rasp/myscript.js "foo" "bar"
type: system
enabled: true
I tried also using command: /usr/bin/node /home/pi/prototype-rasp/myscript.js -- "bar" "foo"
. I fire the OctoPrint event that correctly found the yaml event hook, launches the script but there are no arguments in process.argv
, missing foo and bar.
Any idea how to solve it?