OpenHome media with minidlna and BubbleUPnP Server

dlna_network

One year ago I have written about my Spotify setup. I am still having a Spotify acount, but now that the novelty is gone I find myself listening to it less often. One of the reasons is that I still like to buy music. When I buy a CD, then I rip it to FLAC (an open standard for lossless audio), because that is the way I prefer to listen to it. I can mount my audio collection over SSH with autofs and sshfs when I am not at home. And at home I have a network connected audio system. At home I want to be able to control the music in the living room using a smart phone. Recently I find myself moving from Apple towards Android. Fortunately the audio system I bought supports both the proprietary Apple AirPlay protocol as the open uPnP/DLNA media protocol.

Control point on the server

In my Spotify post I explained you can play the music from an iPhone and stream it using AirPlay. This turned out to be a problem, since your iPhone is in your pocket all the time. When your select music and leave the room the music stops or if you are half within reach, stutters. This is very annoying for other people in the room. I feel this is a critical flaw in the “connected” music experience in my house. In the end it should not matter who selects the music that is playing in a room.

To work around this problem I now use an iPad in the living room to play the music from. This might be an expensive workaround, but it works for me. A better solution would be to move the “control point” from the tablet to the media server. Then we don’t need a dedicated tablet to act as a control point for the room. It also means anyone can access an app on his/her phone and change the music in the room. This turns out to be the ideal situation and this is exactly what the OpenHome media protocol can bring us.

OpenHome media protocol

In this post we explain how to make the above setup work. It requires OpenHome support, which is an extension to UPnP AV as you can read on the openhome.org website:

Devices can implement ohMedia in place of, or alongside of, the UPnP Forum’s AV standards. It offers a number of advantages over the UPnP Forum’s AV standards.

One of the advantages is:

Better support for playlists: Playlists are stored on the renderer, allowing playback to continue when the control point leaves the network (e.g. your tablet goes to sleep, runs out of battery, or leaves the wifi zone).

This is important and expected, because we want the smart phone to tell what to play, but we don’t want it to actually be the point that plays the music or tells what to play next.

DLNA + uPNP + OpenHome

We need to install the following to get to the perfect setup:

  1. minidlna” on the Linux server to provide a DLNA media server
  2. BubbleUPnP Server” on the Linux server to convert the uPnP media renderer into an OpenHome media renderer
  3. BubbleUPnP Android app” on the Android phone to control the playlist on the OpenHome media renderer

This is not just any combination of applications. This is thoroughly tested and I tested many other software packages for many days.

Installing minidlna

On Ubuntu 14.04 you can install minidlna 1.1.2 using the following command:

sudo apt-get install minidlna

We still need to configure some preferences by editing the configuration file:

sudo nano /etc/minidlna.conf

Look for the “media_dir” directive and enable something like this (“A” is for audio):

media_dir=A,/home/maurits/Music

Look for the “root_container” directive and set it to “B” if you like your own folder structure:

root_container=B

Here you specify on which interface the server should listen:

network_interface=eth0

To make the configuration effective you need to save and exit with “Ctrl-X” “y” and restart minidlna using:

sudo service minidlna restart

Now you can access the status page on: http://localhost:8200/

Installing BubbleUPnP Server

Unfortunately Ubuntu 14.04 does not have BubbleUPnP in the repository. This is why you need a PPA:

sudo add-apt-repository ppa:bubbleguuum/bubbleupnpserver
sudo apt-get update
sudo apt-get install bubbleupnpserver

After installing you need to configure your renderer on the following URL: http://localhost:58050/

On the tab “Media Renderers” you need to check “Create an OpenHome renderer” for your renderer. On the “Network and Security” tab I recommend you to leave everything unchecked.

Installing the BubbleUPnP app

BubbleUPnP is a paid Android app, but it also has a free version with some limitations. Fortunately these limitations do not prevent you to properly evaluate the product. A full featured version costs less than 4 euro.

bubbleupnp

Conclusion

With the described setup I really enjoy playing music from my personal collection using my Android phone. I use the setup daily and it is as convenient as playing my Spotify music from my iPad. Great work by the community. Kudos should also go to NETGEAR and BubbleSoft for creating awesome software for Linux and Android.

PS: On a rooted Android device you may be able to play audio from Spotify to UPnP/DLNA renders, but be careful as rooting your device is not without risks.

 

 

 

 

Share

How to disable the built-in “spyware” in Ubuntu 14.04

Since Edward Snowden hit the news, mass surveillance is a hot topic. No wonder that people are complaining about the privacy problems in Canonicals latest Ubuntu Linux versions. Ubuntu has a search bar in which you type every program you start or document you open. Everything you type in this bar is sent to Amazon (among others). It allows there companies to see when you use your computer and what you use it for. Some people call the privacy endangering component “spyware” or “malicious software”.  Let’s look at the definition of spyware:

Spyware is software that aids in gathering information about a person or organization without their knowledge and that may send such information to another entity without the consumer’s consent, or that asserts control over a computer without the consumer’s knowledge. – Wikipedia

This feature is enabled by default. The only way the user is informed is by some legal notice that is buried many menus/clicks deep. I think most users will never see it. This is why I believe it fully qualifies as spyware. In my opinion it would have been okay if an opt-in was presented during the installation, but this is not (yet) the case. Richard Stallman is also very outspoken on the subject:

One of the major advantages of free software is that the community protects users from malicious software. Now Ubuntu GNU/Linux has become a counterexample. What should we do? – Richard Stallman

When Richard Stallman is asking “What should we do?” he does not mean: “How do we disable it?”. Since the answer to that question is easy, let me start with that one.

This is how to disable the Ubuntu “spyware”

If you happen to be running Ubuntu 14.04 and you value your privacy, then do this:

ubuntu_spyware

Switching off “online search results” solves your privacy problem, but not the real problem. The real problem is that Canonical is trying to sell their users privacy to make a quick buck.

What should we do about this behavior by Canonical?

I feel that switching from Ubuntu 14.04 to an Ubuntu 14.04 based distribution will send a clear signal to Canonical. I would suggest Xubuntu 14.04 or Linux Mint 17 as good alternatives to Ubuntu 14.04. Or if you are completely fed up with Canonical, then you may want to switch to Debian or even Trisquel Linux. No other Linux distribution (than Ubuntu) has this privacy problem. I believe that once the popularity of Ubuntu drops, Canonical will have to reconsider selling their users (private) data.

Share

Debugging Go using LiteIDE on Ubuntu 14.04

So this weekend I decided to give the Go programming language (golang) a spin. Go is best described like this:

Go, also called golang, is a programming language initially developed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a statically-typed language with syntax loosely derived from that of C, adding garbage collection, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library. – Wikipedia

When you are stuck, don’t search the web for “Go”; it will not give relevant results. Use the word “golang” instead.

Installing golang on Ubuntu 14.04

ubuntu-go

I am using Ubuntu 14.04 (actually Xubuntu), but these instructions should also work on any other recent Debian-based Linux (like Mint 17). I tested using a clean install, so you should not run into unexpected dependencies. First we install the two prerequisites (Git and Mercurial):

sudo apt-get install mercurial git

Then we download the latest version of the Go language in which debugging is working: version 1.2.2. Debugging (gdb) is broken in golang 1.3 and hopefully gets fixed in 1.4. EDIT: Thank you ondrej for finding this issue. The following commands will download the software package and unpack it to the “go” directory in your home folder (in my case “/home/maurits/go”):

cd ~
wget http://golang.org/dl/go1.2.2.linux-amd64.tar.gz
tar -xf go1.2.2.linux-amd64.tar.gz
rm go1.2.2.linux-amd64.tar.gz

Go supports installing third party packages using the “go get” command. These are not installed in the same directory as the initial Go installation. This simplifies package management, because every project can have it’s own workspace if needed. So, we create a (first) workspace directory that will hold third party packages. We will name it “workspace-go” since it is still generic and it will be located in my home folder.

mkdir ~/workspace-go

We will use the directory later, when we “go get” some third party packages.

Setting up the command-line environment

To avoid adding the GO settings to my environment, I have made a file that holds my Go environment variables. You need to set three variables: GOROOT is the installation directory of GO, GOPATH is the workspace directory for “go get” and finally it can be convenient to add the “bin” directories from GOROOT and GOPATH to the (search) PATH. Using the following commands I make a “go.env” file that can be used to set the environment variables.

