
Key prerequisites:
- There’s an old unused Raspberry Pi 1 board;
- The board has been sitting on a shelf as a dead weight and is not used — the ‘Brick’ board;
What I would like to achieve:
- At a certain moment (for example, based on mood)
the board stops being a ‘Brick’ and a magic memory card is inserted; - An Ethernet cable and a connector from a regular speaker or headphones are plugged into the board;
- Once powered up, the former ‘Brick’ — sings
The main idea:
- Minimum amount of actions for any setup; ideally, we only connect the ‘Ethernet’ cable, power, and speakers, and do nothing else, at all ‘at all’;
- The former ‘Brick’ out of the box supports, for example, 20 internet radio stations, switching between them can be set to a mouse wheel click or to a specific GPIO pin (connect two wires and short them (my childhood dream));
- Control is done via a radio channel, and this radio channel can be an ordinary radio mouse;
- Take an existing system, a distribution assembled in the ‘Yocto Project’
i.e., as usual, we won’t have to do anything, as everything is already done.
(it’s enough just to place an external observer on the other side ‘of the TV’);
Description
The simplest Internet radio speaker ‘KODI’
This build is intended for old Raspberry Pi 1 boards
(gathering dust somewhere on the shelf, but still ready to work)
By default, it uses an m3u8 list of 12 Internet radio stations.
It is assumed that the board operates without an HDMI output, and to turn it off, it is enough to unplug the power adapter from the socket. As a super modern wireless remote control, you can use your super radio mouse (or connect a regular one with a tail).
When powered on, the network interface is configured by default via the DHCP protocol and plays the last remembered radio station from the list, with volume control done by a regular mouse:
(finally designate your mouse as ‘the boss of control,’ and congratulate it, it deserves it)
Scroll wheel forward - increase volume
Scroll wheel backward - decrease volume
Long press (3 seconds or more) on the right mouse button
- select the next radio station
Long press (3 seconds or more) on the left mouse button
- select the previous radio station
To add your own list of Internet radio stations
you can always connect an HDMI cable from the TV
and use the built-in graphical interface of Kodi 17.6
(turn off the board, connect HDMI, and turn on the power adapter)Main menu Kodi => 'Add-ons' => 'My Add-ons'
=> 'PVR Clients' => 'PVR IPTV Simple Client'
Initial implementation
(possible)
Initially, when I decided to create an 'Internet Radio Speaker', I planned the following:
- A minimalist console distribution in the Yocto Project;
- Audio stream is played through GStreamer;
- Network interface is configured via DHCP;
And such a solution has several advantages:
- Quite fast (boot time from power on 30-40 seconds);
- Quite reliable (fewer programs, fewer points of failure);
- The console distribution is much easier to switch to read-only mode
i.e., programs do not write anything to the root file system
(the file system on the SDHC card is, in my opinion, the first candidate for failures);
Note:
In Yocto, it is quite simple to switch the root filesystem (rootfs) to read-only mode by changing a single parameter during the build.
By default, Yocto provides two options:
1) The filesystem operates in read/write mode
(this is how all general-purpose distributions work, such as Ubuntu)
2) The filesystem operates in read-only mode
(this is how specialized distributions work, for example, in routers)
In read-only mode, all directories where application and service data are usually written during operation are mounted in RAM (for instance, the directory /var/log, etc.).
Data is only valid for the current session, and after a power loss, the data is lost.
If you specify "read only" during the build in the Yocto Project, your distribution will be configured to be read-only after the build,
but you can always add the capability to dynamically switch from "read only" to "read/write"; however, that is a whole different story...
And one main drawback:
"It has to be done", i.e., I need to spend N number of evenings
(usually after work, and this is the least effective time; at this time, the brain isn't thinking, it's usually asleep)
Also, I wrote my previous article on Habr about the multimedia center project
and the possibility to continue in the same vein overcame my research impulse. More on this in the next chapter.
Turning Kodi into an Internet radio speaker
To add the functionality I need, I will add another method to the recipe for building the distribution described in the previous see file berserk-image.bb
GUI_SETTINGS = "home/root/.kodi/userdata/guisettings.xml"
# Configuration for launching the last selected TV channel (1-background 2-foreground)
F1_LINE = "0"
R1_LINE = "1"
# Sound output configuration, always only the analog audio output is connected
F2_LINE = "PI:HDMI"
R2_LINE = "PI:Analogue"
# Since HDMI is not used by default, I disable automatic updates
# otherwise it may happen that the power is gone, but the data remains unwritten
F3_LINE = "0"
R3_LINE = "2"
# Method responsible for adding configuration:
# that turns "Smart TV" into a "simple Internet radio speaker"
add_radio_guisettings() {
sed -i "s|${F1_LINE}|${R1_LINE}|" ${IMAGE_ROOTFS}/${GUI_SETTINGS}
sed -i "s|${F2_LINE}|${R2_LINE}|" ${IMAGE_ROOTFS}/${GUI_SETTINGS}
sed -i "s|${F3_LINE}|${R3_LINE}|" ${IMAGE_ROOTFS}/${GUI_SETTINGS}
}
FIND_STR = "touch ./tmp/.FIRST_RUN."
SCRIPT_FIRST_RUN = "etc/init.d/first-run.sh"
# Since HDMI output may not be used,
# it's necessary to disable the "welcome message"
off_kodi_welcome() {
sed -i "s|${FIND_STR}|#&|" ${IMAGE_ROOTFS}/${SCRIPT_FIRST_RUN}
}
The methods are intended for modifying the root file system before the distribution image is created as a single raw file, which is written to the memory card using a command. dd
This is done as follows:
ROOTFS_POSTPROCESS_COMMAND += "add_radio_guisettings; off_kodi_welcome;"
In short, in the main configuration file of Kodi 17.6, three items are changed.
- Configuration for launching the last selected TV channel;
- Sound output configuration, always only the analog audio output is connected;
- Disabling automatic updates;
- Note:
The only thing I had difficulties with was that I had to pull in a database file in sqlite format => TV29.db, which specifies the current playing TV channel (since no channel is selected by default), and this cannot be done via xml configuration in Kodi.
A more detailed sequence of actions for each item:
1) Click on the "gear" icon in the upper left corner of the screen.
and select the "PVR and TV Settings" option (the image of a television with two horns).
Then in the left part of the menu, select the "Playback" item, and in the central section "General".
Specify in the dropdown "Continue with the last channel on startup".
Choosing the setting "Foreground".
or more visually:
"PVR and TV Settings"
=> "Playback"
=> "Continue from last channel on startup" => "Foreground"
2) Click on the gear icon in the top left corner of the screen and select:
"System Settings"
=> "Add-ons" => "Updates" => "Never check for updates"
3) Click on the gear icon in the top left corner of the screen and select:
"System Settings"
=> "Audio" => "Audio output device" => "PI: Analogue"
How I've been watching television incorrectly for two years.
I must confess that I've not learned how to watch television correctly in two years.
I usually watch television in the kitchen. A Raspberry Pi 2B board is connected to the TV, alongside Ethernet and HDMI ports. The board is powered through a regular USB cable plugged into the TV's USB port, which means turning on the TV with the remote also powers the Raspberry Pi board. Similarly, turning off the TV with the remote cuts power to the Raspberry Pi as well.
Yes, I fully realize that this is not the right way to do it, because the root file system of the Kodi media center (ext3) operates in read/write mode. But I'm a lazy person, and initially, I wanted to test how long I could keep turning the system off before it completely stops booting. Unfortunately, over two years, I’ve failed to make that happen (perhaps I've just been lucky, I don't know).
In my opinion, if this method works for my TV, it should also work for a "simple Internet radio speaker". Since I forcibly disabled the automatic update of Kodi plugins, the likelihood of file system failure is further reduced. So far, I see no issues with this.
Note:
However, if you wish, you can switch your distribution to "read-only" mode with one yocto command:
IMAGE_FEATURES += "read-only-rootfs"
and a bit of magic.
The distribution of the "internet radio speaker" described in this article is consumer-grade, and what is crucial for a consumer distribution is a beautiful GUI. In my opinion, it's very difficult or almost impossible to teach an ordinary user to type any incomprehensible magic commands in the console; they don’t even know the term. But a GUI, that’s another matter.
And this is probably my main argument in favor of a non-console distribution. The warm, cozy graphical user interface of Kodi, while not strictly necessary, is nonetheless present.
(Oh, I completely forgot to mention that Kodi can be controlled remotely, for example, using a smartphone app like 'Yatse', which may be a plus for some.)
Kodi configuration for mouse control
and now Rocket
VolumeUp
VolumeDown
ChannelDown
ChannelDown
ChannelUp
<!--
The configuration overrides global events for the following elements:
- scrolling the mouse wheel up
- scrolling the mouse wheel down
- pressing the middle mouse button
- handling long mouse presses (3 seconds or more),
0 identifier for the right button, 1 identifier for the left button
more detailed information on configuring mouse events:
What to do if the cable system hasn't reached you
"But I don't have any free Ethernet ports at home (or never did!)" — might exclaim some lucky holders of old Raspberry Pi 1 boards (perhaps the board was purchased for experimentation and has just been gathering dust on a shelf).
And since the board doesn't have built-in Wi-Fi, it is not very functional without an Ethernet connection.
Of course, using a Raspberry Pi 1 board without Ethernet is possible, but it will require some effort on your part. Usually, such things are interesting only in the context of learning something new; that is, this isn't typical user work.
So, let's consider a hypothetical scenario of using the board without Ethernet:
You can connect an external USB Wi-Fi adapter, bearing in mind that
the adapter should work well under Linux.
Note:
Unfortunately, some WiFi adapters will not work; this is not a feature of the distribution presented in this article, but rather a problem with specific WiFi adapter drivers in the Linux kernel. It can be noted that at this moment you cannot simply go to a store and buy any WiFi adapter. Instead, you should choose a WiFi adapter from a list of less problematic and well-working ones under Linux.
I've only checked the following models:
- WiFi adapter on Atheros chipset D-Link DWA-126 802.11n (AR9271)
- WiFi adapter NetGear WNDA3200
- WiFi adapter NetGear WNA1100
- WiFi adapter TP-Link TL-WN722N (AR9271)
- WiFi adapter TL-WN322G v3
- WiFi adapter TL-WN422G
- WiFi adapter Asus USB-N53 chipset Ralink RT3572
If you already have a USB WiFi adapter, you can check how well it works under Linux as follows:
- Install a widely used Linux distribution
for general use, such as ‘Ubuntu Desktop’ - Boot the system
- Connect your USB WiFi adapter
- Launch the network manager and try to connect to your WiFi access point
- If everything works well and your internet connection is stable, then your adapter is well supported, and you can continue your work on connecting this adapter in a specialized distribution and possibly with other kernel versions
(if not, unfortunately, it’s better not to even try)
Support for external WiFi adapters in ‘Raspberry PI’
For the correct operation of a WiFi adapter in Linux, we need two things:
1) Support in the Linux kernel for the specific WiFi adapter
2) Availability of a kernel module for the specific WiFi adapter in the system
Let’s take the TP-Link TL-WN722N adapter as an example. It has a simply excellent antenna.
Let’s find the chipset on which the board works — in my case, it’s ‘AR9271’ Note:
Interestingly, for the same model of the same manufacturer, the WiFi chipset can differ. For example, I encountered that for the TL-WN722N version 2, a different chipset Realtek RTL8188 is used, which already worked poorly under Linux (at that time). Unfortunately, that's how it goes; sometimes you need to pay attention to the small version numbers on the back (dark side) of the adapter.
Now let’s find the parameter name in the kernel configuration corresponding to the driver for the AR9271 chipset; it’s best to search for the combination of words ‘AR9271 cateee.net’
where "cateee.net" is a cool site with descriptions of Linux kernel module configurations
First, we find the name of the kernel configuration — CONFIG_ATH9K_HTC
and the name of the kernel module we need ath9k_htc
and then you just need to specify the name of the required module in the configuration fragment file
Linux kernel => recipes-kernel/linux/files/rbpi.cfg, add the line:
CONFIG_ATH9K_HTC=m
Thus, subsequently, you can connect any additional hardware to your system (if, of course, it is already supported in the Linux kernel)
What to do if you are a Habr geek — a builder
And you create cool things, for example, like or you are a student dreaming of creating something similar.
So, at a glance, you can pick up some Touch Screen for RPI from aliexpress, order a suitable battery there, connect it all to a Raspberry Pi 1, 2, or 3 board (better to 3, as it has built-in Wifi), choose a graphical interface theme in Kodi designed for touch screens, and voila => you could end up with a simple audio player. Of course, it will be quite bulky, but it will be yours.
Note:
A to build a Kodi Multimedia center for the most budget-friendly board
Raspberry Pi Zero Wifi in yocto, you just need to change two lines:
configuration file => build/conf/local.conf
MACHINE = 'raspberrypi0-wifi'
Kodi build recipe => recipes-mediacentre/kodi/kodi_17.bbappend
EXTRA_OECONF_append = "${@bb.utils.contains('MACHINE',
'raspberrypi0-wifi', '${BS_RPI}', '', d)}"
If the responsiveness of the Kodi 17.6 GUI due to one CPU core in Zero seems mysterious to you, you can do a trick and build an older, but very fast version, like Kodi 15.2, which is more "friendly" in this regard (sometimes legacy solves everything)
Unfortunately, I don't have the board, so I can't check it, but in my experience, this should work.
Brief assembly instructions
1) Install Yocto Project dependencies (for example in Ubuntu):
sudo apt-get install -y --no-install-suggests --no-install-recommends
gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential
chrpath socat cpio python python3 python3-pip python3-pexpect
xz-utils debianutils iputils-ping python3-git python3-jinja2
libegl1-mesa libsdl1.2-dev xterm
2) Download and install Repo:
mkdir ~/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
3) Download the project from GitHub:
PATH=${PATH}:~/bin
mkdir radio
cd radio
repo init -u https://github.com/berserktv/bs-manifest
-m raspberry/rocko/radio-rpi-0.2.8.xml
repo sync
4) Build the project:
./shell.sh
bitbake berserk-image
You can also build the same for Raspberry Pi 3B Plus, 3B, and 2B:
repo init -u https://github.com/berserktv/bs-manifest
-m raspberry/rocko/radio-0.2.8.xml
a more detailed assembly instruction
and recording on the microSDHC card.
Postscript
Certainly, the idea of an Internet radio speaker is quite common; it is well-known and you will find many articles on this topic on Habr, for example,
And you might think that I have simply adjusted the requirements to fit a ready-made solution. To this, I can respond and say that no, honestly.
The story of Mr. Ervi
Believe it or not, here's how it all happened:
Our office shares a boundary with a company that manufactures various sound equipment. One day, the director of this company, let's call him Mr. "Ervi," approached our deputy branch director, Mr. "Arseniy," and asked him how difficult it would be to set up a Raspberry Pi board to play sounds, meaning that the board connects to the network and speakers, and "you can hear a characteristic sound."
After that, Mr. Arseniy went to my boss's deputy, Mr. "Boris," and redirected the question to him. I, as a mere observer, happened to remember this idea and dubbed it the "Task of the Three Bosses."
In general, they wanted to do something good, but it ended with the quote - "But Mr. Ervi, as always, helped."
After a while, I asked Mr. "Boris" his opinion on writing a brief note on this topic for "Habr." Mr. "Boris" replied that changing the "three menu items" in Kodi doesn't really add any new information and isn't worth a separate mention. Of course, I completely agree with him, so I won't tell him that I wrote something about it.
The article was written exclusively for the "Raspberry Pi 1" board borrowed from Mr. "Boris" for the duration of the experiment; any resemblance to other "Raspberry Pi 1" boards is purely coincidental.
May you have plenty of great and diverse builds, and may even the former brick sing for you this year.
Source: habr.com
