doc:appunti:hardware:raspberrypi_nas
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
doc:appunti:hardware:raspberrypi_nas [2021/03/10 08:29] – niccolo | doc:appunti:hardware:raspberrypi_nas [2021/04/02 15:47] (current) – [Home Mediacenter and NAS with the Raspberry Pi] niccolo | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Home Mediacenter and NAS with the Raspberry Pi ====== | ====== Home Mediacenter and NAS with the Raspberry Pi ====== | ||
- | This is my recipe to build a mediacenter and NAS box using the Raspberry Pi. This is the list of components: | + | This is my recipe to build a **[[wp> |
- | * Raspberry Pi 4. | + | |
- | * Seagate IronWolf 3.5 inch Hard disk, 4 Tb. | + | |
- | * Suptronics.com X835 exapnsion board to connect | + | |
+ | * Ugreen **USB audio** adapter. | ||
+ | * **Gamepad** USB wireless (SNES-like) used as remote control. | ||
+ | {{.: | ||
+ | |||
+ | {{.: | ||
+ | **WARNING** :!: It turned out that the **Raspberry Pi 4**, when it uses the **USB 3** interface, produces **radio interferences on the 2.4 GHz** band. It is **impossibile to connect to the 2.4 GHz WiFi** access point which is only 5 meters far. It was also **impossible to use a wireless keyboard and mouse**, using one USB dongle which also operates on the 2.4 GHz. To operate a **wireless gamepad** (which also uses an USB dongle on the 2.4 GHz frequencies) I had to distantiate the dongle from the Raspberry Pi using and USB **extension cable of about 0.5 meters**. Due this **severe problem**, I can suggest the RPi4 solution only if you will use the **Ethernet** interface or an access point on the **5 Ghz** band. As an alternative to the wireless gamepad or keyboard, you can use the **[[https:// | ||
+ | |||
+ | {{.: | ||
+ | **WARNING** :!: There is another potential problem with the **Raspberry Pi 4**: due the increased CPU power, the designers decided to drop the **H263** and **MPG4** codecs from the hardware. That codecs were enabled in-hardware into the older Raspberry Pi models and the license price was included into the hardware price. In older models you could also purchase additional licenses, e.g. for **MPEG2** and **VC-1**; this is no longer an option on the Raspberry Pi 4. I experience a **[[https:// | ||
====== Subsystems ====== | ====== Subsystems ====== | ||
* **[[raspberrypi_nas_x835_sata_board]]** | * **[[raspberrypi_nas_x835_sata_board]]** | ||
* **[[raspberrypi_nas_smart_hard_disk]]** | * **[[raspberrypi_nas_smart_hard_disk]]** | ||
+ | * **[[raspberrypi_nas_networking]]** | ||
* **[[raspberrypi_nas_kodi]]** | * **[[raspberrypi_nas_kodi]]** | ||
* **[[raspberrypi_nas_audio]]** | * **[[raspberrypi_nas_audio]]** | ||
- | * **[[raspberrypi_nas_networking]]** | ||
* **[[raspberrypi_nas_mail]]** | * **[[raspberrypi_nas_mail]]** | ||
+ | * **[[raspberrypi_nas_remote_control]]** | ||
+ | * **[[raspberrypi_nas_case]]** | ||
- | ===== Networking ===== | ||
- | |||
- | Current release of **RaspiOS** (we are on Debian 10 Buster) uses **dhcpcd** to manage networking (see **[[https:// | ||
- | |||
- | * Use **/ | ||
- | * Do not use **/ | ||
- | * WiFi ESSIDs and passwords are in **/ | ||
- | * Do not install **Network Manager**. | ||
- | * If a gaphical interface is needed, use **lxplug-network**. | ||
- | * If some package installs the systemd **wpa_supplicant.service**, | ||
- | |||
- | I want the **eth0** interface to have a static IP address beside the one eventually assigned by DHCP (i.e. I want an IP alias on eth0:0). This is useful when I wan connect to the host even in an unknown network. To achieve this when dhcpcd is running, it is necessary to create an **user defined hook script**. See this page for more details: **[[..: | ||
- | |||
- | ===== Mail system ===== | ||
- | |||
- | I want a working **mail system** on the NAS, mainly because I want to eventually receive error messages from the various subsystems, think e.g. at the **smartd** daemon watching for S.M.A.R.T. hard drive errors... | ||
- | |||
- | In the following examples **pimedianas** is the hostname of my Raspberry Pi Mediacenter NAS. I istalled the **postfix** package and configured it as **satellite system** using a **SMTP relay host**. The relevant settings in **/ | ||
- | |||
- | < | ||
- | myhostname = pimedianas | ||
- | mydestination = $myhostname, | ||
- | relayhost = mail.example.org: | ||
- | default_transport = smtp | ||
- | relay_transport = smtp | ||
- | myorigin = $myhostname | ||
- | # Rewrite some sender addresses. | ||
- | sender_canonical_maps = hash:/ | ||
- | # Relay host requires SASL authentication. | ||
- | smtp_sasl_auth_enable = yes | ||
- | smtp_sasl_password_maps = hash:/ | ||
- | smtp_sasl_mechanism_filter = plain, login | ||
- | smtp_sasl_security_options = | ||
- | smtp_tls_security_level = may | ||
- | </ | ||
- | |||
- | The content of **/ | ||
- | |||
- | < | ||
- | root | ||
- | root@pimedianas | ||
- | root@localhost | ||
- | root@localhost.localdomain pimedianas@example.org | ||
- | </ | ||
- | |||
- | Write the proper info about **localhost** in **/ | ||
- | |||
- | < | ||
- | 127.0.1.1 | ||
- | </ | ||
- | |||
- | Finally I had to put my **SMTP credentials** required by the relaying server into **/ | ||
- | |||
- | < | ||
- | mail.example.org pimedianas: | ||
- | </ | ||
- | |||
- | Last but not least, I redirected all the mail for root to my real email address in **/ | ||
- | |||
- | < | ||
- | root: | ||
- | </ | ||
- | |||
- | Remember to compile all the files and restart the service: | ||
- | |||
- | < | ||
- | postmap / | ||
- | postmap / | ||
- | newaliases | ||
- | systemctl restart postfix.service | ||
- | </ | ||
- | |||
- | Now all the locally generated mails addressed to **root**, **%%root@pimedianas%%**, | ||
- | |||
- | ===== Audio ===== | ||
- | |||
- | I want to use **Kodi** for **HDMI video and audio** playback, but I want also occasionally to play music using **Music Player Daemon**, routing the audio to an external amplifier which has **RCA stereo connectors**. Once the cables are connected, it is also desiderable to play Kodi videos routing video to **HDMI monitor** and routing audio to the **stereo amplifier**. | ||
- | |||
- | For the **software** part, the recommended way is to use **Pulseaudio** as the backend. In this way, both Kodi and MDP can share the audio hardware at the same time, you are free also to use HDMI audio for Kodi (video) and analog RCA for MPD (audio). | ||
- | |||
- | For the **hardware** part, you can use the **digital HDMI audio** or the **analog 3.5 mm jack** (which carries video and stereo audio signals over a CTIA 4 poles connector). For a **better audio quality** you have to connect and **audio hat** or an external **USB audio sound card**; as explained below the integrated audio devices are of unacceptable quality also for an occasional user, let alone an audiophile one! | ||
- | |||
- | ==== Audio hardware: Raspberry Pi 4 ==== | ||
- | |||
- | === Digital audio through HDMI === | ||
- | |||
- | {{ .: | ||
- | This is the first natuarl choiche, at least when watching videos using Kodi. I use an old **Raspberry Pi 3** as a Kodi media center, connected to an HDMI monitor capable of audio too; the sound quality is acceptable and it is aligned to the medium quality of the speakers inside the monitor. Unfortunately I discovered that the **Raspberry Pi 4** has a **worse audio quality** than the Pi 3: I ear continously **pops, clicks and little gaps in the music**. I tried to swap the power supply and the HDMI cable with better quality ones, but **the problem remains**. It seems that the problem is not hardware related, but it is introduced when I add Pulseaudio in the software stack. If I select direct Raspberry **PI:HDMI** as sound device in Kodi, the audio **playback is OK**. | ||
- | |||
- | I prefer to avoid the HDMI audio output mainly because the audio of the HDMI monitor is of poor quality, but another problem is that if **the monitor goes into standby** (as Kodi does, when you don't play anything), also **the audio goes standby**. In this condition even the Music Player Damon cannot play to HDMI. | ||
- | |||
- | In my opinion, **HDMI audio** on the **Raspberry Pi 4** with **Pulseaudio** is of **unacceptable quality**. | ||
- | |||
- | === Analog audio through the 3.5 mm jack === | ||
- | |||
- | {{ .: | ||
- | The second choice is to use the analog audio through the 3.5 mm jack. I purchased a CTIA 4 poles jack **mic/ | ||
- | |||
- | As far as I know, and according to many articles on the net, there is not solution to this problem. | ||
- | |||
- | === Using an externa USB sound card === | ||
- | |||
- | For a decent audio quality, I decided that the only acceptable solution is to relay on an external USB sound card connected to my stereo amplifier. I choosed a model based on the **C-Media Electronics** chip (USB Id **0d8c: | ||
- | |||
- | < | ||
- | # Audio to USB audio device: | ||
- | default-sink = alsa_output.usb-C-Media_Electronics_Inc._USB_Advanced_Audio_Device-00.analog-stereo | ||
- | </ | ||
- | |||
- | |||
- | ==== Audio software: Pulseaudio ==== | ||
- | |||
- | As stated above, I want to play audio both with Kodi and with MPD. Both requires **libpulse0**, | ||
- | |||
- | < | ||
- | apt-get install pulseaudio mplayer | ||
- | </ | ||
- | |||
- | The **Kodi** program will be run using the **kodi Unix user**, so add the user to the **required groups** to grant the required permissions: | ||
- | |||
- | < | ||
- | adduser kodi audio | ||
- | adduser kodi pulse | ||
- | adduser kodi pulse-access | ||
- | </ | ||
- | |||
- | Become the kodi user, **start the PulseAudio server** and list the available **sinks** (audio output devices): | ||
- | |||
- | < | ||
- | su - kodi | ||
- | pulseaudio --start | ||
- | pacmd list-sinks | ||
- | </ | ||
- | |||
- | **WARNING**: | ||
- | |||
- | On the Raspberry Pi I get only the **HDMI** port and the **analog** jack: | ||
- | |||
- | < | ||
- | index: 0 | ||
- | name: < | ||
- | ... | ||
- | ports: | ||
- | hdmi-output-0: | ||
- | index: 1 | ||
- | name: < | ||
- | ... | ||
- | ports: | ||
- | analog-output: | ||
- | </ | ||
- | |||
- | To set the default audio device used by PylseAudio clients, add the following lines to **/ | ||
- | |||
- | < | ||
- | # Audio to the HDMI port: | ||
- | default-sink = alsa_output.platform-bcm2835_audio.digital-stereo | ||
- | # Audio to the analog (jack) port: | ||
- | # | ||
- | # Audio to USB audio device: | ||
- | # | ||
- | </ | ||
- | |||
- | To check the **current volume** use the **pactl list sinks** command: | ||
- | |||
- | < | ||
- | pactl list sinks | ||
- | Sink #0 | ||
- | State: SUSPENDED | ||
- | Name: alsa_output.platform-bcm2835_audio.digital-stereo | ||
- | ... | ||
- | Mute: no | ||
- | Volume: front-left: 65536 / 100% / 0.00 dB, | ||
- | balance 0.00 | ||
- | ... | ||
- | </ | ||
- | |||
- | Eventually turn off the **mute** status and set the required **volume**: | ||
- | |||
- | < | ||
- | # Set Mute: no | ||
- | pacmd set-sink-mute " | ||
- | # Set Volume: 50% | ||
- | pacmd set-sink-volume " | ||
- | </ | ||
- | |||
- | Finally check that the audio is working as kodi user: | ||
- | |||
- | < | ||
- | mplayer -ao pulse / | ||
- | </ | ||
- | |||
- | ==== PulseAudio as a system-wide service ==== | ||
- | |||
- | PulseAudio developers say that **[[https:// | ||
- | |||
- | * **Local users** do not exist. | ||
- | * **Desktop session** does not exist. | ||
- | * **Music Player Daemon** (MPD) is executed as a systemd service and it needs to access the audio device. | ||
- | * **Kodi** is executed via the **kodi-standalone** command, as a systemd service and it needs o access the audio device too. | ||
- | |||
- | We need a Systemd unit file to run the daemon **/ | ||
- | |||
- | < | ||
- | [Unit] | ||
- | Description=PulseAudio system server | ||
- | |||
- | [Service] | ||
- | Type=notify | ||
- | ExecStart=/ | ||
- | |||
- | [Install] | ||
- | WantedBy=multi-user.target kodi.service mpd.service | ||
- | </ | ||
- | |||
- | Systemd service can be of type **forking**, | ||
- | |||
- | Then we can enable and start the service (verify that the **pulseaudio** daemon is running by the **pulse** user): | ||
- | |||
- | < | ||
- | systemctl daemon-reload | ||
- | systemctl enable pulseaudio.service | ||
- | systemctl start pulseaudio.service | ||
- | </ | ||
- | |||
- | From now on, every user with group access to **audio**, **pulse** and **pulse-access**, | ||
- | |||
- | FIXME: When Pulseaudio is running as a system user, some commands like **pacmd** does not work for the user, because they search files under **%%/ | ||
- | |||
- | To enable PulseAudio as a system-wide service, several recipes exist on the Net, many of them are plain wrong: | ||
- | |||
- | * **[[https:// | ||
- | * **[[https:// | ||
- | * **[[https:// | ||
- | * **[[https:// | ||
- | * **[[https:// | ||
- | * **[[https:// | ||
- | |||
- | ==== Use PulseAudio with Kodi ==== | ||
- | |||
- | With the PulseAudio running as a system service, you can start Kodi and go to **Settings** => **System** => **Audio** = **Audio output device** and select **PULSE: Default**. Here you can also switch between HDMI and stereo jack: | ||
- | |||
- | * PULSE: Built-in Audio Digital Stereo, HDMI / DisplayPort | ||
- | * PULSE: Built-in Audio Analog Stereo, Analog Output | ||
- | |||
- | The audio devices **PI: | ||
- | |||
- | ==== Music Player Daemon ==== | ||
- | |||
- | To play music we choosed to install the **Music Player Daemon** (mpd) and a text based client FIXME: **ncmpc** or **ncmpcpp**, | ||
- | |||
- | The mpd configuration file is **/ | ||
- | |||
- | < | ||
- | music_directory | ||
- | bind_to_address | ||
- | |||
- | audio_output { | ||
- | type " | ||
- | name "pulse audio" | ||
- | } | ||
- | </ | ||
- | |||
- | The **mpd** user must be addedd to the relevant groups: **audio**, **pulse** and **pulse-access**. | ||
- | |||
- | ===== Kodi ===== | ||
- | |||
- | Installed the packages: | ||
- | |||
- | * **kodi** | ||
- | * **kodi-bin** - Contains the executable **kodi-standalone**, | ||
- | * **kodi-peripheral-joystick** - Necessary to add support for the gamepad. | ||
- | * **kodi-eventclients-kodi-send** - Contains the **kodi-send** tool, used to control Kodi from the command line. | ||
- | |||
- | We create an user called **kodi** which belongs to the groups: **audio**, **video**, **input**, **pulse** and **pulse-access**. To execute kodi as a Systemd service we created an Unit file **/ | ||
- | |||
- | < | ||
- | [Unit] | ||
- | Description = Kodi Media Center | ||
- | |||
- | # if you don't need the MySQL DB backend, this should be sufficient | ||
- | After = systemd-user-sessions.service network.target sound.target | ||
- | |||
- | # if you need the MySQL DB backend, use this block instead of the previous | ||
- | # After = systemd-user-sessions.service network.target sound.target mysql.service | ||
- | # Wants = mysql.service | ||
- | |||
- | [Service] | ||
- | User = kodi | ||
- | Group = kodi | ||
- | Type = simple | ||
- | ExecStart = / | ||
- | Restart = always | ||
- | RestartSec = 15 | ||
- | |||
- | [Install] | ||
- | WantedBy = multi-user.target | ||
- | </ | ||
- | |||
- | The service must be enabled and started. | ||
- | |||
- | ===== Kodi Add-ons ===== | ||
- | |||
- | We don't want to depend on auto-download, | ||
- | |||
- | Despite installing the add-on from a zip file, any **required add-ons** not present into the system will be automatically downloaded from the net and installed. Fortunately you can find the zip files of this additional add-ons into the **$HOME/ | ||
- | |||
- | |||
- | ===== Music ===== | ||
- | |||
- | Beside Kodi, which has its own functions to play music, I want also the functions offered by the **[[https:// | ||
- | |||
- | * **mpd** - The Music Player Daemon, the underlying daemon which actually plays music. | ||
- | * **ncmpc** - It is a MPD client for text terminals, based on ncurses. | ||
- | |||
- | ===== Transfer rate ===== | ||
- | |||
- | We measured the **transfer rate** from other home NASes, just to figure out how much time is required to **transfer 500 Gb of data**. The receiving NAS is the **Raspberry Pi 4** with a **Seagate 4 Tb** IronWolf 3.5 inch hard disk connected through the **X835 USB3** interface. The network is limited to **100 Mbit** transfer rate, due to the limit of the LAN switch. | ||
- | |||
- | ^ NAS model ^ Disk model ^ Transfer rate (Mbit) | ||
- | | LaCie d2 Network | ||
- | | QNAP TS-120 | ||
- | |||
- | ===== Web References ===== | ||
- | |||
- | * **[[https:// | ||
- | * **[[https:// | ||
- | * **[[https:// | ||
- | * **[[https:// | ||
- | * **[[https:// | ||
doc/appunti/hardware/raspberrypi_nas.txt · Last modified: 2021/04/02 15:47 by niccolo