Tag Archives: Raspberry Pi

Install pngquant on Raspbian, Raspberry Pi

pngquant is a command-line utility and a library for lossy compression of PNG images. The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency.

Install dependency, a library implementing an interface for reading and writing PNG (Portable Network Graphics) format files:

apt-get install libpng-dev

Download source code:

git clone git://github.com/pornel/pngquant.git

Go to directory:

cd pngquant

Build it:


Install it system-wide:

sudo make install

More info: http://pngquant.org/install.htmlhttps://github.com/pornel/pngquant

Raspberry Pi GPIO Temp Controlled Fan

Source: https://ich.wtf/blog/en-raspberry-pi-fan-gpio.php

Author: HerrAusragend

Our aim:

We want to setp up an automatic, GPIO and temp controlled fan using a Raspberry Pi without additinal software. After the CPU Core temperature exceeds a specific temperature, the fan starts spinning.


  • Raspberry Pi (Model B+) (Buy)
  • Fan (4-Pin, 12V) inin this case from an old NVIDIA Graphicscard
  • Pinboard
  • GPIO Connector wires (3x) (Buy)
  • Transistor BC337-40 800mA (Buy)
  • Resistor 1 kΩ 0.5W (Buy)

These hyperlinks are just recommended. You can use similar parts.

Helpful Links:


rpi circuit diagram
Circuit diagram


We connect Pin 4 (5V out) directly to the fan.
Pin 6 (Ground) will be connected over the Transistor with the 2nd fan wire.

To activate the Transistor, we need a low volatage, which we gain by Pin 3 (GPIO2). The GPIO Pins have a standard voltage of 3.3V. We reduce this by inserting the Resistor.


If we now switch on Pin 3 (GPIO2), the fan should start to spinn.

Enable GPIO2: (root)

echo "2">/sys/class/gpio/export
echo "out">/sys/class/gpio/gpio2/direction

Switch on GPIO Pin / Fan (root)

echo "1">/sys/class/gpio/gpio2/value

Switch off GPIO Pin / Fan (root)

echo "0">/sys/class/gpio/gpio2/value

Set up autmoatic temp control

In the following, we will set up the fan so that it starts after reaching a special temperature.

We log into the Raspberry Pi as root.


The Raspberry Pi autmoaticly checks the core temperature throught the built-in control panel.
If the temperature exceeds a certain value, the fan will start.
As long as the temp doesn’t fall below our value, the fan will not stop.

apt-get update && apt-get upgrade
apt-get install nano

Now we locate our directory of the script…

mkdir /home/fan
cd /home/fan

…and create our script.

nano fan.sh

Copy the following content into the script: (Use right mouse button to paste)

