Thursday, July 23, 2015

Docker first steps

Currently looking at implementing DevOps based solution at work and whenever you hear DevOps one of the most famous trending buzz work is Docker .



I decided to give it a try on a Windows 7  pc , basically you need to follow the tutorial to install Boot2Docker which will is simple enough in terms of just being an exe that will kick start a stripped down Linux instance on your Windows pc or Mac .

The first thing you need to do is try out this simple command:

docker run hello-world


The picture below explains syntax within the commands:
Now the first issue I got however that no Docker images were being downloaded , i just kept getting i/0 timeout errors . Figureout that something might be blocking the images being downloaded.

A simple googling provided a rapid answer that the problem had to do with Cisco Connect Anywhere , if you have it installed either you need to exit it ( and close from system tray ) or you  can follow the instructions from this stackoverflow query:

http://stackoverflow.com/questions/26686358/docker-cant-connect-to-boot2docker-because-of-tcp-timeout

Sure enough once Cisco Connect Anywhere was closed i was able to download the image.

Sunday, April 12, 2015

Control GPIO Pins on Raspberry Pi 2 using Webiopi

I recently started working on a robot controlled with my Raspberry Pi , it is at the moment kind of rover which is attached to my Raspberry Pi through a long umbellical cord of wires. There are 2 servos to which my Raspberry Pi sends out data through an L298N H-Bridge which makes the Robot "Rover" wheels  move either backward or forward .

I managed to also write a python code to send signals to the servers which looks a bit like this :

-------------
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)

GPIO.output(7,True)
time.sleep(1)
GPIO.output(7,False)
GPIO.output(11,True)
time.sleep(1)
GPIO.output(11,False)
GPIO.output(13,True)
time.sleep(1)
GPIO.output(13,False)
GPIO.output(15,True)
time.sleep(1)
GPIO.output(15,False)
GPIO.cleanup()


--------------

Now that is great but what would have been better would be to access to the GPIO pin remotely via a REST API for example and here is where Webiopi kicks in which basically provides you a WEB and a REST interface to connect to you GPIO pins of your PI :
https://code.google.com/p/webiopi/wiki/INSTALL  

As a first setup you need to follow the instructions from the Webiopi install page above .

Note: that current version ,  WebIOPi-0.7.1 ,didn't work straight off with my Raspberry Pi 2 I had to do the following changes to the following c files  once the Webiopi setup was completed:

1.python/native/cpuinfo.c,change "BCM2708" to "BCM2709";
2.python/native/gpio.c, change "#define BCM2708_PERI_BASE 0x20000000" to "#define BCM2708_PERI_BASE 0x3f000000";
3.run setup.sh again.

The above solution was found from RaspberryPi forums .

Now you should be up and running after having re-run the setup for WebIOPI. You launch the server using command:

sudo /etc/init.d/webiopi start

Then you go to navigate to the following location on your PI :

http://IP_ADDRESS_OF_YOUR_PI:8000/

Note that you can get the IP_ADDRESS_OF_YOUR_PI using ifconfig command .

To quickly test the setup navigate to :
http://IP_ADDRESS_OF_YOUR_PI:8000/app/gpio-header

For those pins on which servos are connected change them from IN to OUT  and click on the number corresponding to the pin to execute .


Weaved

Note that WebIOPI is supported by Weaved which provides you to install a package on your Raspberry PI that allows you to control your RaspberryPi WebIOPI from anywhere as long as  you and your PI are connected to the internet .

What nice is that this is a free service and I justed it works .

https://developer.weaved.com/portal/members/betapi.php


Sunday, September 21, 2014

Starting Chromium on the PI in full screen mode

OK this is something fairly easy but do remember that you will do first change your settings on raspi-config to boot on desktop:

1. Step one enter the following command , sudo raspi-config
2. The in the menu select the sub menu to choose where you boot to
3. Select to boot to desktop

Now that has been done you follow the commands to be added as described in the following web page (its all straight forward):

 http://www.danpurdy.co.uk/web-development/raspberry-pi-kiosk-screen-tutorial/ 

