Skip to content

wvengen/phoniebox-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phoniebox Rust

This is a standalone program for creating a Phoniebox-like device: a digital music player that is controlled by physical action, like scanning an RFID card or barcode.

The existing solution felt too much like a collection of scripts, where configuration was needed in various places, and I needed to make changes to the system that I wasn't sure I wanted. This project is a very basic reimplementation as a single Rust-binary, with a single configuration file. Many features are missing, but it works great as a simple alternative.

The current build uses a Raspberry Pi Zero 2 W with the Codec Zero HAT (though the HAT is not needed if you only use a Bluetooth speaker).

Install

Requirements:

  • Small form-factor computer, e.g. Raspberry Pi Zero 2 W
  • USB Speaker, or audio out (e.g. Codec Zero HAT) + analog speaker
  • RFID reader, barcode scanner (or even just a numeric keypad)
    • Olimex RFID module (in serial mode),
    • PN532-based RFID modules (untested),
    • any device that acts like a keyboard, like a barcode scanner,
    • or you can implement a new input module.
  • RFID cards (when using an RFID reader).
  • Enclosure (not strictly necessary, but recommended).

See INSTALL for installation instructions for the Raspberry Pi Zero.

To add here: how to connect a Bluetooth speaker.

Configure

Copy config.example.toml to config.toml if you haven't done so before. This file contains all configuration. The sections are:

section [media]

This section has a single key path, which indicates where the music is located.

section [input.<name>]

Each input device (RFID reader, keyboard) has its own section, where <name> is something you can choose to indicate the input device. This means you can have, for example, multiple RFID readers, or an RFID reader and a barcode scanner.

The available input device types depend on the rust feature flags, but if they are all enabled, these are available:

  • evdev - generic keyboard device, like a keypad or a barcode scanner. The idea is one can enter a sequence of numbers and letters, ending with Enter to signify the sequence is ready (this is how may barcode scanners work).

  • olimexserial - Olimex RFID module in serial mode.

  • pn532serial - PN532-based device, over a serial interface (as of yet untested).

See the example configuration file for each input device type's available configuration.

section [actions]

This section has a single actions key, which contains a list of actions. Each action has an id indicating the RFID card ID (or sequence of numbers and letters) as its trigger, an action to perform, and any arguments to the action. The available actions are:

  • play - play music, with either the path argument, to indicate which file to play, or if it is a directory, to play all files in the directory; or it can have the url argument, which is either an http(s) URL to be played, or an RSS feed, where the first entry will be played (typically the last episode of a podcast).

  • exec - execute a command, with argument cmd to indicate the (shell) command.

There is one other way to add an action, namely: if you put a file card.txt in a subdirectory of the music directory (see section [media]), this directory will be played when the scanned id matches the contents of card.txt.

Use

Power on, and scan an RFID card or barcode.

Develop

This project can be developed as a regular Rust project on a Linux sytem: it uses general audio output, and can work with either the keyboard or a USB RFID reader.

To use the keyboard, enable the evdev device. You can find its path by listing the entries in /dev/input/by-path/, the keyboard usually ends with -kbd and may have i8042 in its name. You can test-read input device events with evtest, and see if it is the one you intend to use. Do not enable grab in the configuration with your general keyboard, it is meant for use with e.g. a dedicated barcode scanner.

First copy config.example.toml to config.toml, change it to your situation, and run with cargo run -- -c config.toml; terminate it with Ctrl-C.

To add here: concise overview of the source code.

License

To decide: either GPL-v3-or-later, or MIT. Need to check dependencies too. In any case, fine to use already (but not share yet).

About

Basic phoniebox alternative in Rust

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages