Posted on

RPI Alternative to Google Text to Speech

Installing Pico TTS

  • Open and check /etc/apt/sources.list if it contains the following. Remove the “#” if they are commented out.

deb wheezy main contrib non-free rpi
deb-src wheezy main contrib non-free rpi

  • Update the list of available packages and their versions

sudo apt-get update

  • Install some dependencies for the compilation

sudo apt-get install fakeroot debhelper automake autoconf libtool help2man libpopt-dev hardening-wrapper

  • Install fakeroot

mkdir pico_build
cd pico_build
apt-get source libttspico-utils

  • Prepare the packages

cd svox-1.0+git20110131
dpkg-buildpackage -rfakeroot -us -uc

Compiling the packages will take 15-20 minutes to complete.

  • If there is no error during the compilation, you should find at least 4 packages in the pico_build folder.

cd ..



  • We just need 3 out of 4 libraries and this have to be installed in order.

sudo dpkg -i libttspico-data_1.0+git20110131-2_all.deb
sudo dpkg -i libttspico0_1.0+git20110131-2_armhf.deb
sudo dpkg -i libttspico-utils_1.0+git20110131-2_armhf.deb

  • Pico TTS engine is now ready.


Testing Pico TTS

  • Test the library by typing

pico2wave -w test.wav “Yeey, it works! “
aplay test.wav

  • Create whatTimeIsIt.php and insert the following script

vi whatTimeIsIt.php

$tempAudioFile = “temp.wav”;
$currentTime = date(‘h’) * 1;
$message = “Its” . $currentTime . “o clock”;
exec(“pico2wave -w $tempAudioFile ‘$message’ && aplay $tempAudioFile && rm $tempAudioFile”);

  • Change access permission

chmod 644 whatTimeIsIt.php

  • Execute the script

php whatTimeIsIt.php

  • If you want, you can create a cron job to execute the script automatically every hour.

crontab -e

Then insert:

0 * * * * sudo /usr/bin/php ~/Scripts/whatTimeIsIt.php

Change the text in blue according to where you saved your script.

Posted on

Fresh Installed Raspbian from NOOBS

Getting started with NOOBS… follow the instructions here:

1.) Update the list of available packages and their versions

sudo apt-get update

2.) Install the newer versions of the packages

sudo apt-get upgrade


sudo apt-get dist-upgrade to get the new OS release

Also be aware that downloaded package files (.deb files) are kept in /var/cache/apt/archives. You can remove these in order to free up space with sudo apt-get clean.

3.) Update RPI’s FW:

sudo rpi-update

4.) Update MOTD (if you want)

  • Remove all text from motd and motd.tail:

sudoedit /etc/motd

sudoedit /etc/motd.tail

  • Remove last login

Find ‘PrintLastLog’ and change its value to ‘no’

sudoedit /etc/ssh/sshd_config

PrintLastLog no

  • Restart SSH

sudo service ssh restart

  • Install TCLSH

Simple shell containing Tcl interpreter

sudo aptitude install tcl

  • Download the customized MOTD script


  • Move the script to the /etc directory

sudo mv motd.tcl  /etc

  • Set Permissions for the Script

This allows all shell users to execute the script at login.

sudo chmod 755 /etc/motd.tcl

  • Integrate New Script into Shell Profile

Force the system to execute the script at user login.

sudoedit /etc/profile

Add following line to end of file


You should be able to see the new motd on you next login.

5.) Install/Setup VNC (tightVNC)

  • Install the server software from the repositories:

sudo apt-get install tightvncserver

  • Initialize the server


  • Adding Tightvnc to the startup


sudo mv tightvncserver-init.txt /etc/init.d/tightvncserver

You may need to change the variable on line 16. It is currently set to pi which is the default username on the Raspberry Pi Debian image. Set this to whatever username you want to login to TightVNC as. Do not put root as the user.

Change the file so it is owned by root (not strictly necessary, but is the standard ownership for init files

sudo chown root:root /etc/init.d/tightvncserver

Make the file executable by running

sudo chmod 755 /etc/init.d/tightvncserver

Add the script to the default runlevels with the command

sudo update-rc.d tightvncserver defaults

TightVNC will now start at startup. I’d recommend you reboot at this point to make sure it’s working, but you can just stop and start if you don’t want to reboot.

You can manually start and stop it using

sudo /etc/init.d/tightvncserver start


sudo /etc/init.d/tightvncserver stop

Note that this is designed for running only one instance of TightVNC on the computer. If you want to be able to start and stop specific instances of TightVNC then you will need to tweak the startup script appropriately.

6.) Configure  your system settings using “raspi-config”

sudo raspi-config

Posted on

Customized Wireless Home Security System

Have you thought about installing a home security system, but hesitated because it’s expensive and you don’t think that you really need it? You are not alone. 🙂

Installing home security system can be costly, but not installing one could cost you even more. The biggest reason why you should consider is that it offers protection to you and your loved ones, your home, and your treasured possessions.

There are many types of home security systems available in the market today. There are systems specifically designed for surveillance and recording purposes, and there are systems that provide more on detection and reporting. Like any other device, cost varies according to its features, efficiency, accuracy, resolution, form factor, etc. It’s hard to choose a system that is right for you off the shelf.  That is the reason why most people would prefer to sign contract with home security systems provider that offers customized/tailored fit home security solutions. But not me. 🙂

In this blog, I would like to share how to build our own customized home security system using open-source hardware and software, and a USB camera.

There are actually quite a number of posts related to this out there that does the same thing but programmed differently, but I like the way Marc-Olivier Schwartz put it in one of his posts.


We are going to design here a system that has the following basic features:

  • Monitors and detects for movements.
  • When movement is detected, it will automatically take a snapshot of the event, save it locally, upload it to the cloud, then remove the local copy of the snapshot to optimise your SD card capacity.
  • On certain conditions, takes video and streams them as M-JPEG via HTTP locally or send the stream to YouTube so you can view the live streaming anywhere.

Hardware Needed

Required Parts

  • 1x Arduino Yun (with power supply)
  • 1x micro SD Card (at least 1 GB)
  • 1x USB video class or UVC Camera
  • 1x PIR Sensor
  • 1x Pushbutton Switch to trigger and stop video stream
  • 1x 220Ω 1/4W pull down resistor for the pushbutton switch
  • Jumper Wires

Optional Parts (used for debug and to display status)

  • 1x Tri-color LED
  • 3x 100Ω 1/4W Resistors
  • 1x 16×2 Alphanumeric LCD
  • 10KΩ Potentiometer
  • Additional jumper wires

Web Service Needed

  • Dropbox – Cloud storage service
  • Temboo – A layer that acts as an interface between the Dropbox’s API and your Yun.
  • YouTube – YouTube Live Event to broadcast our video stream live.

Setting up the Hardware

Schematic Diagram


Breadboard Layout


 Actual Setup



Mount and connect all the parts according to the schematic diagram above, insert the micro SD card, then connect the camera to the USB port of the Yun and power up the board.

For the USB camera, you can refer to the following for the List of USB video class webcams.

Setting up Temboo Application and Dropbox API

The first service that we need to set is Temboo – a library of programming processes (virtualised codes) that makes the life of the developer, like us, a lot easier. In this case, Temboo will act as an interface layer between the Arduino Yun and Dropbox.

Go over to Login to your account if you already have, else, sign up for a free account. Once you are in, click “Account”, then Applications and create New Application. Take note of your account name, the name of the application that you just created and your API key, you will need them later.

Then go over to to download the latest Temboo Python SDK. Once downloaded, extract the folder to the micro SD card. Yes, correct :), you need to remove the SD card from the Yun, plug it in to your PC, copy the folder over to the root directory, then insert the SD card back to the Yun.

The next service that we need to set is Dropbox. If you don’t have a Dropbox account, you need to create one.

 Then go over to the developers section of Dropbox to create an app for you to be able to integrate with Dropbox.

Click “Create App” and follow the snapshot below.


Once you have create your app, write down the “App Key” and “App Secret” because these will be your input in the next step.

Go over to, then input the Dropbox App Key and App Secret to get the next set of data for the next authorization process.

You will be asked to visit a URL to grant your application access to your Dropbox data. Write down the OAuthTokenSecret and the CallbackID. You’ll need them, together with the previous two data (App Key and App Secret) to run the final authorization.

Go over to, input the four data you’ve saved previously to get the Dropbox Access Token, Access Token Secret, and UserID associated with the access token and secret. Write them down because you’ll need them later.

Then the last service that you need to set is Youtube. You need to have a google account to stream videos on Youtube. You can create one from here:

Setting Up your Arduino Yun

The details on how to connect and setup your Yun to your network will not be covered here. It is assumed that your board is already set and properly connected to your WiFi network.

We are going to login to our Yun using SSH from a terminal and we’re going to install all the packages needed for our application. We are also going to test the USB camera to see if everything are ok.

Open a terminal and type the following to connect to your Yun via SSH.

ssh root@yourYunName.local

or using your Yun’s private IP address if you know.


 If your connection is successful, you should see some nice ASCII art (default is LININO):


We can now install the required packages. We’ll start with an update of the package manager:

opkg update

UVC drivers:

opkg install kmod-video-uvc

python-openssl package:

opkg install python-openssl

fswebcam utility (we will use this utility to take snapshot (picture) of an event)

         opkg install fswebcam

mjpg streaming library:

opkg install mjpg-streamer

The installation process should be smooth.

Testing the USB Webcam

Since we have all the drivers and dependencies installed, we are now ready to test the webcam. Make sure that the SD card is mounted into the Yun.

cd /mnt/sda1

You should be able to see the Temboo Python SDK folder that you extracted earlier.

To test the camera and take a picture, just execute the following command.

fswebcam test.png

You should see something like this:


You should also see the test.png when you do an “ls”

You can check the picture by removing the SD card from your Yun and open the picture on your PC.

Motion Detection

Now that the infrastructure (both HW and SW) are set, it’s time to add in the program. The program is categorized into two – the microcontroller sketch (FW) that handles the inputs (triggers), LCD and indicators, and the Shell and Python scripts that handles webcam, snapshot, streams and uploads.

You can get all the files needed here:

Motion detection is done in the microcontroller side. We use a passive infrared (PIR) sensor to detect motion by measuring changes in the infrared (heat) levels emitted by surrounding objects. When motion is detected the PIR sensor outputs a high signal on its output pin. We use this change of the pin state to execute “fswebcam” utility to take a snapshot of the event and save in the SD card first.

Upload Snapshots Automatically to Dropbox

After a snapshot is taken, a Python script “” will be executed to upload the snapshot to the Dropbox folder we’ve set earlier. There few items that you need to change in order for the script to work. Now is the time to put all those details that you wrote down earlier to use.

Change the following lines accordingly with your Temboo Application details:

# Declare Temboo session and Choreo to upload files

session = TembooSession(‘ACCOUNT’, ‘APPLICATION’, ‘KEY’)

uploadFileChoreo = UploadFile(session)

Change the following lines accordingly with your Dropbox App details:

# Set inputs





You also need to ensure that the folder of the Temboo Python SDK you extracted earlier in the root directory of the SD card is named “temboo“.

Once the upload process is completed, the sketch will execute another shell command to remove the local copy of the uploaded snapshot.

Streaming Video Locally

In this project, for simplicity, we are going to use a pushbutton switch to trigger (start) and stop video stream. When the switch is pressed the first time, the sketch will execute the “” to initiate mjpg streamer utility to capture JPG frames from a connected webcam and stream it locally via HTTP.

mjpg_streamer -i “ -d /dev/video0 -r 640×480 -f 25” -o “ -p 8080 -w /www/webcam” &

You can change the resolution to the right number for your webcam.

To test if your setup could stream locally, press and release the pushbutton switch. You should be able to see that you the built-in red LED of your Yun is lit up and if your camera has LED, it should lit up also indicating that the camera is used.

Then go to or http://YourYunName.local:8080/stream.html to see the live stream.

You should see something like this:


Press again the pushbutton switch to stop streaming. Your onboard LED and camera LED should be turned OFF.

 Streaming Live Video to YouTube

In order for YouTube to broadcast your live content, you need to send them an encoded stream. YouTube Live provides support for a variety of encoders, but since I’ve tried Wirecast before without issue, we’ll use the same here.

If you don’t have Wirecast yet, you can get the installer here:

If you already have, don’t launch it yet. Create a new live event first in YouTube.

