Turning the Hub into an Internet Radio

Update

Main window of LuCI web interface for OpenWRT

Main window of LuCI web interface for OpenWRT

There is a saying: “There was no sadness, just updates.” This is exactly about OpenLumi. The peculiarity of the device is that it has very little RAM and permanent memory – 256 MB each. After the update, I tried to roll out HA, and it even worked. But the first attempt to install additional integrations was unsuccessful – the memory ran out.

It became clear that if you install HA on it, you will first need to re-solder the flash memory chip, taking it from some old DDR2 bar. Again, the hardware is weak for HA, although it has a full set of wireless interfaces necessary for it. So I temporarily decided to turn the gateway into an Internet radio, which could be plugged into a socket in the kitchen and listen to your favorite Internet radio stations.

Software

There are many ways to play music on Linux, but for OpenWRT the easiest way is to choose an application MPD (Music Player Daemon). This is a cross-platform application with a client-server architecture that allows you to play music files from a specific directory. In addition, MPD has support for streaming audio playback, which makes it an ideal option for working as an Internet radio receiver.

There are many different clients to command the MPD daemon. But for our purposes the simplest one will suffice – MPC (Music Player Client). This is a minimalistic CLI that allows you to issue commands to the daemon, such as starting or stopping playback. But before installing and configuring both of these applications, I suggest taking a look at the gateway's audio device configuration:

# aplay -l
**** List of PLAYBACK Hardware Devices **** 
card 0: tfa9882audio [tfa9882-audio], device 0: 2028000.sai-tfa9882-hifi tfa9882-hifi-0 [2028000.sai-tfa9882-hifi tfa9882-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Here we are dealing with ALSA. We have one sound card available tfa9882audio. Let's open alsamixer and set Master volume to medium level:

# alsamixer

Now let's download some test sound:

# wget https://www2.cs.uic.edu/~i101/SoundFiles/StarWars60.wav

Let's try to reproduce it:

# aplay -D default StarWars60.wav
Playing WAVE 'StarWars60.wav' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono

The Star Wars theme song plays from the gateway speaker, which means ALSA is functioning correctly and we can proceed with installing MPD. First, let's update the package list:

# opkg update

Install the mpd-full and mpc packages:

# opkg install mpd-full mpc

Let's launch the daemon to check:

# mpd
server_socket: bind to '0.0.0.0:6600' failed (continuing anyway, because binding to '[::]:6600' succeeded): Failed to bind socket: Address in use
output: No 'audio_output' defined in config file
output: Successfully detected a alsa audio device

In the next SSH session we call the client, without parameters for now:

# mpc
volume: n/a   repeat: off   random: off   single: off   consume: off

The connection is successful, but nothing is playing yet. Our task is to play streaming internet radio, so we find the address of the stream (for example, Comedy Radio) and add it to the mpd playlist:

# mpc add https://pub0102.101.ru:8000/stream/air/aac/64/202

Let's start playback:

# mpc play
https://pub0102.101.ru:8000/stream/air/aac/64/202
[playing] #1/1   0:00/0:00 (0%)
volume: n/a   repeat: off   random: off   single: off   consume: off

And now our Internet radio is already playing from the gateway speaker. You can increase the volume either via alsamixer or directly from mpc:

# mpc volume 100
MPD error: Failed to set mixer for 'default detected output'; no such mixer control: PCM

Oops! It seems that the sound card autodetection thinks that our mixer is called PCM, but it is registered in the system as Master. For ease of editing configs, we install the Nano text editor:

# opkg install nano

Stop playback:

# mpc stop

And in another SSH session, stop MPD via Ctrl + C. Open the mpd config for editing:

# nano /etc/mpd.conf

In the Audio Output section, uncomment the section and bring it to the following form:

audio_output {
        type            "alsa"
        name            "My ALSA Device"
        device          "hw:0,0"
        mixer_type      "software"
        mixer_device    "default"
        mixer_control   "Master"
        mixer_index     "0"
}

Save the file and exit the editor: Ctrl + X and Y when asked to save changes. Confirm with Enter. Launch mpd in one session and playback with mpc in another session, after first executing the playlist clear command and re-adding the stream link:

# mpc clear
# mpc add https://pub0102.101.ru:8000/stream/air/aac/64/202
# mpc play

And now, when we call the volume change via mpc, everything works correctly:

# mpc volume 100

Autostart

The biggest problem you might encounter is the daemon's permissions. OpenLumi uses an old-fashioned init system, so first stop the daemon if it's running:

# /etc/init.d/mpd stop

Now let's edit the mpd launch config:

# nano /etc/init.d/mpd

We specify that the daemon must be launched as root, otherwise it will not be able to gain access to open the ALSA device:

USER="root"
GROUP="root"

Save the file and exit.

# nano /etc/rc.local

Insert the following content before the line exit 0:

sleep 5
mpc clear
mpc volume 80
mpc add https://pub0102.101.ru:8000/stream/air/aac/64/202
mpc play

Save the config and exit the nano editor. Since sometimes the system may not start the thread, referring to the fact that it cannot resolve the domain, we set a sleep 5 delay before starting. This small pause helps to wait until the network connection is fully established.

Now we boldly pull the power supply gate – after 70 seconds Comedy Radio turns on automatically. Exactly what was required.

Results

The reader will probably be outraged: you can't run anything from root, it's not secure and generally bad. If you follow all the rules, you must create a separate user. Then add it to the audio group and give it rights to a specially allocated directory, where mpd will store its current state and the generated playlist, for example. But this will take much longer. You will spend at least a couple of hours figuring out at what stage you don't have enough access rights and in what config what to edit.

In addition to mpc, you can come up with many interesting things. For example, there are MPD clients that raise a small web server and allow you to conveniently manage playlists and tracks. In general, you can easily mount a network share in the system and control playback from a mobile device. But that's a completely different story.

Be sure to share in the comments whether it is worth developing this topic and telling about an alternative control option. Tell us about your own experience with this gateway: what projects have you tried to implement on this hardware and what was the result?

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *