loudnessspy project for audio calculating RMS, and publishing to MQTT.
Find a file
2025-09-01 22:19:21 +02:00
.vscode Initial commit for loudnessspy project with audio recording and MQTT integration. Added Cargo.toml for dependencies, workspace configuration, and main application logic for capturing audio input, calculating RMS, and publishing to MQTT. 2025-08-29 21:17:51 +02:00
src Refactor audio input handling to use ALSA instead of CPAL, improving device management and sample capture 2025-09-01 22:19:21 +02:00
.gitignore Initial commit for loudnessspy project with audio recording and MQTT integration. Added Cargo.toml for dependencies, workspace configuration, and main application logic for capturing audio input, calculating RMS, and publishing to MQTT. 2025-08-29 21:17:51 +02:00
Cargo.toml Refactor audio input handling to use ALSA instead of CPAL, improving device management and sample capture 2025-09-01 22:19:21 +02:00
loudnessspy.code-workspace Initial commit for loudnessspy project with audio recording and MQTT integration. Added Cargo.toml for dependencies, workspace configuration, and main application logic for capturing audio input, calculating RMS, and publishing to MQTT. 2025-08-29 21:17:51 +02:00
Readme.md Improve error message for MQTT timeout to include host and port details 2025-08-30 16:38:36 +02:00

loudnessspy

Ein Rust-Programm für den Raspberry Pi, das kontinuierlich die Lautstärke (RMS) des ersten verfügbaren Mikrofons misst und alle 2 Sekunden per MQTT an einen Server sendet.

Features

  • Durchgehende Aufnahme des ersten (USB-)Mikrofons
  • Alle 2 Sekunden Berechnung der mittleren Lautstärke (RMS)
  • Versand der Werte als JSON per MQTT (mit Username/Passwort)
  • Robuster Betrieb: Reconnect bei Netzwerkproblemen, Timeout beim Senden

Konfiguration

Die Datei config.toml im Projektverzeichnis steuert die Verbindung:

host = "localhost"
port = 1883
username = "user"
password = "pass"
client_id = "loudnessspy"
topic = "loudnesspy/volume"

Kompilieren für Raspberry Pi 1 (32 Bit)

  1. Rust-Target installieren:
    rustup target add arm-unknown-linux-gnueabihf
    
  2. Cross-Compiler und ARM-ALSA-Entwicklerdateien installieren:
    sudo apt-get install gcc-arm-linux-gnueabihf libasound2-dev:armhf pkg-config-arm-linux-gnueabihf
    
  3. Umgebungsvariablen setzen:
    export PKG_CONFIG_SYSROOT_DIR=/usr/arm-linux-gnueabihf
    export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig
    export PKG_CONFIG=arm-linux-gnueabihf-pkg-config
    
  4. Bauen:
    cargo build --release --target=arm-unknown-linux-gnueabihf
    

MQTT-Format

Alle 2 Sekunden wird ein JSON wie folgt gesendet:

{"rms":0.0123}

Hinweise

  • Das Programm sucht bevorzugt nach USB-Mikrofonen, nutzt sonst das Standardgerät.
  • Bei fehlender Verbindung wird automatisch reconnectet.
  • Fehler beim Senden werden geloggt, blockieren aber nicht den Hauptloop.

Autostart

sudo apt install tmux

nano ~/bashrc

Am Ende hinzufügen

if ! tmux has-session -t loudnessspy 2>/dev/null; then
    tmux new-session -d -s loudnessspy '~/loudnessspy'
fi

tmux Pane Control

tmux attach

Ctrl b, " Split pane horizontally
Ctrl b, % Split pane vertically
Ctrl b, o Next pane


Autor: Leonhard Suckau Lizenz: AGPL