Once done, launch Wirecast and setup as follows:



  1. Go to Sources and click New Web Stream… Start demo
  2. Select “HTTP” for protocol and “Motion JPEG” for “Format Options”
  3. Tick “Live Stream”
  4. Put http://YourYunIP:8080/?action=stream for URI. You can also use your home network’s public IP provided that you have forwarded port 8080 to your Yun’s private IP.
  5. Click  the “Connect” button. Video stream should appear in the video frame.
  6. Click the “Stream” button on the top left corner. It will ask you for destination. Choose “YouTube”. Then authenticate using your Google Account.
  7. Choose your event and click OK.
  8. Look for the Master Layer and click the + sign to add camera. Choose the Web Stream Source that we configured earlier.
  9. Select the source. You should see the video.


Now, go back to YouTube and click the Live event control room, you should see something like this:


Click Preview. It may take a while before you will be able to click “Start Streaming”. Once done, you will be able to view your live video like this:


Congratulations! You just completed your first Customized Home Wireless Security System hack!

There are so many things that you can do in order to make this base design more interesting. For example, you can add feature to automatically turn ON your light or send you a tweet or SMS when motion is detected. You may also want to program the device to monitor only at a specific time period. There are endless tweaks that you can do.

Snapshots of the working setup

working1 working2

working3 working4

Posted on

OpenVPN Configuration on RPI

OpenVPN is an open-source software application that implements virtual private network (VPN) techniques for creating secure point-to-point or site-to-site connections in routed or bridged configurations and remote access facilities. It uses a custom security protocol that utilizes SSL/TLS for key exchange. It is capable of traversing network address translators (NATs) and firewalls.

VPN gives extremely secure connections between private networks linked through the Internet. It allows remote computers to act as though they were on the same secure, local network. Allows you to be at home and access your company’s computers in the same way, as if you were sitting at work, and vice versa.


On RPI (Server Configuration):

For Raspbian or similar distribution

Step 1. Switch to root.

WARNING: Mistakes while in superuser mode could lead to data loss or the deletion of important system files.  Please double-check your command before hitting the “Enter” key.

Step 2. Update the list of available packages and their versions

apt-get update

Step 3. Install OpenVPN and OpenSSL

apt-get install openvpn openssl

Step 4. Change the current working directory to /etc/openvpn and copy the easy-rsa templates from /usr/share/doc/openvpn/examples/easy-rsa/2.0

cd /etc/openvpn

cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0 ./easy-rsa

Step 5. Now open easy-rsa/vars and update the following line


export EASY_RSA=”`pwd`”


export EASY_RSA=”/etc/openvpn/easy-rsa”

nano easy-rsa/vars


Watch the double quotes! “Ctrl + x”, then “y” to save and exit.

Step 6. Perform the following steps.

Change the current working directory to easy-rsa:

cd easy-rsa

Execute vars:

source vars

Refresh /etc/openvpn/easy-rsa/keys:


Generate 1024 bit RSA private key template

./pkitool –initca

Create symbolic link for openssl.cnf:

ln -s openssl-1.0.0.cnf openssl.cnf

Step 7. Build the client-server keys. For beginners, it is recommended to hit the “enter” key (use default answers) on all questions. Answer “y” on all [y/n] questions.

./build-ca OpenVPN

./build-ca OpenVPN

The next command is going to take few minutes. Be patient :).


Step 8. Go back to /etc/openvpn directory

cd ..

Create a new file “openvpn.conf” with the following content:

dev tun

proto udp

port 1194

ca /etc/openvpn/easy-rsa/keys/ca.crt

cert /etc/openvpn/easy-rsa/keys/server.crt

key /etc/openvpn/easy-rsa/keys/server.key

dh /etc/openvpn/easy-rsa/keys/dh1024.pem

user nobody

group nogroup




status /var/log/openvpn-status.log

verb 3


push “redirect-gateway def1”

#set the dns servers

push “dhcp-option DNS”

push “dhcp-option DNS”

log-append /var/log/openvpn


nano openvpn.conf 


You can change the DNS-servers to any DNS you like.

Again watch if the double quotes did not change into some other characters after you copy and paste it. “Ctrl + x”, then “y” to save and exit.

Step 9. Configure the iptables for OpenVPN:

echo 1 > /proc/sys/net/ipv4/ip_forward

Get the Pi’s private IP address


Execute this:

