A lightweight microservice that manages audio hardware configuration on a Raspberry Pi for the Beatnik Audio System.
This service allows you to configure Audio HATs (like HiFiBerry DACs/Amps) via a simple HTTP API. It automatically handles:
- System Overlays: Adjusting
/boot/firmware/config.txt(or/boot/config.txt) to load the correct drivers. - Audio Engine Routing: Adjusting
/etc/camilladsp/default.ymlso CamillaDSP uses the correct output device. - Hardware Detection: Automatically reading HAT EEPROMs to identify connected hardware.
Before you begin, ensure the following software is installed on your Raspberry Pi:
- Raspberry Pi OS (Bookworm or newer recommended)
- Node.js (Version 18 or newer)
- Root Privileges (
sudo), as system files need to be edited.
We recommend installation via nvm (Node Version Manager) as it offers more flexibility than system packages.
Install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrcInstall Node.js:
nvm install 20
nvm use 20You can install the entire service (including Node.js, dependencies, and systemd setup) with a single script.
wget https://raw.githubusercontent.com/byrdsandbytes/beatnik-hardware-api/master/setup.sh
chmod +x setup.sh
./setup.shFollow the prompts on the screen. The script will ask for your sudo password to install the system service.
If you prefer to install everything manually, follow these steps:
We recommend installing in the /opt/ directory.
cd /opt
sudo git clone https://github.com/byrdsandbytes/beatnik-hardware-api.git
cd beatnik-hardware-apiSince we are using nvm, run npm without sudo.
npm installnpm run buildIf you didn't use the setup script:
sudo cp beatnik-hardware.service /etc/systemd/system/Important: Adjust the ExecStart path in /etc/systemd/system/beatnik-hardware.service to point to your Node.js executable (find it with which node).
sudo systemctl daemon-reload
sudo systemctl enable beatnik-hardware.service
sudo systemctl start beatnik-hardware.servicesudo systemctl status beatnik-hardware.serviceIf everything is green (active (running)), the server is running on port 3000.
You can test the service directly from the Pi or from another computer on the network.
Shows the currently configured card and (if present) the automatically detected hardware.
curl http://localhost:3000/api/hardware/statusExample Response:
{
"currentConfig": { "id": "none", "name": "No HAT..." },
"detectedHardware": { "id": "hifiberry-amp", "name": "HiFiBerry Amp2..." },
"isMatch": false
}curl http://localhost:3000/api/hardware/hatsThis rewrites config.txt and camilladsp.yml.
curl -X POST http://localhost:3000/api/hardware/apply \
-H "Content-Type: application/json" \
-d '{"hatId": "hifiberry-amp"}'Response:
{
"status": "success",
"message": "Configuration applied. Reboot required.",
"rebootRequired": true
}A reboot is required to make changes to config.txt effective.
curl -X POST http://localhost:3000/api/hardware/rebootYou can test the service on your laptop without a Pi. The service uses environment variables to override paths to system files.
Create dummy files for testing:
touch test-config.txt
touch test-camilla.ymlStart the server in dev mode with environment variables:
# Linux / Mac
CONFIG_PATH=./test-config.txt CAMILLA_CONFIG_PATH=./test-camilla.yml npm run devThe server is now running and writes changes to your local test files instead of /boot/config.txt.
- Overwriting Configurations: This service overwrites parts of
/boot/firmware/config.txtand/etc/camilladsp/default.yml. Manual changes to audio settings in these files may be lost. - Backup: The service tries to be "gentle", but it is always advisable to have backups of your working configuration files.