Saturday, January 04, 2014

Firing up Raspberry PI omxplayer using Java code

The Pi has an excellent HDMI media player called omxplayer but it fails short in terms of interface to interact with , for starters by default you can interact with it only via command line for example the following command will play an mp4 file:

omxplayer -r -o hdmi myVideoFile.mp4

I have been working on a Spring Boot Restful application to be able to control the OMXPlayer on the Raspberry Pi . For now my Spring Boot application which runs on Raspberry Pi itself only provides a means to play a specified file and to stop the omxplayer .

Now whats interesting is that Spring Boot provides an easy means to quickly put up an executable jar file which can expose Restful endpoints . So next step is how to call the command above from Java on the Pi which is basically a unix system .


Strangely as it sounds it took me a while to figure this out whilst navigating through stackoverflow , well its not that complicated.

All you need is a ProcessBuilder :

ProcessBuilder pb = new ProcessBuilder("bash", "-c", "omxplayer -r -o hdmi myVideoFile.mp4");
Process process = pb.start();

StringBuffer sb = new StringBuffer();

BufferedReader reader = new BufferedReader(new InputStreamReader(

String line = reader.readLine();
while (line != null) {
line = reader.readLine();

The ProcessBuilder will execute a Java process which in turn execute your omxplayer play command on the unix system , the output of this operation is returned back to the sb StringBuffer . 


Currently I couldn't find an elegant way to stop the playback though so what am doing is that am literally killing the process using the kill command e.g :

kill -9 3144

where 3144 is some PID (Process ID) which you need to capture to kill the process (executed through the process builder) , note that each time you fire off the omxplayer it will have a different ID.

Note that I use the following  command to get the PID 

ps -ef |egrep \"/usr/bin/omxplayer.bin

This will give you something as shown in the screenshot below :

Note that in either case you can use the same codes above to execute the :

1. codes that will return you the output from which you can then extract the PID 
2. execute the kill command to stop the process 

So that's as simple as it is for now.

Thursday, January 02, 2014

Spring Boot on Raspberry Pi

Update-4th Jan 2014 : OMXPlayer start and stop now working through Rest Interface

I've successfully managed to deploy a minimal Spring Boot application which contains only one controller to interface with the Pi's omxplayer on a Raspberry Pi device. Although I managed to deploy the Spring Boot application properly and the rest interface is working , interaction with the omxplayer is still work in progress :) !

Below you will find the steps to get started installing JAVA and your existing Spring Boot application on the PI.

Installing Java on the PI

All that is really required as a pre-requisite is that JAVA needs to be installed and this is achieved with the following command on the PI:

sudo apt-get update && sudo apt-get install oracle-java7-jdk

The command will update your Raspberry Pi OS in my case its Raspbian and afterwards will install JAVA 7 embedded on your device its a 70+ MB download , so took less than 12 minutes in Mauritius .

Then once downloaded the install will unpack by itself here you need to have a little dose of patience , remember the Raspberry is not like your standard pc , give it some time :) .

Once everything has been installed go to your ssh client on Mack or Putty on Windows and execute the following command to check whether Java has been installed properly:

java - version

Running your Spring Boot Application

This section assumes that you already have a working Spring Boot application the one I've deployed merely exposes a Rest interface but does not have to persist anything in a database .

Note that there are lots of examples already available from the GIT hub check the webui one here :

A simple getting started guide is also available here:

I've decided to use Jetty as the embedded servlet container as it is much lighter than Tomcat , so you will need to add the following within your maven POM file are adapt it to your gradle build if thats what your using.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""

Note that the jackson-databind is required for exposing your Rest interface.

Once you are satisfied with your spring boot application and have tested that it is working properly its time to deploy the app on your Raspberry .

Get hold of your favorite FTP program and transfer generated Jar file to your /home/pi directory for example.

Then all you need to do is to execute the jar file as follows:

java - jar your-jar-filename-xxx.jar

where your-jar-filename-xxx needs to be substituted with the name of your generated jar file.

My application as mentioned was just a couple of classes big but it did take around 82 seconds to be installed , however once installed it ran without any issues , so this is promising. 

Ok that's it for now , I need to work a bit more on my Raspberry application such as I can finally provide a RESTful interface to the omxplayer , one thing for sure is that  Spring Boot makes deploying a webserver on the raspberry device something as easy as executing a JAR file.

Wednesday, January 01, 2014

Cyclone warning class 2 - Bejisa

Update 2-Jan-2014  9:05pm: There is now no cyclone warning in Mauritius , theoretically normal office day tomorrow !

Update 2-Jan-2014  6:30pm - A cyclone warning class 2 is still in force in Mauritius .  Adding some photos which are circulating on Facebook. Outside there are still sudden bursts of rain , weather is heavily cloudy in Port-Louis.

Picture of waves hitting Caudan Waterfront in Port-Louis

Careless people with small children enjoying themselves at the beach 

Branches/Trees have falling down near by car parking

Update 2-Jan-2014 12:17pm - Raining a lot in Port-Louis at the moment for some 30 minutes now looks like its  going to continue like that for a while now , also the cyclone is moving past Mauritius onto Reunion island , until something really unexpected happens chances are that tomorrow its normal working day :) !

