Tutorial
raspberrypi.org/magpi The Official Raspberry Pi Projects Book 119
AlexaPi
ifthisthenthat
The flow of information
for getting the
Alexabot to respond to
your command
default server on Port 80 come up. We will start our
server with the following command:
./ngrok http -subdomain=dexterindustries 5000
...where ‘dexterindustries’ is a reserved domain set
up with our basic account on ngrok. If you go with the
free account, you’ll now need to go back and re-enter
the domain name that ngrok gave your Pi into each of
your IFTTT commands.
Set up the Flask server
The final step in getting our Amazon Alexa-controlled
robot working is setting up the Flask server on
the Raspberry Pi.
We’ll set up a Flask server in Python to listen to
IFTTT. To install Flask on the Raspberry Pi, enter the
following into your command line:
sudo pip install flask
You can try running the Flask server we’ve
provided in our GitHub code and see what happens:
python alexabot-flask-app.py
You should see the Flask server start!
To get an idea of how the code works on the Flask
server, you can type the following in your web browser:
http://alexabot.ngrok.io/forward. You should get this
response in your browser: ‘Alexabot moved forward!’.
This illustrates how the Forward command works;
each command will work this way, with its own
directory and custom code for moving the GoPiGo.
Now, with all the services set up, we should be able
to say a command like “Alexa trigger forward”; Alexa
will alert IFTTT, which will send an HTTP message
through ngrok back to our GoPiGo and post to the
web server running in Flask. The Flask program will
command the GoPiGo to move forward.
The quick-start method to get running with
Alexabot is to first start AlexaPi:
sudo python /opt/AlexaPi/src/main.py
Next, start ngrok in a separate window:
sudo ~/ngrok/ngrok http
-subdomain=dexterindustries -log=stdout
5000 > log.txt &
Finally, start the Flask server:
sudo python alexabot-flask-app.py
Start talking! Remember, your commands need to
start with “Alexa trigger...” and then the command
you want the robot to carry out.
ALEXA POWERED ROBOT