Aymkdn / assistant-plugins

Des plugins pour les Assistant (comme Google Home, Cortana, Alexa)
https://aymkdn.github.io/assistant-plugins/
MIT License
92 stars 21 forks source link

Launch sur raspberry #250

Closed Ybbet closed 5 years ago

Ybbet commented 5 years ago

Bonjour,

J'essaie d'exécuter par IFTTT une commande pm2. J'ai créé un applet :

Dans les logs, j'ai bien :

1|assistan | [assistant] (2019-06-05 14:23:28) Commande reçue:  [ 'launch_"pm2 restart mm"',
1|assistan |   'notifier_{salon} Magic Mirror restart' ]

Le notifier fonctionne. Mais pas le launch. De ce fait, y a-t-il une écriture particulière pour launch ? Une restriction ?

Merci de votre aide.

Aymkdn commented 5 years ago

Peut-être en mettant le path complet vers pm2 ?

Ybbet commented 5 years ago

Je viens d’essayer et nope, ça ne donne rien.

1|assistant  | [assistant] (2019-06-05 16:12:59) Commande reçue:  [ 'launch_"/usr/bin/pm2 restart mm"',
1|assistant  |   'notifier_{salon} Magic Mirror restart' ]
1|assistant  | [assistant] (2019-06-05 16:12:59) Appel du plugin 'launch'
1|assistant  | [assistant-launch] Lancement du programme : "/usr/bin/pm2 restart mm"
1|assistant  | [assistant] (2019-06-05 16:12:59) Appel du plugin 'notifier'
1|assistant  | [assistant-notifier] (salon) Lecture du message : Magic Mirror restart
Aymkdn commented 5 years ago

Cela utilise https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

Problème de droit peut-être ?

Tu peux modifier le fichier node_modules/assistant-launch/launch.js pour ajouter du log (après https://github.com/Aymkdn/assistant-launch/blob/3a08070f8971ffdf15bfae0e1fe0ec2d47dfcaf2/launch.js#L23) :

console.log("error => ",error);
console.log("stderr => ",stderr);
console.log("stdout => ",stdout);

Cela pourrait t'aider à trouver le problème.

Ybbet commented 5 years ago

Alors, oui en effet, avec les logs, on comprend mieux ce qui se passe. La commande suivant est envoyée telle quelle :

launch_"/usr/bin/pm2 restart mm"

Soit l'erreur :

1|assistant  | error =>  { Error: Command failed: "/usr/bin/pm2 restart mm"
1|assistant  | /bin/sh: 1: /usr/bin/pm2 restart mm: not found
1|assistant  |     at ChildProcess.exithandler (child_process.js:294:12)
1|assistant  |     at ChildProcess.emit (events.js:189:13)
1|assistant  |     at maybeClose (internal/child_process.js:970:16)
1|assistant  |     at Socket.stream.socket.on (internal/child_process.js:389:11)
1|assistant  |     at Socket.emit (events.js:189:13)
1|assistant  |     at Pipe._handle.close (net.js:600:12)
1|assistant  |   killed: false,
1|assistant  |   code: 127,
1|assistant  |   signal: null,
1|assistant  |   cmd: '"/usr/bin/pm2 restart mm"' }
1|assistant  | stderr =>  /bin/sh: 1: /usr/bin/pm2 restart mm: not found
1|assistant  | stdout =>  

J'ai essayé avec :

launch_/usr/bin/pm2 {{TextField}} mm

Et ça, ça marche.

Mais si on veut être compliant avec le child_process, on doit écrire ceci :

launch_"/usr/bin/pm2" {{TextField}} mm|notifier_{salon} Magic Mirror {{TextField}}

Ce qui rendra : launch_"/usr/bin/pm2" restart mm|notifier_{salon} Magic Mirror restart. On peut même tester avec juste pm2 à la place de /usr/bin/pm2.

Il faudrait peut-être ajouter l'info dans la documentation. ;-)