echo "export GOROOT=\$HOME/go" > ~/go.env
echo "export GOPATH=\$HOME/workspace-go" >> ~/go.env
echo "export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin" >> ~/go.env

To actually load the above file you have to type the following command in the Terminal:

. ~/go.env

Note that the environment variables are only set in the active terminal. When you open another Terminal you will have to run the “go.env” file before you can use the “go” command(s). When your Go environment is correctly set you can (for example) get some nice third party tools using:

go get code.google.com/p/go.tools/cmd/...
go get github.com/golang/lint/golint

Run a for loop example from the command-line

There is a very good website named “Go by Example“. It holds a large set of small Go files that clearly show how the various built-in functions of the Go language work. I chose the “for loop” example to show how compiling and running a golang file works. I make a directory “hello” (from “hello world”) to store my first Go programs in. Then I download the “for.go” example:

mkdir ~/hello
cd ~/hello
wget https://raw.githubusercontent.com/mmcgrana/gobyexample/master/examples/for/for.go

To run the code you need to open a Terminal and load the Go environment from the “go.env” file. Now the “go” command is available and you can execute “go run” as shown below:

. ~/go.env
cd ~/hello
go run for.go

You can also first “build” an executable file. The advantage is that you can distribute this file. It can be executed on any other Linux machine with the same architecture. Go also support cross-compiling for other architectures. It means that Go does not require anything (a VM or run-time) to be installed on the target machine. The downside to this is that the executable size is large. This simple “for.go” script has a compiled size of 2,2 MB (megabyte). This can be reduced to 1,2 MB by removing debug symbols using the “ldflags” like below:

. ~/go.env
cd ~/hello
go build -ldflags "-s" for.go
./for

Debug from the command-line

Golang has decent GDB support. This may help you a lot when you run bugs that you cannot effectively squash using “printf debugging”. Below I give an example of a run where I break on line 19 of the “for.go” script. Note that you expect the variables “i” and “j” to be “4” and “7”. They will not have these values, unless you disable compiler optimizations by adding the “gcflags” to the build command as shown below:

. ~/go.env
cd ~/hello
go build -gcflags "-N -l" for.go
gdb for
b for.go:19
r
l
i loc
q
y

LiteIDE: a Go IDE with debugging capabilities

liteide2

In the above section we have seen how to run, build and debug from the command line. Fortunately, there is also a nice IDE available that simplifies these things. It is called LiteIDE and it supports just one language: Go. The following commands download it from sourceforge and install it in the “liteide” directory in your home folder (in my case “/home/maurits/liteide”):

wget --content-disposition http://sourceforge.net/projects/liteide/files/X22/liteidex22.linux-64.tar.bz2/download
tar -xf liteidex22.linux-64.tar.bz2
rm liteidex22.linux-64.tar.bz2

In the menu you can create a launcher that executes the following:

~/liteide/bin/liteide

The following file can be used as an icon:

~/liteide/share/liteide/welcome/images/liteide400.png

When you have started the application there is one thing you must do:

View -> Manage GOPATH... -> Add Directory... -> Select: ~/workspace-go

This will make sure that any third party package that you install can be loaded.

Step-by-step debugger for Go

To make sure the (GDB based) step-by-step debugger works you need to do the following:

Build -> Build Configuration... -> Custom -> BUILDARGS -> Enter: -gcflags "-N -l"

Verify everything is working correctly by executing the following debug run:

File -> Open Folder -> Click: hello -> Choose
Double click "for.go" in the "Folders" pane
Build -> Build (Ctrl-B)
Put cursor on line 19
F9 (toggle breakpoint)
F5 (start debugging)
F5 (until green arrow is on line 19)
Debug pane should show "Variables" tab with "i=4" and "j=7"

Happy coding!

Share

Symfony on HHVM 3 and Nginx 1.4 vs PHP 5.5 and Apache 2.4

symfony_hhvm_nginx

Installing Symfony

From symfony.com/download we get the latest (2.4.4) version of Symfony. I have unpacked it and put it in the directory “/home/maurits/public_html”. In “app/AppKernel.php” I moved the “AcmeDemoBundle” to the production section and in “routing.yml” I added the “_acme_demo” route that was originally in “routing_dev.yml”.

Test environment