iptables -t nat -A POSTROUTING -s -o eth0 -j SNAT –to [Pi’s IP Address]

Step 10. Enable pocket forwarding:

cd ..

nano sysctl.conf

Uncomment net.ipv4.ip_forward=1 line to enable packet forwarding for IPv4

change from





“Ctrl + x”, then “y” to save and exit.

Step 11. Add to rc.local to run the iptables command when the Pi boots.

nano /etc/rc.local

Add the following lines just above “exit 0”

iptables -t nat -A INPUT -i eth0 -p udp -m udp –dport 1194 -j ACCEPT

iptables -t nat -A POSTROUTING -s -o eth0 -j SNAT –to-source [RASPBERRY IP ADDRESS]


“Ctrl + x”, then “y” to save and exit.

Step 12. Start OpenVPN daemon:

/etc/init.d/openvpn start

Step 13. Change the current working directory to /etc/openvpn/easy-rsa/keys and create raspberrypi.ovpn.

cd /etc/openvpn/easy-rsa/keys

Create raspberrypi.ovpn and add the following content:

dev tun


proto udp

remote [Raspberry PI IP Address] 1194

resolv-retry infinite




ca ca.crt

cert client1.crt

key client1.key


verb 3

Replace “[Raspberry PI IP Address]” with your Pi’s private IP address, DNS or DDNS.

nano raspberrypi.ovpn


“Ctrl + x”, then “y” to save and exit.

Step 14. Now we need to copy the keys from “/etc/openvpn/easy-rsa/keys” to a non-root folder. It doesn’t matter where. In this example we’ll copy it in  /home/pi/openvpn directory.

tar czf openvpn-keys.tgz ca.crt ca.key client1.crt client1.csr client1.key raspberrypi.ovpn

mkdir /home/pi/openvpn | mv openvpn-keys.tgz /home/pi/openvpn/

chown pi:pi -R /home/pi/openvpn

Exit from superuser mode:


Step 15. Restart OpenVPN daemon:

/etc/init.d/openvpn start

On clients:


  • Download the installer from
  • Start with the installation. Select the default options and continue.
  • Once the installation is complete, copy the openvpn keys from the server (openvpn-keys.tgz) and extract it in C:\Program Files\OpenVPN\config.

You can also access the config folder thru the Start Menu

click on [Start]->[All Programs]->[OpenVPN]->[Shortcuts]->[OpenVPN configuration file directory].


  • Connect to VPN.


  • Verify if VPN is indeed connected.


Type the on your browser. It should show your servers public IP address.



  • Download and install the OpenVPN Connect client (by OpenVPN Technologies) from the App Store.


  • Launch the OpenVPN app when it’s done downloading, and tap “Using iTunes Sync, select your device, go to OpenVPN under the “apps” tab, and drop your .ovpn and related cert/key files into the file sharing window.”
  • Connect your iPhone, iPod, or iPad to your computer with the provided cable.
  • Open up iTunes if it didn’t start automatically.
  • Click on your Phone in the left pane of iTunes.
  • Click on Apps on the top row, scroll down to “File Sharing”, and click on the “OpenVPN” app.
  • Click Add File…
  • Now back to your iOS (iPhone, iPod, iPad) device, you should see the profile were transferred successfully. Tap the green plus (+)  and drag the connect/disconnect bar to connect.
  • Open a browser and type Check if the returned IP is the public IP address of your VPN server.


Posted on

Customized RPI MOTD

1.Remove Default MOTD

Remove all text from motd and motd.tail

$ sudoedit /etc/motd
$ sudoedit /etc/motd.tail 

2. Remove last login

Find ‘PrintLastLog’ and change its value to ‘no’

$ sudoedit /etc/ssh/sshd_config

PrintLastLog no

3. Restart SSH

$ sudo service ssh restart

4. Install TCLSH

Tclsh is a useful shell application which evaluates Tcl commands in a file.

$ sudo aptitude install tcl

5. Create new MOTD script

Change directory to /etc

$ cd /etc

Download a copy of the customized motd script

$ sudo wget

6. Set Permissions for the Script

This allows all shell users to execute the script at login.

$ sudo chmod 755 /etc/motd.tcl

7. Integrate New Script into Shell Profile

This forces the system to execute the script at user login.

$ sudoedit /etc/profile

Add following line to the end of the file