Sunday, March 24, 2013

Send image from Raspberry Pi via Bluetooth

Our next Bluetooth step is to send files between the Raspberry Pi and my Smartphone.

Raspberry Pi to HTC
We have to check which services are available on the Phone:
sdptool browse <MAC of the Phone>
Search for "OBEX Object Push" and remember the Channel. In my case it is: 12.

Next step is to install obexftp:
sudo apt-get install obexftp
Now we can send a file from Raspberry Pi to the Phone. In my case I have downloaded a picture of tux in my home-directory as described here: http://www.acmesystems.it/bluetooth

Enter the following command (don´t forget to use the right channel) and a Bluetooth file receive request should come up on your Phone:





Yeah, tux is on my phone now!

Raspbian Bluetooth USB

Last week I ordered some stuff from amazon:
  • A cheap USB Bluetooth dongle
  • USB Webcam
  • Very small USB Stick 32GB
First I want to try to establish a BT connection between my Raspberry Pi and my Smartphone (HTC Wildfire). To test my new BT dongle, I inserted it in my Laptop (Win7 x64). There I got an device error (Code: 10 cannot start device) - so far so bad.
On my Raspberry Pi, I had to install the necessary software first:
sudo apt-get install bluez
sudo apt-get install bluez-utils
Then we can check if the device is there and scan for devices (Don´t forget to make your Phone etc. visible in your Bluetooth settings). To test if the connection is working, we can use l2ping <MAC of Phone>

That seems to work - nice.
I found most of the infos needed here: http://www.dreamgreenhouse.com/

Wednesday, February 20, 2013

Website accessible via dynamic DNS

To allow access to my website hosted on the raspberry pi, I need a domain name. Also because I am behind a router I will have no fixed public IP. To solve this dilemma we can use a so called dynamic DNS service, which will update our DNS entry with the current public IP of the router. http://en.wikipedia.org/wiki/Dynamic_DNS
Luckily there are several free available dynic DNS providers: http://dnslookup.me/dynamic-dns/
I decided to use no-ip.com because DynDNS is not free any more.

First you need to go to http://www.noip.com/ and register your domain name. Afterwards you need to install the no-ip client software on your raspberry pi. Usually all that it does,is to check your public ip in a specific interval and send this information to no-ip, so they can update the DNS entry.

But because I am using a FritzBox as router, I can configure directly that I want to use a Dynamic DNS provider and it takes care of everything for me (so no need to install anything on my precious pi).
All you have to do, is go to the webinterface of the FritzBox and enter your dynDNS provider, username & password.
It should look something like this:


Save everything, maybe restart your router and wait some minutes. Now you should be able to reach your website under your selected domain name from everywhere in the worl.

Note: After subscribing to no-ip.com it took some hours until my domain name was populated & working - so be a little patient!

Phyton-CGI with lighttpd

Since static html pages are boring and for little girls only, we now want to create our first website with phyton-cgi calls.

Add/change the following in your lighttpd configuration file (/etc/lighttpd/lighttpd.conf):
$HTTP["url"] =~ "^/cgi-bin/" {
        cgi.assign = ( ".py" => "/usr/bin/python" )
}
Create a directoy "/var/www/cgi-bin/" for your phyton scripts, and also make sure that phyton is installed and the binary is "/usr/bin/phyton" - otherwise change according to your setup.
Now we change or index.html file and add a simple form to it:
<form method="GET" action="/cgi-bin/test.cgi">
  <input type="submit" value="Start" name="Start"/>
</form> 
Then we create our phyton file "/var/www/cgi-bin/test.py" with following content:
#!/usr/bin/python
import cgi
import cgitb 
cgitb.enable()  # for troubleshooting
cgi.test()      # cgi test output
 
Now we can go to our website and click on the "Start"-Button, which will call our python-cgi script and outputs a page with all kinds of environment variables etc. It worked!

If you have problems try restarting the lighttpd service and check if you have the rights to read/write/execute stuff in your /var/www/ directory.