timestamp() {
	date +"%Y-%m-%d %T"


TEMP=`vcgencmd measure_temp | cut -c6,7`
STATUS=`cat /sys/class/gpio/gpio2/value`
echo `timestamp` "  Info:    Temperature: $TEMP"	>>$LOGDIR
if [ $TEMP -ge $VALUE ] && [ $STATUS -eq 0 ]
	echo `timestamp` "  Warning: Fan started."	>>$LOGDIR
	echo "1">/sys/class/gpio/gpio2/value
elif [ $TEMP -le $VALUE ]  && [ $STATUS -eq 1 ]
	echo `timestamp` "  Warning: Fan stopped."	>>$LOGDIR
	echo "0">/sys/class/gpio/gpio2/value

To change the value, you have to edit line 6.

To let the script run in background, we need cronjob.

crontab -e

and paste the following content:

* * * * * /home/fan/./fan.sh

(repalce with your path)

Overclocking Raspberry Pi: Set scaling_governor on Raspbian boot

If you are trying to overclock your Raspberry, but CPU keeps running at same frequency, there may be a reason in aggressive scaling_governor set to “powersave”.

Check your scaling_governor:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

If the result is


its probably the reason why your overclocking in /boot/config.txt file is not working.

You can see the list of available scaling governors using next command:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
conservative ondemand userspace powersave performance

Let do some tests.

Check the current frequency:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

The result is probably “700000”, which is default CPU frequency.

Lets make processor bussy and check its result:

for i in {1..10000} ; do set X 1; done && cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

The result is probably “700000” again.

Change the scaling governor:

su -c "echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"

Check your scaling_governor:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

The result should be


Lets test it again:

for i in {1..10000} ; do set X 1; done && cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

Now, the result should be “800000”.

To change scaling_governor on boot, edit /etc/rc.local file:

sudo nano /etc/rc.local

Add next line, so file looks like:

echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
exit 0


sudo reboot

After reboot, test if scaling_governor is set to “ondemand”:
(Note: Wait few minutes before you issue next command. There is a delay before new scaling_governor is applied.)

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

The result should be:


By default, CPU threshold is set to 95.

You can check it using:

cat /sys/devices/system/cpu/cpufreq/ondemand/up_threshold

So, a threshold is set to 95. It means CPU speed will rise when CPU utilisation is 95%.

You can set this value to a lower percentage. It means CPU will be clocked higher when CPU utilisation is lower.
For example if you want to speed up your CPU at 60%, add next line to /etc/rc.local file.

echo 60 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold

Install Nibbleblog on Raspbian, Raspberry Pi

Nibbleblog is a powerful engine for creating blogs, all you need is PHP to work. Very simple to install and configure (only 1 step).

First, install:

sudo apt-get install php5-gd

Restart Apache and PHP-FPM to reload new configuration:

sudo /etc/init.d/apache2 restart
sudo /etc/init.d/php5-fpm restart

Download latest archive (here):

wget http://sourceforge.net/projects/nibbleblog/files/v4.0/nibbleblog-v4.0.3.zip

Create folder for your blog (*example):

sudo mkdir /var/www/blog

Extract the archive:

unzip nibbleblog-v4.0.3.zip -d /var/www/blog

Note: You can download this archive on your computer and upload files via sftp://<raspberry-pi-ip-address> if you prefer.

Set permissions on your folder:

sudo chown johndoe:www-data -R /var/www/blog
sudo chmod 775 /var/www/blog/content


sudo chown www-data:www-data -R /var/www/blog
sudo chmod 755 /var/www/blog/content

Point your browser to location where files are extracted, for example:




and complete the form.


Install ReadyMedia miniDLNA 1.1.4 on Raspbian

Source: Install ReadyMedia miniDLNA 1.1.4 Raspberry Pi

The latest version of ReadyMedia miniDLNA in the Raspbian repos is ancient so we are going to compile miniDLNA (now ReadyMedia) from source on Raspbian. This should fix avi problems you may have had in the past like them not showing up in the library.

Remove your old miniDLNA 1.0.24 (if they exist)

sudo apt-get purge minidlna -y
sudo apt-get remove minidlna
sudo apt-get autoremove -y

Make sure you have a source repository, default Raspbian does not include this

echo "deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free" | sudo tee -a /etc/apt/sources.list


edit /etc/apt/sources.list file:

sudo nano /etc/apt/sources.list

and add next line:

deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

Update repositories so it will detect your new source repo

sudo apt-get update

Grab dependencies for building it from source

sudo apt-get build-dep minidlna -y

If you get any errors you can install the dependencies manually

sudo apt-get install libjpeg-dev libsqlite3-dev libexif-dev libid3tag0-dev libvorbis-dev libflac-dev -y

Download miniDLNA 1.1.4 source

wget http://sourceforge.net/projects/minidlna/files/minidlna/1.1.4/minidlna-1.1.4.tar.gz

Unpack it

tar -xvf minidlna-1.1.4.tar.gz

Enter the miniDLNA directory

cd minidlna-1.1.4

Configure, make and install miniDLNA, it will take 5 minutes.

./configure && make && sudo make install

Copy the default configuration file

sudo cp minidlna.conf /etc/

Copy the startup daemon script to autostart ReadyMedia miniDLNA on boot

sudo cp linux/minidlna.init.d.script /etc/init.d/minidlna

Make the startup script executable

sudo chmod 755 /etc/init.d/minidlna

Update rc to use the miniDLNA defaults

sudo update-rc.d minidlna defaults

Edit the configuration

sudo nano /etc/minidlna.conf

Note: Edit the following to point to your media

This version of minidlna will give you multiple folders under Video. Before movies and TV would have been under separate categories, now movies and TV will both be under the category video. It will also show the folder structure of them instead of showing just the video files. Avi files will also show up and be streamable.

inotify uses resources because it autoupdates your library, if you don’t use inotify you will have to manually restart and reload the miniDLNA service

The friendly name is how your miniDLNA server will show up to its streaming clients

# Names the DLNA server
friendly_name=RasPi Media Server
# Tells the DLNA to update the library when there are changes

Ctrl+X, Y and Enter to save and exit

Start the minidlna service

sudo service minidlna start

Now make sure it starts on boot

sudo reboot

Your Raspberry Pi DLNA server will now be accessible to stream media to your clients: PCs, XBOX, PS3, Phones, TVs and more.

Install Seafile on Raspian, Raspberry Pi

Prerequisites: Install LAMP (optional: Installing No-IP client on Raspian)

More info at: Deploying Seafile under Linux

Login as root:

sudo su

Create directory for Seafile: (example*)

mkdir /media/usbhdd/seafile

Move to created directory:

cd /media/usbhdd/seafile

Download latest Seafile server for Raspberry Pi:

wget https://bitbucket.org/haiwen/seafile/downloads/seafile-server_4.0.6_pi.tar.gz

Extract archive:

tar xvf seafile-server_4.0.6_pi.tar.gz

Create directory:

mkdir installed

Move your archive to newly created directory:

mv seafile-server_4.0.6_pi.tar.gz installed

Check prerequisites:

dpkg-query -l python2.7 python-setuptools python-imaging python-mysqldb

and install missing packages:

apt-get install python-setuptools python-mysqldb

Move to directory:

cd seafile-server-4.0.6/

Run the script:

What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] <hostname/servername>

