Putting It All Together
I’ve now blogged about most of the pieces I needed for my morning greeter project. So now it’s time to write about putting it all together into a single, working solution.
Here’s a quick recap of the pieces so far:
- Raspberry Pi with Bluetooth USB Adapter
- Alexa Voice Service Client
- Text-to-Speech
- Custom Alexa Skills:
- Bluetooth Proximity Detection
Alexa Agent
To make it easier to send commands to Alexa, I wrote a simple agent class using Python with two main interface methods.
The agent will take care of TTS, sending the request to AVS, and playing back the response. The full code is available in my Github repository: alexa-agent
Alexa API
Next, I needed a way to connect triggers (e.g. bluetooth proximity detection) to Alexa commands. A flexible way for doing this is through a simple web service API that can be invoked via HTTP requests.
This can be done very quickly using Flask:
The above code, along with sample WSGI and Apache configuration files is available in my Github repository: alexa-agent-flask
Note: If you’re using custom Alexa skills, make sure to modify the list of commands with the appropriate intent phrases.
Bluetooth Scanner
The last piece is the bluetooth proximity detection trigger. I recently updated my bluetooth-proximity repository with a simple scanner script that can be modified for this purpose.
Simply replace the dummy_callback()
function with a function that will call the Flask API endpoint for the morning report. For example:
You can test if the bluetooth scanner is working by running the script manually (i.e. python bluetooth_scanner.py
). Once it’s working, you can set it up as a simple systemd
service using the steps below.
Systemd Service
-
Write a
systemd
service file namedbluetooth_scanner.service
[Unit] Description=Bluetooth Scanner [Service] Type=simple ExecStart=/usr/bin/bluetooth_scanner.py [Install] WantedBy=multi-user.target
- Copy the
bluetooth_scanner.py
script to/usr/bin/
- Copy the
bluetooth_scanner.service
file to/lib/systemd/system/
- Reload the
systemd
daemon using the commandsystemctl daemon-reload
- Start the bluetooth scanner service using the command:
systemctl start bluetooth_scanner.service
- Enable the service to auto-start with the system using the command:
systemctl enable bluetooth_scanner.service
That’s it! You should now have a bluetooth triggered morning report. I hope this series of blog posts has been helpful. Thanks for reading.