More information about phyton & cgi can be found here: http://docs.python.org/2/library/cgi.html

Raspberry Pi as webserver

Now I want to setup a small webserver on my raspberry pi. First we have to choose an appropriate lightweight webserver, because a standard Apache installation seems to big & overkill.
Two small webserver, which seem to be very good and also widely used are:
I heard a lot of good things about nginx, mainly its speed and rewriting abilities, but I decided to use lighttpd just because I found good instructions for it first. Installing:
 sudo apt-get install lighttpd
Configuration:
sudo nano /etc/lighttpd/lighttpd.conf
Check that the following modules are enabled:
server.modules = (
            "mod_access",
            "mod_alias",
            "mod_accesslog",
            "mod_auth",
            "mod_ssi",
            "mod_cgi",
            "mod_compress",
            "mod_fastcgi",
            "mod_rewrite",
            "mod_magnet",
)
The web root dir should be "/var/www/" and the user which runs lighttpd is "www-data" - no need to change anything here.
Lighttpd should be already running. You can start/stop/restart the service with:
sudo /etc/init.d/lighttpd start
sudo /etc/init.d/lighttpd stop
sudo /etc/init.d/lighttpd restart
Now create a file "/var/www/index.html" with some html code, open a Browser and go to "http://<yourIP>/index.html". VoilĂ .

Saturday, January 26, 2013

First python program

I am new to python, so I first want to create the traditional "hello world" program in python and see if it works.
On my raspberry pi, python was already installed and added to the path.
There are different Version installed (standard 2.7 and the newer 3.2). Check your version:
python --version
Open an editor and type the following program:
#!/usr/bin/python
print "hello world"
Save as "test.py". It can be executed either by calling the python binary or making the file executable (asuming you are in the same directory as the python script file):
python test.py
chmod +x test.py   //sets the executable flag
./test.py
Or if you want to run it as phyton 3.2:
python3.2 test.py
This will output an error, because in the 3.x version of python the "print" command is a function and so we have to use it with parenthesis like this:
print("Hello world")
 Now it should work and print "Hello world" to stdout. Nice.

Thursday, January 24, 2013

Text to speech engine

Now we make the raspberry speak. I tried two different text-two-speak engines:
In the end I think espeak is the better choice, because it works more stable and the voice sounds better.
Installing is quite simple:
sudo apt-get install espeak
sudo apt-get install festival
Now for testing:
espeak "hello world"
espeak -f readFile

echo "hello world" | festival --tts
festival --tts readFile
The standard voice is english and male with a speed of 175. You can change that - for example:
espeak -s 150 -v german "hallo welt"
This changes the speed of the voice and sets the language to German.
If you have problems with the audio output, try running the command with sudo.
To check if it is a problem with your audio configuration or just with espeak, try playing a test audio file:
sudo aplay /usr/share/sounds/alsa/Front_Center.wav
Still no audio? Check your mixer settings - you can force an output channel:
sudo amixer cset numid=3 <n>
n=0 auto, n=1 analog, n=2 hdmi



To get the sound over HDMI working with my TV (LG 32LH2000) I also had to change the config.txt file in the boot directory. Add/uncomment the following line and restart the raspberry pi:
hdmi_drive=2
Still not working for some reason hmpf? Try loading the sound driver:
sudo modprobe snd_bcm2835

Removing a package
Since the festival package is not needed anymore, we remove it:
sudo apt-get remove --purge festival
sudo apt-get clean

Linux commands & stuff

Since I am not to used to using gnu/linux, here is a list of some commands/programs that are used often:

apt-get install <xxx> - install a new package
apt-get update - update the package list
apt-get upgrade - install new version of your packages
ls - list files/dirs
mv - moves a file
cp - copies a file
rn - renames a file
startx - start X-session (desktop)
nano - simple editor (ctrl+O = save, ctrl+X = close)
groups - print the groups a user is in
chmod - Changes the permission of a file

and many more...
A lot of times problems occure due to permission issues, so try "sudo" infront of the command before becoming furious. Also make sure that you have the rights to read/write a file, otherwise it won´t work.