What is the ip or domain of the server?
For example: www.mycompany.com,
[ This server's ip or domain ] <your-dynamic-dns-address> OR <hostname>.local OR <local-IP-address>

Which port do you want to use for the ccnet server?
[ default "10001" ]

Where do you want to put your seafile data?
Please use a volume with enough free space
[ default "/media/usbhdd/seafile/seafile-data" ]

Which port do you want to use for the seafile server?
[ default "12001" ]

Which port do you want to use for the seafile fileserver?
[ default "8082" ]

Please choose a way to initialize seafile databases:

[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases

[ 1 or 2 ] 1 *recomended by seafile

What is the host of mysql server?
[ default "localhost" ]

What is the port of mysql server?
[ default "3306" ]

What is the password of the mysql root user?
[ root password ] <your-mysql-root-password>

verifying password of user root ... done

Enter the name for mysql user of seafile. It would be created if not exists.
[ default "root" ] seafile OR <any-other-username-for-seafile-mysql-user>

Enter the password for mysql user "seafile":
[ password for seafile ] <password>

Enter the database name for ccnet-server:
[ default "ccnet-db" ]

Enter the database name for seafile-server:
[ default "seafile-db" ]

Enter the database name for seahub:
[ default "seahub-db" ]

This is your configuration

server name: <hostname/servername-you-used>
 server ip/domain: <ip-adress/domain-you-used>
 ccnet port: 10001
seafile data dir: /media/usbhdd/seafile/seafile-data
 seafile port: 12001
 fileserver port: 8082

database: create new
 ccnet database: ccnet-db
 seafile database: seafile-db
 seahub database: seahub-db
 database user: seafile

Press ENTER to continue, or Ctrl-C to abort

While in /media/usbhdd/seafile/seafile-server-4.0.6:

Start seafile:

./seafile.sh start # Start seafile service

Start seahub

./seahub.sh start # Start seahub website, port defaults to 8000
Starting seahub at port 8000 ...

It's the first time you start the seafile server. Now let's create the admin account

What is the email for the admin account?
[ admin email ] <your-mail>

What is the password for the admin account?
[ admin password ] <password>

Enter the password again:
[ admin password again ] <repeat-password>

Successfully created seafile admin

Type in your browser, and check if setup is successful:




Generate and apply your ssl keys (logged in as user):

sudo openssl genrsa -out seafile-key.pem 2048
sudo openssl req -new -x509 -key seafile-key.pem -out seafile-cacert.pem -days 1095
sudo mkdir /etc/apache2/ssl
sudo mv *.pem /etc/apache2/ssl
sudo mkdir /var/www/seafile
sudo a2enmod ssl

Edit file:

sudo nano /media/usbhdd/seafile/ccnet/ccnet.conf

Add this line:

SERVICE_URL = https://<your-dynamic-dns-address>:8001


SERVICE_URL = https://<hostname>.local:8001


SERVICE_URL = https://<local-IP-address>:8001

Edit file:

sudo nano /media/usbhdd/seafile/seahub_settings.py

Add this line:

FILE_SERVER_ROOT = 'https://<your-dynamic-dns-address>:8001/seafhttp'


FILE_SERVER_ROOT = 'https://<hostname>.local:8001/seafhttp'


FILE_SERVER_ROOT = 'https://<local-IP-address>:8001/seafhttp'

Enable modes on Apache:

sudo a2enmod rewrite
sudo a2enmod fastcgi
sudo a2enmod proxy_http

Edit file:

sudo nano /etc/apache2/ports.conf

Add these lines:

<IfModule ssl_module>
Listen 8001

<IfModule mod_gnutls.c>
Listen 8001

Edit file:

sudo nano /etc/apache2/sites-available/seafile-ssl.conf:
FastCGIExternalServer /var/www/seafile/seahub.fcgi -host -idle-timeout 600

<Directory /data/opt/seafile/seafile-server-latest/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted

<VirtualHost *:8001>
ServerAdmin <your-mail>

Servername <hostname/servername-you-used>
ServerAlias <hostname/servername-you-used>

DocumentRoot /var/www/seafile
Alias /media /media/usbhdd/seafile/seafile-server-latest/seahub/media

SSLEngine On
SSLCertificateFile /etc/apache2/ssl/<cert-name-you-used>.pem (*seafile-cacert.pem previously as an example)
SSLCertificateKeyFile /etc/apache2/ssl/<key-name-you-used>.pem (seafile-key.pem previously as an example)

RewriteEngine On

# seafile httpserver
ProxyPass /seafhttp
ProxyPassReverse /seafhttp
RewriteRule ^/seafhttp - [QSA,L]

# seahub
RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /seahub.fcgi/$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Enable site:

sudo a2ensite seafile-ssl.conf

Restart Apache:

/etc/init.d/apache2 restart

Log in as root:

sudo su

Move to folder:

cd /media/usbhdd/seafile/seafile-server-latest


./seahub.sh stop
./seafile.sh stop


./seafile.sh start
./seahub.sh start-fastcgi

Forward ports on your router if you are using dynamic dns:

  • 8001
  • 10001
  • 12001

to local IP address.

Test your setup in browser:


Install client on your computer or smartphone and test. (Download client here.)


Create a script /etc/init.d/seafile-server (*logged in as user)

sudo nano /etc/init.d/seafile-server

The content of this script is: (You need to modify the value of user and script_path accordingly)


# Provides: seafile-server
# Required-Start: $local_fs $remote_fs $network mysql
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts Seafile Server
# Description: starts Seafile Server

# Change the value of "user" to your linux user name

# Change the value of "script_path" to your path of seafile installation

# Change the value of fastcgi to true if fastcgi is to be used
# Set the port of fastcgi, default is 8000. Change it if you need different.

case "$1" in
sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}
if [ $fastcgi = true ];
sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}
if [ $fastcgi = true ];
sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}
sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
echo "Usage: /etc/init.d/seafile {start|stop|restart}"
exit 1

