Friday, January 19, 2018

RaspBerry Pi - The Audio Engine - Part 4 - Advanced OS Tuning

Nice to have you back @ Part 4 of the series.

By now you already should have a nicely running audio streaming system based on the Raspberry PI 3B(+), a nice little HAT DAC and piCorePlayer as audio engine.


This part of the "RPI Audio Engine series" will cover some more rather "advanced tweaks".



This article is Work-in-Progress!  Latest update: Nov-18-2018



As with all tuning measures my ultimate goal is to make the system more efficient and smooth running. I mentioned that before.

The tweaks I propose in this "Advanced OS Tuning" article are optional. 

I'd still say - just try them. ;)



Uncluttering

What we do first is: 

1. shutdown the webserver (the WEB-GUI)
2. shutdown ssh (remote access)
3. shutdown DHCP

As soon as you're done with the overall pCP setup, all these services are not needed anymore during normal operation - "audio streaming mode". 

These processes just keep hanging around and are blocking system resources and continuously poking around on the network stack.  

You'll be able to disable/pause this mod easily!

SO. What are we doing here? We first wait a little after boot. During this period you'll be able to access the pCP WEB GUI.  That'll give you all the time to disable this mod again!

If you let the period pass, you'll lock yourself out. No more pCP access via WEB or ssh! Until you reboot the system again. You then can try to disable the mod again!

From my experience 120 seconds is sufficient time to boot up and to disable the mod.


pCP offers to issue certain Linux commands via its WEB GUI. The entered commands will be automatically executed during the pCP startup period.
In the first part of this "Advanced OS Tuning" exercise  we'll make use of that feature.






Enter this line, as shown above, in the "User commands" menu and save it: 

sleep 120;pkill -f httpd,pkill -f ssh;pkill -f udhcpc

After doing that you have to reboot your PI to activate the mod!

If you now intend to run any further pCP configurations via WEB-GUI or ssh, you can just disable/pause the mod by adding a '#" in front of the command line.


#sleep 120;pkill -f httpd,pkill -f ssh;pkill -f udhcpc

Save it and reboot again. 

Once you're finished with your config work just remove the "#", save it and reboot again.

That's an easy one, wasn't it!

And that already concludes the 1st part of this article.


pCP terminal access


Everything until now, could be accomplished by using the WEB GUI.


More complex stuff needs to be done via terminal and ssh access.
It's not that difficult as it sounds! I walk you through that process.


Once more. Before your start make a backup of your SD card first. 


Let's get started.


1. ssh login

I won't get into that right now. On Windows you need to install puTTY. On OSX and Linux you can simply use a terminal.There are numerous guides out there how to accomplish ssh access from any platform.

You'll need the IP address. We covered that in Part 2
You'll need a user name. For pCP it's  "tc"
You'll need a password. For pCP it's   "piCore"

Basically you'll end up like this:






From now we're going to execute all commands as user "root" - the adminuser of Linux. This way we avoid that any of the commands we'll execute fail.

Enter:

sudo su

Now you switched to user root. It stays like that as long as you remain in the terminal!

  
Next we mount the boot-partition of the SD-card to be be able to edit some system config files. You can compare these files with a BIOS on a normal computer. On the PI the BIOS info is basically kept in two different text-files.

Note: On Raspbian or Arch Linux Arm we wouldn't have to mount the boot partition!

Just type (or copy/paste):

mount /dev/mmcblk0p1 /mnt/mmcblk0p1





Let's backup the file we gonna touch - run this step only once!
 



cp /mnt/mmcblk0p1/config.txt /mnt/mmcblk0p1/config.txt.orig


Now we're set to introduce this or that tweak.


Turn Off Power and Act LEDs


There are two LEDs on the PI. These 

a. draw about 5mA current or less in blinking mode
b. might cause an annoying light spectacle in a dark listening room.
c. and cause certain activity on the CPU

The process to accomplish this, is different for every RPI model.

Copy/paste all highlighted lines one one after one.

The commands are different for each RPI model.
Don't get them mixed up!.

............................................................................................ For RPI 3B:

1. Disable the ACT LED

echo 'dtparam=act_led_trigger=none' >> /mnt/mmcblk0p1/config.txt 
echo 'dtparam=act_led_activelow=on' >>/mnt/mmcblk0p1/config.txt

2. Disable the PWR LED

echo 'dtparam=pwr_led_trigger=none' >>/mnt/mmcblk0p1/config.txt
echo 'dtparam=pwr_led_activelow=on' >>/mnt/mmcblk0p1/config.txt

............................................................................................
FOR RPI 3B+

echo 'dtoverlay=pi3-act-led>>/mnt/mmcblk0p1/config.txt


Disable the ACT LED

echo 'dtparam=act_led_trigger=none>>/mnt/mmcblk0p1/config.txt


Disable the PWR LED

echo 'dtparam=pwr_led_trigger=none>>/mnt/mmcblk0p1/config.txt

echo 'dtparam=pwr_led_activelow=off>>/mnt/mmcblk0p1/config.txt


Disable the ethernet port LEDs

echo 'dtparam=eth_led0=14>>/mnt/mmcblk0p1/config.txt

echo 'dtparam=eth_led1=14>>/mnt/mmcblk0p1/config.txt


............................................................................................
ALL

sync; reboot



..................................................................................................................................................

That'll be it for the time being.

This article became much shorter as the original. Many 
of the "measures" I had described in the earlier versions are now much easier to accomplish and/or done differently or described elsewhere. One reason for it is that the pCP team also reads the blog and introduced this or that mod into the GUI once in a while. Thx a lot for that.


Wrap-Up

Hopefully you made it all the way down here. I'm pretty sure you did. 
I'm pretty confident you'll enjoy the result.


Don't forget to make a backup of your SD-card after this exercise!



Enjoy.

3 comments:

  1. Hi, I'm finding your blog both useful in tuning my Rpi3 with Picoreplayer and technically very interesting.

    ReplyDelete
  2. Hey Klaus,

    thanks for keeping up the good work... and even more for sharing it with us!

    When using your suggested "Measure 1" the LEDs of my PI 2 kept staying on, I then changed "on" to "off" et voilá: They´re off now! Just a typo I assume?

    I plan to use a second PI3 B+ as a standalone LMS server (picoreplayer-based, too): It would be great to know if you had any suggestions for optimizations of that particular setup?!

    All the best,
    Oliver

    ReplyDelete