Then you just reboot using sudo reboot .

Saturday, July 12, 2014

NodeJS / Express and Restful API on the PI

Am now looking at how to provide a restful interface for the PI using NodeJS thankfully there was already a blog entry that explained how to get started with exposing a restful interface ( GET , POST , DELETE) using NodeJS express.

So if you are like me and want to have something clean and easy that gets you up and running check out the following :
http://blog.modulus.io/nodejs-and-express-create-rest-api

All the codes work seamlessly on the Raspberry PI .

I also found a NodeJS plugin which seems very promising to integration with omxplayer at the following link:
https://github.com/vabatta/omx-manager#basicusage

I have thus managed to integrate a REST API on the PI that allows me to Post a Request to play a file and it actually calls omxplayer and the video file is played on my HDMI TV.

I will post a sample Express NodeJS file once I have something working well with basic features e.g

1. Controls for pausing , forward etc..
2. Availability to display currently playing file in list
3. Looping
4. Amount of time remaining (no idea if this is achievable)
5. etc..

Saturday, July 05, 2014

No Audio on Raspberry PI

If for some reason you are not getting any audio through omxplayer on your Raspberry Pi , try the following steps:


  1. Execute:  sudo nano /boot/config.txt
  2. Uncomment line:  hdmi_drive=2
  3. Re-start your Raspberry Pi such as it reboots
  4. Connect to your PI again and try to play a file e.g  omxplayer -o hdmi /home/pi/myNAS/myShare/The.Big.Bang.Theory.mp4
The important thing is to use the -o hdmi option.



Mounting a NAS Drive on Raspberry Pi

I got my Pi last year in December and I know i went through the painful task of searching for all the options for configuring my Pi to access a NAS (Network Attached Storage) drive. In my case my Transcend 750GB HD is connected to my Orange Livebox .

Today I decided that I would restart from scratch with my PI installation as OMXPlayer somehow stopped working so am writing this up such as others can quickly setup their NAS drive.

First thing you need to create the following directory on your PI :

/home/pi/myNAS/myShare

this is simple as executing :



  1. mkdir myNAS
  2. then cd myNAS
  3. mkdir myShare
Once you've create the directory you need the following information :

  • Location of your NAS storage device e.g //livebox/myNASLocation
  • Username and password to connect to the NAS device e.g myUsername / myPassword
Then login to your raspberryPi and execute the following command:



  • sudo nano /etc/fstab
You will need to specify the mapping for the NAS within this file simply add a line like the following to the file within the nano editor:
  • //livebox/myNASLocation/  /home/pi/myNAS/myShare cifs username=myUsername,password=myPassword,uid=pi  0 0

Obviously you will need to replace :


  1. //livebox/myNasLocation/  
  2. , myUsername with your actual NAS username
  3. and myPassword  with password for your NAS
-with your own values.


Now do a CONTROL+X  to exit nano , enter Y to save and enter on your Return to exit Nano.


Just to make sure you might want to re-open the file to check whether the settings were correctly saved.

Now that we have added the value , the last thing that to do is to mount the NAS , simply enter the following command :


  • sudo mount /home/pi/myNAS/myShare

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 .

Play

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(
p.getInputStream()));

String line = reader.readLine();
sb.append(line);
while (line != null) {
line = reader.readLine();
sb.append(line);
}
-------------------------------------------

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 . 


Stop

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 Spring.io 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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>0.5.0.M6</version>
</parent>
   <groupId>com.your.groupid</groupId>
        <artifactId>your-artifactid</artifactId>
        <packaging>jar</packaging>
        
<properties>
        </properties>
        
<dependencies>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter</artifactId>
                </dependency>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-jetty</artifactId>
                </dependency>
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-webmvc</artifactId>
                </dependency>
        </dependencies>
        <build>
                <plugins>
                        <plugin>
                                <groupId>org.springframework.boot</groupId>
                                <artifactId>spring-boot-maven-plugin</artifactId>
                        </plugin>
                </plugins>
        </build>
</project>

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.