Georgetown’s MakerHub needs music. And a working doorbell. The most practical and simple approach is to build a Spotify streaming service that can be interrupted by an IoT doorbell. Tools for building this solution include:
- A Raspberry Pi 3 or 4
- Amplified speaker and cable
- Librespot & PulseAudio
- IoT doorbell based upon the ESP8266 MCU
- MQTT protocol using TCP on the MakerHub’s private network
The following instructions will help anyone with basic familiarity with Raspberry Pis, Linux, and hacking to debug or build from scratch the solution we’ve cobbled. It involves the following steps:
- Create a minimal Raspian OS on a MicroSD
- Put the RPi on the MakerHub private network
- Install packages to compile and install librespot
- Install PulseAudio and Sox
- Install packages to install MQTT
- Clone the Doorbell Git repository and configure the default settings in config.py
- Enable Librespot, PulseAudio, MQTT-listen to load on boot up
-
Create a Raspian LITE distribution (no desktop) following these instructions.
-
Using
sudo raspi-config, enablesshd()and configure wpa_supplicant to find the hidden private network called PILGRIMAGE_25. Access the ASUS router at 192.168.1.1 and add the MAC address of the RPi. Be sure to change to defaultpipassword fromraspberryto the MakerHub assigned password.
The /etc/wpa_supplicant/wpa_supplicant file should include the following, as a minimum:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
scan_ssid=1
ssid="PILGRIMAGE_25"
key_mgmt=NONE
}
-
Fetch packages for compiling and install librespot Install
gitvia:pi@raspberrypi:~/iot_doorbell $ sudo apt install git
Install rust & C compilers to install librespot following instructions on this page. Compile using the pulseaudio-backend and not the default ALSA:
pi@raspberrypi:~ $ sudo apt-get install libpulse-dev
pi@raspberrypi:~ $ git clone https://github.com/librespot-org/librespot.git
pi@raspberrypi:~ $ cargo build --no-default-features --features "pulseaudio-backend"</code>
-
Install pulseaudio & sox for audio playback via:
pi@raspberrypi:home/pi/iot_doorbell $ sudo apt-get install pulseaudio pi@raspberrypi:~/iot_doorbell $ sudo apt-get install sox libsox-fmt-mp3</code> -
Install pip3 and paho-mqtt via:
pi@raspberrypi:~/iot_doorbell $ sudo apt-get install python3-pip pi@raspberrypi:~/iot_doorbell $ pip3 install paho-mqtt -
Install MakerHub bits from git:
pi@raspberrypi:~/iot_doorbell $ git clone https://github.com/GeorgetownMakerHubOrg/iot_doorbell.git
You will also need to replace the dummy values for USER, X_AIO_KEY, MQTT_PASSWORD, and MQTT_SUB_TOPIC with real values.
- Since librespot and mqtt-listen will run as a user process, configure both librespot and mqtt-listen to start as a ‘pi’ process on bootup:
-
Using the
raspi-configtool, select “1 System Options-> S5 Boot / Auto Login->B2 Console Autologin Text consoleto have the RPi automatically log in as ‘pi’ user on bootup. -
Copy the librespot.service file from the iot_doorbell distribution to the user system control directory. Enable this service and start this service:
pi@raspberrypi:~/iot_doorbell $ sudo cp librespot.service /lib/systemd/user pi@raspberrypi:~/iot_doorbell $ sudo cp mqtt-listen.service /lib/systemd/user pi@raspberrypi:~/iot_doorbell $ systemctl --user enable librespot.service pi@raspberrypi:~/iot_doorbell $ systemctl --user enable mqtt-listen.service
-
The doorbell uses the following components:
- D1 Mini Wemos ESP8266
- Single Neopixel for Status
- Simple push button
3D Printed a very nice case from Thingiverse. It looks like this.