Update 2-Jan-2014 8:08 am - Just had some heavy rainfall some moments ago in Port-louis , so hard that I could not open the window to take a picture as the rain was gushing in  , now its gone back to be more calm but there will be intermittent rainfall throughout the day. Thankfully its not hot the temperature is 23 degrees Celcius so its more or less bearable.

Update 2-Jan-2014 6:00 am - There is still a cyclone warning class 2 in force in Mauritius .

In Port-Louis the weather is cloudy there are some strong winds and some rain but nothing apart from that I cannot see any damage to trees etc.  From the looks of the updated trajectory however it appears that to be curving towards our friends in Reunion island either case for them the 3rd is going to be stormy.

Picture Source L'Express

Original Post 1-Jan-2014 -Mauritius has gone in cyclone warning class 2 looking at the satellite imagery it is highly likely that we will go in cyclone warning class 3 probably somewhere tomorrow afternoon and possibly not cyclone warning on the 3rd of January but this is only guess work , it might just be that cyclone turns a bit to the right and it would go over Mauritius rather than down straight to Reunion island.

                                                           Picture Source L'Express

The latest bulletin can be found here:

By the way if you are in Reunion be careful and take all your necessary precautions as in current downward progression it is highly likely that the eye of the cyclone will pass straight over the island according to the predictions of the Mauritius Meteorological Station (MMS).

However there is one thing which I was finding weird in the last prediction from MMS when there was a cyclone warning class 1 , the path of the eye of the cyclone was between Mauritius and Reunion which appeared really odd to me since the cyclone was really far off. I was thinking it would go rather downwards to the south.

Now with the latest satellite imagery I can see that at the actual path of the cyclone is indeed straight to the south which makes sense but then there are a lot of factors that affect the trajectory of a cyclone.

Lets see how things goes during the night hopefully there will not be any casualties and only wind and rain .

Motorcyclists wear uniforms now

Went to buy some rotis in the morning in Port-louis and it immediately struck me that something had drastically changed on our roads.

Dozen of brightly colored individuals were riding their bikes whilst flashing colors ranging from bright orange to lemon yellow. This is due to a law that has been passed that makes wearing those reflectors compulsory even in daylight as of 1st of Jan 2014.

Note that in Port-louis there are a lot of policeman so better wear that reflector if your using your bike.

I personally think its a good move to protect 2 wheelers although definitively not very sexy ! :)

Poisson Salay

A friend just shared this clip on his facebook wall,  really appreciate it as it looks like its a low budget production but the song is very catchy !