I tested on my i5-2300 CPU with 16GB of RAM and an SSD. To run a benchmark, I installed on my Ubuntu 14.04 both Apache 2.4 with PHP 5.5 and Nginx 1.4 with HHVM 3. I used Apache Bench (ab) to test the “/demo” path on both web servers. In Apache, I disabled XDebug and enabled Zend OPcache.

Install and configure HHVM 3 with Nginx 1.4 for Symfony

For HHVM, we find pre-built (64-bit) packages listed on Github. This is how you install them on Ubuntu 14.04:

wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/ubuntu trusty main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get install hhvm

First we install Nginx from the Ubuntu 14.04 repository using:

sudo apt-get install nginx

Now we configure Nginx using the “normal” FastCGI configuration:

server {
    listen             8080;
    server_name        sf2testproject.dev;

    root /home/maurits/public_html/web;

    location / {
        # try to serve file directly, fallback to rewrite
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        # rewrite all to app.php
        rewrite ^(.*)$ /app.php/$1 last;
    }

    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
}

Single request

When doing a single request and analyzing the response times using the Firebug “Net” panel there is no noticeable difference. This is probably because the threads do not have to compete for CPU. So let’s skip this and do some load testing.

Apache Bench results (Symfony 2.4 / Apache 2.4 / PHP 5.5)