Note: If you want to start seahub in fastcgi, just change the fastcgi variable to true.

Note: If you deployed Seafile with MySQL, append “mysql” to the Required-Start line: # Required-Start: $local_fs $remote_fs $network mysql

Add Directory for Logfiles:

sudo mkdir /media/usbhdd/seafile/logs

Make the seafile-sever script executable:

sudo chmod +x /etc/init.d/seafile-server

Add seafile-server to rc.d

sudo update-rc.d seafile-server defaults



Backup Raspian using rsync

Create a folder on external disk, for example:


Create exclude list, to avoid loop and unnecessary files:

sudo nano /media/usbhdd/backup/rsync-exclude.txt

Add next lines: (Note: new rule – new line)


Test and backup using next command:

sudo rsync -av --progress --delete --exclude-from=/media/usbhdd/backup/rsync-exclude.txt / /media/usbhdd/backup/rsync/

Lets make backup runs automatically and send an email after execution:

(Note: Setup your mail using Gmail)

Create a script:

nano /home/<username>/scripts/rsync-backup.sh

Add next lines:

sudo rsync -av --delete --exclude-from=/media/usbhdd/backup/rsync-exclude.txt / /media/usbhdd/backup/rsync/
if [ "$?" -eq "0" ]
   echo "rsync backup OK - $(date)" | mail -s "rsync backup status" <your-gmail-account>@gmail.com
   echo "Error while running rsync. Exit code: $? - $(date)" | mail -s "rsync backup status" <your-gmail-account>@gmail.com

Make it executable:

chmod u+x /home/<username>/scripts/rsync-backup.sh

Login as root:

sudo su

Edit crontab file:

crontab -e

And add next lines:

#every wednesday at 12:00
00 12 * * 3 /home/<username>/scripts/rsync-backup.sh >> /home/<username>/logs/cron.log 2>&1
@monthly mail -s "cron monthly log report" <your-gmail-account>@gmail.com < /home/<username>/logs/cron.log

*The last three lines are for monthly report on crontab jobs. They are not necessary for backup. They are just there for monthly check if everything in crontab went smoothly.