pmoscode / diy-media-player-box

Application to run on the DIY Media Player Box. This is a Golang app which serves the Admin UI and manages the NFC card trigger and the audio output. Communication is achieved via MQTT (mosquitto)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logo
GPLv3 License

DIY Media Player Box

This is a small application which turns any Raspberry Pi in a music box.

My target was to build a DIY Music Box for small children. (Like the Toniebox)

Features

  • Microservice architecture

  • Communicates via MQTT (mosquitto)

  • Simple UI for managing audiobooks

  • Audio upload / preview in UI

  • Simple new Rfid card discovery / management

  • Works on a Raspberry Pi Nano

  • Has "easy to set up" install script (Ansible and Taskfile)

  • Logs (almost) everything to log files

Architecture

This is a short overview of the architecture. All communication is done via the mqtt protocol.

graph LR;
    A(rfid-reader) -->|sends rfid id| C(controller)
    B(io-controller) -->|sends volume +/- and track +/-| C
    C --> |sends track metadata| D(audio-player)
    C --> |provides| E(UI)

    F(monitor) --> |checks and kills| G(rfid-reader / controller / io-controller / audio-player / logger)
    H(logger) --> |logs| I(rfid-reader / controller / io-controller / audio-player)

Screenshots

Main screen
New audio book
Audio book view
Audio book files

Installation

Preparation

You need:

You need to create a .env file in the root dir. (Copy .env.dist and adjust settings) The assumption is, that the default Raspbian user (pi) is used.

The content of that .env file:

REMOTE_SERVER=<ip_address_of_pi>
RASPBERRY_PASSWORD=<password_of_pi_user>

Configuration

Inside the folder "ansible/config" you will find the configuration of the single components. There you can make changes if desired.

For "io-controller" and "audio-player" you should adjust the values to your hardware setup…​

This config file will be sent to remote everytime you change the "backend" or can be copied via Taskfile task (See below: The Taskfile)

Before you start

I tested this on a Raspberry Pi Zero / Raspberry Pi 3 and the audio preview in the browser.

Note
You cannot compile the UI on a Raspberry Pi Zero due to lack of memory (512 MB) But everything will be done by the tasks…​ :)

Installation

The Taskfile

The Taskfile has everything you need to make it run on the Pi. Here are the tasks to accomplish this (or parts of it, when required):

Task name

Description

setup-target

If the Raspberry was freshly set up, use this to prepare the Pi for all compile tasks (install golang and some dev-dependencies)

compile-rfid-reader

Copy the rfid-reader folder to the raspi, compile it and copy the compiled artifact to the Pi’s home folder

compile-controller

Copy the controller folder to the raspi, compile it and copy the compiled artifact to the Pi’s home folder

compile-io-controller

Copy the io-controller folder to the raspi, compile it and copy the compiled artifact to the Pi’s home folder

compile-audio-player

Copy the audio-player folder to the raspi, compile it and copy the compiled artifact to the Pi’s home folder

compile-logger

Copy the logger folder to the raspi, compile it and copy the compiled artifact to the Pi’s home folder

compile-monitor

Copy the monitor folder to the raspi, compile it and copy the compiled artifact to the Pi’s home folder

compile-all

Execute the tasks "compile-all-backend", "compileUi" and "copyUi" at once

compile-all-backend

Execute the tasks "compile-rfid-reader", "compile-controller", "compile-io-controller", "compile-audio-player", "compile-logger" and "compile-monitor" at once

compile-ui

Build and package the UI and copy the result to the controller folder (into "ui" folder)

copy-ui

Copy the ui from controller folder to the raspi into the Pi’s home folder

Order of operation

To get everything work as expected, you only need to execute two tasks in the given order:

  • Call setupTarget once when you have a fresh Raspberry Pi set up (I assume you have the audio setup already done)

  • Call compileAll to compile all binaries (it may take some time on the raspi zero…​)

Example:

task setupTarget
task compileAll

Cron jobs on Raspi

The setupTarget task will also add commands to the cron file of the pi user:

  • to add a liveness probe, which checks if every component is still alive (every 5th minute)

  • to restart the monitor every 3rd hour

Documentation

The UI is that simple, that I assume, I don’t need to write any documentation for it.

If I’m wrong, let me know.

Contribution

Feel free to suggest new features and submit any pull requests. :)

Static code analyze

Static code analyze is not handled by the taskfile. It is done via:

https://staticcheck.io/docs/getting-started/

License

Authors

Appendix: Possible optimizations

Everything will be compiled on the Raspi, because te local compile is not working for some reason. I get a "Segmentation Fault" for controller and audio-player. Rfid-reader is working fine. And io-controller didn’t exist at that time.

The current state is located in the folder: local-compile

About

Application to run on the DIY Media Player Box. This is a Golang app which serves the Admin UI and manages the NFC card trigger and the audio output. Communication is achieved via MQTT (mosquitto)

License:GNU General Public License v3.0


Languages

Language:Go 58.5%Language:TypeScript 28.2%Language:HTML 5.1%Language:Shell 4.4%Language:JavaScript 1.6%Language:Sass 1.5%Language:Dockerfile 0.7%