maurits@nuc:~$ ab -c 10 -n 2000 http://sf2testproject.dev/demo/
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking sf2testproject.dev (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests

Server Software:        Apache/2.4.7
Server Hostname:        sf2testproject.dev
Server Port:            80

Document Path:          /demo/
Document Length:        4658 bytes

Concurrency Level:      10
Time taken for tests:   9.784 seconds
Complete requests:      2000
Failed requests:        0
Total transferred:      9982000 bytes
HTML transferred:       9316000 bytes
Requests per second:    204.42 [#/sec] (mean)
Time per request:       48.918 [ms] (mean)
Time per request:       4.892 [ms] (mean, across all concurrent requests)
Transfer rate:          996.36 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       3
Processing:    18   49  10.9     50      90
Waiting:       15   41  10.1     41      78
Total:         18   49  10.9     50      91

Percentage of the requests served within a certain time (ms)
  50%     50
  66%     54
  75%     56
  80%     58
  90%     62
  95%     65
  98%     69
  99%     73
 100%     91 (longest request)

Apache Bench results (Symfony 2.4 / Ningx 1.4 / HHVM 3)

maurits@nuc:~$ ab -c 10 -n 2000 http://sf2testproject.dev:8080/demo/
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking sf2testproject.dev (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests

Server Software:        nginx/1.4.6
Server Hostname:        sf2testproject.dev
Server Port:            8080

Document Path:          /demo/
Document Length:        4658 bytes

Concurrency Level:      10
Time taken for tests:   4.678 seconds
Complete requests:      2000
Failed requests:        0
Total transferred:      9900000 bytes
HTML transferred:       9316000 bytes
Requests per second:    427.50 [#/sec] (mean)
Time per request:       23.392 [ms] (mean)
Time per request:       2.339 [ms] (mean, across all concurrent requests)
Transfer rate:          2066.52 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     8   23  11.5     21      84
Waiting:        8   22  11.3     20      84
Total:          8   23  11.5     21      84

Percentage of the requests served within a certain time (ms)
  50%     21
  66%     26
  75%     30
  80%     32
  90%     39
  95%     46
  98%     54
  99%     58
 100%     84 (longest request)

Conclusion

On both setups, I did not do any optimization. I just installed and ran the benchmark. It seems that Symfony 2.4 on HHVM is about twice as fast as on PHP 5.5. In a real life setup this means you need half the machines. This seem like a good cost reduction at first, but it may not be as good as it looks. I believe that in reality most Symfony applications are doing database and/or API calls. These will not be faster when using HHVM, since HHVM only speeds up PHP execution. This is why I think that the difference will be smaller (than a factor 2) for a real life Symfony application. What do you think?

Share

10 tools for PHP developers in Ubuntu 14.04

real_programmers
To convert your Ubuntu 14.04 into a powerhouse for software development for PHP, you need to install some developer tools from the rich set of available software packages. I have made a top 10 of my favorite developer tools.

1) Install Eclipse 3.8 as a complete IDE

Altough everybody I know prefers the JetBrains IDE’s, I am still a sucker for free (as in speech) software. I think Eclipse and the various distributions of Eclipse you can download are just as good, when properly configured.

sudo apt-get install eclipse

2) Install Geany 1.23 as a lightweight IDE

I also often find myself using a lightweight IDE. After using way too much “gedit” I have recently (re)discovered “Geany” and I feel it is perfect. With the following commands you install it with a good set of plugins.

sudo apt-get install geany geany-plugins

You can find some Geany color schemes on Github that are worth installing as well.

wget https://github.com/downloads/codebrainz/geany-themes/geany-themes-1.22.2.tar.bz2
tar -xvf geany-themes-1.22.2.tar.bz2
mkdir -p ~/.config/geany/colorschemes/
cp geany-themes-1.22.2/colorschemes/* ~/.config/geany/colorschemes/
rm -Rf geany-themes-1.22.2 geany-themes-1.22.2.tar.bz2

3) Install MariaDB 5.5

MariaDB is the replacement for MySQL now that Oracle has acquired it. This is comparable to the replacement of OpenOffice with LibreOffice after Oracle got their hands on it.

sudo apt-get install mariadb-server

4) Install PostgreSQL 9.3

PostgreSQL may be the most powerful database around.

With PostgreSQL 9.2, query results can be returned as JSON data types. Combined with the new PL/V8 Javascript and PL/Coffee database programming extensions, and the optional HStore key-value store, users can now utilize PostgreSQL like a “NoSQL” document database, while retaining PostgreSQL’s reliability, flexibility and performance. (source)

I feel you should always consider using it before choosing any “NoSQL” or “documents-based” database.

sudo apt-get install postgresql pgadmin3

Do not forget to set the root (postgres) password.

sudo -u postgres psql postgres
ALTER USER postgres WITH PASSWORD '<password>';
\q

5) Install Apache 2.4 + PHP 5.5 + modules

Install Apache and the default method (mod_php) to serve the new PHP 5.5.

sudo apt-get install apache2 libapache2-mod-php5

Install PHP 5 support for MariaDB and PostgreSQL.

sudo apt-get install php5-mysql php5-pgsql

Some PHP packages for Symfony development.

sudo apt-get install php5-intl php5-sqlite

PHP packages for cURL and XDebug.

sudo apt-get install php5-curl php5-xdebug

Optional PHP packages for creating images (GD), doing geolocalization on IP address (GeoIP), encryption and Redis/Memcache caches.

sudo apt-get install php5-gd php5-geoip php5-mcrypt php5-redis php5-memcache php5-memcached

Now enable mod_rewrite and restart Apache to make sure everything is loaded.

sudo a2enmod rewrite
sudo service apache2 restart

6) Install Adminer 4

PhpMyAdmin is a very popular web-based database management tool. Adminer is a drop in replacement that beats it on almost all points. You can install the latest version of Adminer using:

sudo mkdir /usr/share/adminer
sudo wget -O /usr/share/adminer/latest.php "http://www.adminer.org/latest.php"
sudo ln -s /usr/share/adminer/latest.php /usr/share/adminer/adminer.php
echo "Alias /adminer.php /usr/share/adminer/adminer.php" | sudo tee /etc/apache2/conf-available/adminer.conf
sudo a2enconf adminer
sudo service apache2 reload

Now go here to run it: http://localhost/adminer.php

In the future you can easily update Adminer using:

sudo wget -O /usr/share/adminer/latest.php "http://www.adminer.org/latest.php"

7) Install Git

Install the Git source code versioning system:

sudo apt-get install git

Check out this great Git cheat sheet.

8) Install some compilers and build tools

With the following commands you get most common compilers and build tools.

sudo apt-get install gcc build-essential libc6-dev autoconf automake

9) Install the Microsoft fonts

There are always people that rely on the standard Microsoft fonts (like Arial). Although this is bad practice and HTML5 allows you to embed fonts, still it may solve some problems to just install these:

sudo apt-get install ttf-mscorefonts-installer

10) Upgrade your Office experience

A developer also needs to read or write some documentation or specifications. Libreoffice Writer is IMHO better than the real thing (Microsoft Word).

sudo apt-get purge gnumeric abiword
sudo apt-get install libreoffice

Feedback?

Did we miss some really important package? Let us know in the comments.

Share