From f002f7a1408cebb5fbdfa6a98c271608f5ff1bf9 Mon Sep 17 00:00:00 2001 From: Boaz Sender Date: Tue, 1 Apr 2025 17:52:06 -0700 Subject: [PATCH] automate broadcaster setup --- docs/listener.md | 64 +++++++++++++++--------- installation/broadcaster/darkice.cfg | 24 +++++++++ installation/broadcaster/darkice.service | 11 ++++ installation/broadcaster/install.sh | 37 ++++++++++++++ installation/broadcaster/readme.md | 37 ++++++++++++++ installation/listener/install.sh | 51 +++++++++++++++++++ installation/listener/player.service | 12 +++++ installation/listener/screen.service | 12 +++++ package.json | 3 +- 9 files changed, 225 insertions(+), 26 deletions(-) create mode 100644 installation/broadcaster/darkice.cfg create mode 100644 installation/broadcaster/darkice.service create mode 100644 installation/broadcaster/install.sh create mode 100644 installation/broadcaster/readme.md create mode 100644 installation/listener/install.sh create mode 100644 installation/listener/player.service create mode 100644 installation/listener/screen.service diff --git a/docs/listener.md b/docs/listener.md index 37d641c..6263b08 100644 --- a/docs/listener.md +++ b/docs/listener.md @@ -1,57 +1,69 @@ # Listener software (Mplayer + drivers) + ## Summary + User: grace Hostname: listener.local Password: emergence Running mplayer, soundcard library, lcd graphics library, and custom python code for text printing logic. ## Bill of Materials -* Raspberry pi zero wh - https://www.waveshare.com/product/raspberry-pi/boards-kits/raspberry-pi-zero-2-w-cat/raspberry-pi-zero-2-w.htm?sku=21038 -* Waveshare UPS with 1000mah battery - https://www.waveshare.com/ups-hat-c.htm -* Waveshare sound card hat with speakers- https://www.waveshare.com/wm8960-audio-hat.htm -* 1602 LCD screen - https://www.waveshare.com/lcd1602-i2c-module-blue.htm?sku=30496 -* Jumper wires - https://www.waveshare.com/product/accessories/adapters-cables-antennas/jumper-wires/jumper-wire-1-pin-2.54-pitch-200mm.htm -* mini HDMI to hdmi cable - https://hosatech.com/products/video/hdmi/hdmc-400/ -* micro USB male to usb a femail adapter - https://www.amazon.com/dp/B01C6032G0 -* Keyboard with usb a cable - https://www.amazon.com/AmazonBasics-Matte-Keyboard-QWERTY-Layout/dp/B07WJ5D3H4/ + +- Raspberry pi zero wh - https://www.waveshare.com/product/raspberry-pi/boards-kits/raspberry-pi-zero-2-w-cat/raspberry-pi-zero-2-w.htm?sku=21038 +- Waveshare UPS with 1000mah battery - https://www.waveshare.com/ups-hat-c.htm +- Waveshare sound card hat with speakers- https://www.waveshare.com/wm8960-audio-hat.htm +- 1602 LCD screen - https://www.waveshare.com/lcd1602-i2c-module-blue.htm?sku=30496 +- Jumper wires - https://www.waveshare.com/product/accessories/adapters-cables-antennas/jumper-wires/jumper-wire-1-pin-2.54-pitch-200mm.htm +- mini HDMI to hdmi cable - https://hosatech.com/products/video/hdmi/hdmc-400/ +- micro USB male to usb a femail adapter - https://www.amazon.com/dp/B01C6032G0 +- Keyboard with usb a cable - https://www.amazon.com/AmazonBasics-Matte-Keyboard-QWERTY-Layout/dp/B07WJ5D3H4/ ## Hardware assembly -* Solder header to the pi if not pre-soldered -* Plug the battery into the UPS board -* Screw the UPS to the pi -* Screw a next level of standoffs to the pi -* Put the audio hat on the pi's headers, and screw it to the standoffs -* Plug in the speakers -* Plug the jumper wires into the screen and the pi according to the [screen-wiring.png](screen-wiring.png) file (via https://peppe8o.com/1602-lcd-raspberry-pi-display/). + +- Solder header to the pi if not pre-soldered +- Plug the battery into the UPS board +- Screw the UPS to the pi +- Screw a next level of standoffs to the pi +- Put the audio hat on the pi's headers, and screw it to the standoffs +- Plug in the speakers +- Plug the jumper wires into the screen and the pi according to the [screen-wiring.png](screen-wiring.png) file (via https://peppe8o.com/1602-lcd-raspberry-pi-display/). ## Pre work + 1. install raspian lite 64 for raspi zero 2. configure user and wifi and turn on ssh services when you install 3. boot 4. find the ip address of the pi and ssh to it ## Setup instructions + ### Creature comforts + 1. sudo apt update && install git vim zsh 2. sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ### Install Waveshare soud card drivers + #### Install drivers + Following instructions instructions at https://www.waveshare.com/wiki/WM8960_Audio_HAT 1. git clone https://github.com/waveshare/WM8960-Audio-HAT 2. cd WM8960-Audio-HAT -3. sudo ./install.sh +3. sudo ./install.sh 4. sudo reboot -5. sudo dkms status +5. sudo dkms status 6. Check the output of dkms to confirm that drivers installed correctly 7. sudo apt install mplayer #### Test radio + mplayer -playlist http://blackportaldetroit.com:1313/portal.m3u #### Daemonize radio -sudo vim /lib/systemd/system/listener.service + +sudo vim /lib/systemd/system/player.service + ``` [Unit] Description=Listenign Service @@ -68,19 +80,20 @@ WantedBy=multi-user.target ``` sudo systemctl daemon-reload -sudo systemctl enable listener +sudo systemctl enable player sudo reboot #### Raise volume -alsamixer + +alsamixer sudo alsactl store ### LCD screen and sound processing logic + Install software from this repo - -1. sudo raspi-config +1. sudo raspi-config 2. enable i2c in interface options 3. i2cdetect -y 1 4. confirm that i2cdetect tells you the address 27. @@ -89,10 +102,11 @@ Install software from this repo 6. volta install node 7. git clone git@git.featherboaz.com:boazsender/portal.git -8. cd portal && npm install +8. cd portal && npm install 9. npx prisma generate && npx prisma db push && npx prisma db seed 10. sudo vim /lib/systemd/system/screen.service + ``` [Unit] Description=Screen Service @@ -107,6 +121,6 @@ ExecStart=/home/grace/.volta/bin/node /home/grace/portal/build/screen.js [Install] WantedBy=multi-user.target ``` -11. sudo systemctl daemon-reload -12. sudo systemctl enable listener +11. sudo systemctl daemon-reload +12. sudo systemctl enable screen diff --git a/installation/broadcaster/darkice.cfg b/installation/broadcaster/darkice.cfg new file mode 100644 index 0000000..2b529ad --- /dev/null +++ b/installation/broadcaster/darkice.cfg @@ -0,0 +1,24 @@ +[general] +duration = 0 # Stream indefinitely +bufferSecs = 5 # Buffer for the input, in seconds +reconnect = yes # Reconnect to the server if disconnected + +[input] +device = plughw:1,0 # Your audio capture device +sampleRate = 44100 +bitsPerSample = 16 # Bits per sample +channel = 1 # 2 = stereo, 1 = mono + +[icecast2-0] +bitrateMode = cbr # Constant bit rate +format = mp3 # Audio format +bitrate = 128 # Bitrate in kbps +server = localhost # Server name or IP +port = 8000 # Port number +password=emergence # Your Icecast password +mountPoint = portal # Mount point to stream to +name = Black Portal # Name of the stream +description = Black Portal Project # Description of the stream +url = http://blackportaldetroit.com # URL related to the stream +genre = politics # Genre of the stream +public = no # Do not list on public lists diff --git a/installation/broadcaster/darkice.service b/installation/broadcaster/darkice.service new file mode 100644 index 0000000..95b725b --- /dev/null +++ b/installation/broadcaster/darkice.service @@ -0,0 +1,11 @@ +[Unit] +Description=Darkice Service +[Service] +User=root +Type=simple +Restart=on-failure +RestartSec=5 +WorkingDirectory=/home/grace +ExecStart=/usr/bin/darkice -c /etc/darkice.cfg +[Install] +WantedBy=multi-user.target diff --git a/installation/broadcaster/install.sh b/installation/broadcaster/install.sh new file mode 100644 index 0000000..922d584 --- /dev/null +++ b/installation/broadcaster/install.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root (use sudo)" 1>&2 + exit 1 +fi + +is_Raspberry=$(cat /proc/device-tree/model | awk '{print $1}') +if [ "x${is_Raspberry}" != "xRaspberry" ] ; then + echo "Sorry, this only works on raspberry pi" + exit 1 +fi + +ver="1.0" + + +# we create a dir with this version to ensure that 'dkms remove' won't delete +# the sources during kernel updates +marker="0.0.0" + +apt update +apt -y install git vim zsh darkice icecast2 + + +cp ./darkice.cfg /etc/ +cp ./darkice.service /lib/systemd/system/ + +systemctl daemon-reload +systemctl enable darkice +systemctl start darkice + +sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" + +echo "------------------------------------------------------" +echo "The Black Portal broadcasting device has been provisioned." +echo "Reboot this raspberry pi now in order for things to work" +echo "------------------------------------------------------" \ No newline at end of file diff --git a/installation/broadcaster/readme.md b/installation/broadcaster/readme.md new file mode 100644 index 0000000..0308e4f --- /dev/null +++ b/installation/broadcaster/readme.md @@ -0,0 +1,37 @@ +# Broadcaster Software (icecast and darkice) + +## Summary + +User: grace +Hostname: portal.local +Password: emergence +Running icecast and darkice. See icecast-darkice.md for setup instructions. + +## Bill of Materials + +- Raspberry pi 4b (1 gig ram) - https://www.sparkfun.com/raspberry-pi-4-model-b-1gb.html +- 3 x USB to XLR sound card cable - https://www.amazon.com/dp/B089WFYZ5R?ref=ppx_yo2ov_dt_b_fed_asin_title&th=1 +- 3 x XLR microphones - +- Raspberry pi 4 Power supply - https://www.waveshare.com/pi-psu-us-w.htm +- ethernet cable - https://hosatech.com/products/data/network-cable/cat-500/ +- micro hdmi to regular hdmi cable- https://www.waveshare.com/pi-official-micro-hdmi-cable-1m.htm + +## Hardware setup + +- Plug the mic into the the usb cable +- Plug the usb cable into the pi +- Plug the pi into the wall + +## Pre work + +1. install raspian lite 64 for raspi model 4b +2. configure user and wifi and turn on ssh services when you install +3. boot +4. find the ip address of the pi and ssh to it + +## Setup instructions + +npm run deploy:broadcaster +ssh grace@broadcaster.local +cd portal/broadcaster +sudo ./install.sh diff --git a/installation/listener/install.sh b/installation/listener/install.sh new file mode 100644 index 0000000..32268a2 --- /dev/null +++ b/installation/listener/install.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root (use sudo)" 1>&2 + exit 1 +fi + +is_Raspberry=$(cat /proc/device-tree/model | awk '{print $1}') +if [ "x${is_Raspberry}" != "xRaspberry" ] ; then + echo "Sorry, this only works on raspberry pi" + exit 1 +fi + +ver="1.0" + + +# we create a dir with this version to ensure that 'dkms remove' won't delete +# the sources during kernel updates +marker="0.0.0" + +apt update +apt -y install git vim zsh mplayer + +sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" + +curl https://get.volta.sh | bash +volta install node +git clone git@git.featherboaz.com:boazsender/portal.git +cd portal +npm install +npx prisma generate && npx prisma db push && npx prisma db seed +cp ./screen.service /lib/systemd/system/ + +cp player.service /lib/systemd/system/ + +git clone https://github.com/waveshare/WM8960-Audio-HAT +cd WM8960-Audio-HAT +sh ./install.sh + +systemctl daemon-reload +systemctl enable player +systemctl enable screen +systemctl enable wm8960-soundcard.service +systemctl start player +systemctl start screen +systemctl start wm8960-soundcard + +echo "------------------------------------------------------" +echo "The Black Portal listening device has been provisioned." +echo "Reboot this raspberry pi now in order for things to work" +echo "------------------------------------------------------" \ No newline at end of file diff --git a/installation/listener/player.service b/installation/listener/player.service new file mode 100644 index 0000000..e606891 --- /dev/null +++ b/installation/listener/player.service @@ -0,0 +1,12 @@ +[Unit] +Description=Listenign Service +[Service] +User=root +Type=simple +Restart=on-failure +RestartSec=5 +WorkingDirectory=/home/grace +ExecStart=mplayer -playlist http://blackportaldetroit.com/portal.m3u + +[Install] +WantedBy=multi-user.target diff --git a/installation/listener/screen.service b/installation/listener/screen.service new file mode 100644 index 0000000..a5e3b73 --- /dev/null +++ b/installation/listener/screen.service @@ -0,0 +1,12 @@ +[Unit] +Description=Screen Service +[Service] +User=root +Type=simple +Restart=on-failure +RestartSec=5 +WorkingDirectory=/home/grace +ExecStart=/home/grace/.volta/bin/node /home/grace/portal/build/screen.js + +[Install] +WantedBy=multi-user.target diff --git a/package.json b/package.json index c0efd48..fec0392 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "main": "index.js", "scripts": { "build": "tsc", - "deploy": "npm run build && rsync -avx rsync -a --exclude-from='exclude.txt' ./ grace@listener.local:portal" + "deploy:broadcaster": "rsync -avx rsync -a --exclude-from='exclude.txt' ./ grace@broadcaster.local:portal", + "deploy:listener": "npm run build && rsync -avx rsync -a --exclude-from='exclude.txt' ./ grace@listener.local:portal" }, "repository": { "type": "git",