Shutdown & restart
sudo shutdown -h now - shutsdown the raspberry pi now
sudo shutdown -r now - restarts the raspberry pi now
As suggested here: http://raspberrypi.stackexchange.com/questions/381/how-do-i-turn-off-my-raspberry-pi it might be a good idea to leave the rasperry pi connected to the power supply cable and use a plug board with a power switch - to limit the number of insert/disconnect cycles. If you are a little princess.


Config files & services
In linux most of settings/programs can be configured by editing their specific config files. After changing the config files you have to restart the pi or restart the specific service. This can be achieved like this:
sudo service <serviceName> restart/stop/start

First boot

If everything works, the raspberry pi should boot and you have a picture on your HDMI Screen. On the first start, the "raspi-config" script should start automatically: http://elinux.org/RPi_raspi-config


Her you can edit basic settings. If you want to run the script again later, just type in your command line:
sudo raspi-config
 My settings:
  • expand_rootfs - to use the full sd card size (otherwise the full size is not recognized)
  • Set time/date, keyboard layout & change default password (Username: pi Password: raspberry)
  • SSH server starts automatically
  • Do not start the Desktop
  • memory_split - 64MB for graphics is enough, since I won´t use the desktop/games etc.
You can start the desktop later by simply typing:
 startx
  
As you can see there are already some programs pre-installed. The desktop environment is LXDE: http://lxde.org/ which looks pretty nice, but as I said before it does not matter since I am nit going to use the desktop.
For webbrowsing you have midori, but it is pretty slow. You can install other browsers if you want to but firefox won´t run fast. Chromium might run better.

The main programming language for the raspberry pi is python. Since I am new to Python, I am looking forward to use it & learn!

Now it is time to update our system and remove all not needed programs:
sudo apt-get update
sudo apt-get upgrade
This will update the package list and install new versions of our packages.At least if you have already a working internet connection. I simply connected the raspberry pi with an ethernet cable to my router. Since I am using static IPs, I have to manually configure an IP adresse.

Configure static IP, Subnet mask, gateway:

You can use some tools or ifconfig to configure the network options, but the fastest way is to directly change the config file:
sudo nano /etc/network/interfaces
Here you have to set the specific interface to static (disable dhcp). Then you enter the following lines right underneath (remove the "<>" signs):
iface eth0 inet static
address <your IP here>
netmask <SubnetMask>
gateway <Standard gateway>
Afterwards reboot the pi and test your internet connection:
ping raspberrypi.org




Start

Hello,
This is my blog about my raspberry pi experiences and projects.
I got my Pi (Model B) some weeks ago and I am very happy with it. Yeah, playing!
If you have any suggestions or like something, please leave a comment. Since I am not a native english speaker, ignore any spelling- or grammer mistakes ;-)


Setup & Installing

Things you need before starting:
  • Raspberry Pi
  • Power supply (5V, 700mA min.)
  • SD card (I am using a SanDisk Ultra SDHC 16GB Class 10)
  • HDMI cable
  • Screen with HDMI connector
  • USB Keyboard, mouse
  • Ethernet cable or usb wifi (if you want network/internet). If you want to use an usb wifi adapter make sure it works under Linux/Raspberry Pi.
Before you can use your raspberry pi, you need to download and install an operating system on the SD card.
I choose the standard Raspbian "wheezy" image (based on Debian).
Download here: http://www.raspberrypi.org/downloads
Note: I am using the hard-float version, since it is faster. Right now (January, 2013) if you want to use Java, you have to use the soft-float version (at least for the Oracle/Sun Version as far as I know).

After downloading I followed this guide: http://elinux.org/RPi_Easy_SD_Card_Setup for formating & copying the image to my SD card.

Now just insert the SD Card, connect all the cables/keyboard etc. and start the raspberry pi by plugging the power supply in.
Note: I had to connect the HDMI cable and start the screen prior to starting the raspberry pi, otherwise there was no picture.