Internet Of Things with Raspberry Pi – 2

This is a follow-up to my previous tutorial Internet of Things with Raspberry Pi – 1. (If you’re not familiar with web servers, PHP coding and the basic concepts of IOT, you should probably go through part 1 first.)

In the previous tutorial, we set up an Apache 2 web server on the Raspberry Pi and created a web page for it, from which we could control an LED.

In this tutorial, we’ll be adding controls for playing videos and songs on the Raspberry Pi using the OMX media player.

The setup

Step 1:

Connect the following to the Raspberry Pi as shown in the pictures:

Power supply

HDMI (if your screen/monitor doesn’t have an HDMI port, you can use a VGA to HDMI converter)

Ethernet (to internet)

USB Keyboard and mouse (unless you’re accessing the Pi over SSH or VNC)

Step 2:

Run the following command to install OMXplayer on the Raspberry Pi:

sudo apt-get install omxplayer

You’ll be using this player to play media on your Pi.

Step 3:

Start by downloading two to three nice songs and shorten their file names to something small. (e.g. ‘Where the river flows by Scorpions’ can be shortened to just ‘WhereTheRiverFlows’) Long names also work, but they take too much time to type when coding. Now put all the songs into a folder called ‘songs’. Make this folder in ‘/home/pi’.

Step 4:

Similarly, create a folder in ‘/home/pi’ called ‘videos’ and add a video in it. Follow the same steps as earlier for naming it.

Step 5:

Run the following commands to open your current web page code:

sudo nano /var/www/index.php

Add the new parts as shown below or just copy this code to the index.php file: