4

I've installed AlexaPi onto my Pi 3 running Debian. I currently have to open 3 terminal tabs and run 3 commands to start Alexa. I'm trying to create a start up file so these load on boot.

I've tried following the feedback from this question. But I'm not sure how to write the commands in the file.

The commands I'm trying to run are:

~TAB1-Run Listen Script~

 cd ~/Desktop/alexa-avs-sample-app/samples 
 cd companionService && npm start

~TAB2-Initiate Alexa Script~

cd ~/Desktop/alexa-avs-sample-app/samples
cd javaclient && mvn exec:exec

~TAB3-Run Wake Word~

cd ~/Desktop/alexa-avs-sample-app/samples
cd wakeWordAgent/src && ./wakeWordAgent -e sensory

If someone is able to explain or provide a script on how to achieve this it will be greatly appreciated as I'm trying to learn.

Many thanks

Andy

Andy14
  • 41
  • 1
  • 5
  • @Darth Vader, Thank you for the edit, reads much better cheers – Andy14 May 20 '17 at 09:48
  • Are these actually GUI apps? If so, why do you want to run them from a terminal window? If not, why do want to run them at boot in a terminal window? Either way, this is smells of wrong. Someone else was here a few days ago asking about pretty much the same thing, and it seems confused to me -- but then I have never used Alexa. – goldilocks May 20 '17 at 13:46
  • @goldilocks: Ok I did forget to mention that I'm running a magic mirror app. This means when I boot my raspberry PI 3 up the magic mirror app opens on boot. The reason I want AlexaPi app to load on boot is my wife wants to power the PI 3 (her smart mirror) up and it loads magic mirror and Alexa so she has no messing around. She has NO computer skills trust me, she had her mobile phone upside down and wondered why she couldn't her anyone lol.

    And no these app have no GUI you have to run the commands to open them (I believe until i'm told wrong).

    – Andy14 May 20 '17 at 17:22
  • Why you want to start them at boot is not what I asked -- it doesn't matter why. What I asked was why you wanted to run them from a terminal window if they aren't actually GUI apps. I suspect they are not, unless one presents something to do with the magic mirror, but even then, there is no reason to need to start it from a GUI terminal. Which is the flip side of the question...my basic point is it is hard to see a reason to run commands you want to start at boot from a GUI terminal, period. Do you think these are the only commands run at boot? – goldilocks May 21 '17 at 13:39
  • ...Do you think other such processes are started by launching a GUI terminal and then executing from there? There is no reason for that. If you understand what I am getting at, you should make clear to non- Alexa users, and people who don't know you are making a magic mirror, exactly what is going on. From the looks of things, if you wait for another Alexa user to help you with this here you may be waiting a long time, but if you added those details, likely someone else might be able to, because almost certainly there is a more general case of what you want to do. – goldilocks May 21 '17 at 13:39
  • @goldilocks: I think the OP may not realize how to run commands in the background which is why they are being executed from three different terminals. – Daddy the Runner May 22 '17 at 01:18
  • @Andy14: It looks like you should be able to execute all three commands from a single terminal if you put an ampersand (&) at the end of the second line in the examples you provided. For example cd companionService && npm start &. If that works, then you need to create a shell script with the commands and have the PI execute the shell script on startup. – Daddy the Runner May 22 '17 at 01:23
  • @DaddytheRunner Yes, I suspect something like that as well which is why I am prodding ;) Unless there is something special going on, most likely this could all be done in one (straight to background, no terminal required) script. Which then begs the question why this odd meme seems to have been replayed here by several Alexa users...it would not be the first time someone's inexpert blog has led people down the garden path. – goldilocks May 22 '17 at 17:29

1 Answers1

2

Based on the information you have provided. I recommend you try the following steps:

  1. Execute the following commands in a single terminal window:

    cd ~Desktop/alexa-avs-sample-app/samples/companionService
    npm start &
    cd ~/Desktop/alexa-avs-sample-app/samples/javaclient
    mvn exec:exec &
    cd ~/Desktop/alexa-avs-sample-app/samples/wakeWordAgent/src
    ./wakeWordAgent -e sensory &
    
  2. If step one works. Then create the following script file using your favorite text editor (e.g. nano, vi, geany, are some options):

    #!/usr/bin/sh
    cd ~Desktop/alexa-avs-sample-app/samples/companionService
    npm start &
    cd ~/Desktop/alexa-avs-sample-app/samples/javaclient
    mvn exec:exec &
    cd ~/Desktop/alexa-avs-sample-app/samples/wakeWordAgent/src
    ./wakeWordAgent -e sensory &
    
  3. Now follow the instructions in the Execute script on start-up question and you should be good to go.

Here are some more details explaining what each step above is doing:

  1. Step one is testing the assumption that all three commands can be executed in the background. It also combined and simplified the change director commands (cd) into a single cd command. There is no reason to visit the parent directories on the way to the final destination. The ampersand at the end of the commands tells linux to execute the commands in the background and not wait for the program to end before doing the next task. This is very important when creating scripts to be run at startup. Otherwise the startup process could get stalled waiting for a program to end that won't.

  2. In the second step we create what is called a script file. The first line tells the linux operating system which language to use to understand the script. In this case, we are using sh which is the program used to run commands from a terminal window.

    If you need help learning how to write commands into a script file, try searching for tutorials on the various text editors. Here is one for the nano editor: http://www.raspberrypi-spy.co.uk/2013/11/quick-guide-to-nano-text-editor-on-the-raspberry-pi/

  3. The third step provides information on having the RPi run your script on startup.

Daddy the Runner
  • 391
  • 2
  • 10
  • Hi @Daddy the Runner. First of all thank you for taking the time to help me provide a solution. Unfortunately, these commands need to be run in different terminal tabs. Reading the documentation https://github.com/alexa-pi/AlexaPi/blob/master/README.md , the first tab listens for a response from the second tab which provides a key for authentication from my Amazon Developer account. The 3rd tab is to initiate the wake word "Alexa" instead of pressing a button. – Andy14 May 24 '17 at 05:54
  • I did however, using your step above created 3 different startup files to load one after another (which essentially I'm doing manually entering them in different tabs). This didn't work though. As I'm new to this and still learning I don't think it's possible to do it this way. – Andy14 May 24 '17 at 05:54
  • After researching a bit more I did find this post (https://github.com/alexa-pi/AlexaPi/issues/162), which explains about 2 different setups of the program. One being manual (one I'm using I believe) and one that installs the app as a service, which can be run with one simple command. 'sudo systemctl start AlexaPi' which is simple to start on boot (apparently)

    Think next step would to re-install the app following the documentation exactly for the auto service of AlexPi instead of some YouTube tutorial which doesn't explain everything (which I followed sigh).

    Thank you @Daddy the Runner

    – Andy14 May 24 '17 at 05:54