Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Code notes

René Kliment edited this page Jan 15, 2017 · 6 revisions

A note on Shairport-sync

By default, shairport-sync (the airplay client) uses port 5000. This is no problem if everything goes as planned, but AlexaPi's authorization on sammachin's design uses port 5000 as well, and if shairport-sync is running while that happens, everything fails.

As a result, I have changed the authorization port for AlexaPi to 5050. Note that you will have to change the settings within the developer website for this to work.

How it works internally

The Amazon AVS credentials are stored in the configuration file called config.yaml which is used by auth_web.py and main.py, there is a template with blank values.

The auth_web.py is a simple web server to generate the refresh token via OAuth to the Amazon users account, it then fills this in the configuration file and displays it in the browser.

main.py is the 'main' Alexa client. It simply runs on a while True loop waiting either for the trigger word "Alexa," or for the button to be pressed. It then records audio and when the button is released it posts this to the AVS service using the requests library. When the response comes back it is played back using vlc.

The LEDs are a visual indicator of the status. Dual red/green LED can be used as well as separate LEDs. Red is connected to GPIO 24 and green to GPIO 25. When recording the red LED will be lit when the file is being posted and waiting for the response both LED's are lit (or in the case of a dual R?G LED it goes Yellow) and when the response is played only the green LED is lit. If the client gets an error back from AVS then the red LED will flash 3 times.