Friday, January 25, 2013

Sidekick 3

RaspberryPi the sidekick

McDonald's is currently advertising that "every hero needs a sidekick". Of course, if you've been following my blog, you already know this for a fact.

In the previous Sidekick articles (sidekick and sidekick 2), we saw how we could run a program on the Raspberry Pi, and the display would then be forwarded to another computer, through the use of X forwarding with ssh (-X).

One side effect of that mode is that the program will detect the X Windows property of the PC, and not the Raspberry Pi. For example, if your X server on your PC supports Open GL, although the Raspberry Pi supports only Open GL ES 2.0, the program will see the full Open GL stack.

It can be a good thing, but sometimes it can lead to surprises. Another limitation is the windowing.


When running a single application, this is the best way to use the Raspberry Pi as a sidekick. But don't forget to use the X forwarding, else you get:

pi@raspberrypi ~ $ idle
Traceback (most recent call last):
  File "/usr/bin/idle", line 5, in <module>
  File "/usr/lib/python2.7/idlelib/", line 1406, in main
    root = Tk(className="Idle")
  File "/usr/lib/python2.7/lib-tk/", line 1688, in __init__ = _tkinter.create(screenName, baseName, className,
interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

If we use ssh -X (or X forwarding in putty), it works as intended:

idle main window

And if we go to file and do an open, we see the files that are on the Raspberry Pi. Let me open the quick and dirty cam server we did at the last PyHack workshop (I'm putting the code in text too)

#!/usr/bin/env python

import web

class Images:
    def GET(self):
        typemap = {
        return open("fablocker.png","rb").read()

URLS = ( "/secret", Images ,

app = web.application(URLS, globals())

if __name__ == "__main__":

 This is just the web server side of things and is using

idle new editor window

We now have 2 windows of programs running on the Raspberry Pi, but displaying on our computer's desktop.

But sometimes it's important to have a full desktop. So how do we do this, to see the whole Raspberry Pi desktop?


The solution is Virtual Network Computing (VNC).

There are many implementations of the protocol, and they fall into 2 camps.
  • The kind that gives you a new desktop (it is not the same as the one that is on the HDMI output)
  • and the kind that attaches to the original desktop.


the client

Before installing the server, let's talk about the client. On your PC, if you have a unix or linux machine, there is a chance that you have a program called vncviewer. Try it and see if you do. If not, you will have to install it. This will depend greatly on what operating system you run, as far as how to do that. If your desktop is a *nix, I'm sure you know how to use your package manager to get vncviewer.

Under Windows you can get tightvnc for windows or you can try the multiplatform (Linux, Solaris, Windows, Mac) RealVNC. Many Mac users are partial to Chicken of the VNC.


Tightvnc is of the first category of servers. This has the advantage that you can get a graphical desktop, even if your Raspberry Pi is on the command line, without X windows started.

First we will have to install it:

$ ssh -X pi@raspberrypi

pi@raspberrypi ~ $ sudo apt-get install tightvncserver
pi@raspberrypi ~ $ tightvncserver :1

You will require a password to access your desktops.

Would you like to enter a view-only password (y/n)? n

New 'X' desktop is raspberrypi:1

Creating default startup script /home/pi/.vnc/xstartup
Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspberrypi:1.log

 And that should work, when you access your Pi remotely with a client.

It is also possible with tightvnc to specify a screen resolution that you choose, and it wont have anything to do with the Raspberry Pi screen resolution or your monitor's capability. For example, to get a 1024x768 desktop:

pi@raspberrypi ~ $ tightvncserver -geometry 1024x768 :1

Of course if tightvnc works well for you, you will want to automate the startup of the server. Stewart Watkiss posted the following startup script on (would go under /etc/init.d as tightvncserver):

# /etc/init.d/tightvncserver
# Customised by Stewart Watkiss
# Set the VNCUSER variable to the name of the user
# to start tightvncserver under
eval cd ~$VNCUSER
case "$1" in
   su $VNCUSER -c '/usr/bin/tightvncserver :1'
   echo "Starting TightVNC server for $VNCUSER "
   pkill Xtightvnc
   echo "Tightvncserver stopped"
   echo "Usage: /etc/init.d/tightvncserver {start|stop}"
   exit 1
exit 0

And then under .vnc, a xstartup file that contains the following:

xrdb $HOME/.Xresources
xsetroot -solid black
/usr/bin/lxsession -s LXDE &
And that should be it. After rebooting, it should start automatically. If you prefer x11vnc, then follow the next set of instructions instead.


x11vnc falls into the second category of servers. It will attach to the X server of the Raspberry Pi. As such, you have to run LXDE, you can't stay in console text mode.

To install it:

$ ssh -X pi@raspberrypi

pi@raspberrypi ~ $ sudo apt-get install x11vnc
pi@raspberrypi ~ $ x11vnc -storepasswd

You'll have to enter a password. Next we need to configure the startup with lxde:

pi@raspberrypi ~ $ cd .config
pi@raspberrypi ~ $ mkdir autostart
pi@raspberrypi ~ $ cd autostart
pi@raspberrypi ~ $ wget

Be patient on the last step, this is getting a startup file for x11vnc from my Brython playground site. It is usually pretty busy... Reboot the Pi and you should be set.

Accessing the Pi

Once you have the server running, you run the viewer on your PC, and specify the ip address (or name if you have avahi or the like), you will be greeted with a password prompt. That is the password you defined for the server, earlier:

And then, the desktop!

1024x768 Raspbian desktop, from my PC


hutenmy cawodson said...

For certain i will always claim who sit back and watch will make all very reputable pursuit wrist watches all over could will begin to connect not much on the subject of these people For the last generations with the help of exceptional feel, a keep an eye on seems to have produced two or three unique game devices that serve a fantastic design, appealing plus practical tricky motions, masculine styles, and also reasonable fees. The year 2010 in which combination with factors realises alone while in the modest format clock. The application sounds like a watch features designed ahead of so it utilizes an active circulation along with related term because many other varieties. Everything you tend to be visiting is often a improvement regarding dial model together with complete event as part of the much bigger as well as by now very fashionable collecting activity products. What precisely retains the particular set mutually in addition to large shapes not to mention military-inspired appears to be certainly is the the queen. The item performs in a different right from screw-down caps for that you choose to pose the idea in section even to another. White symptoms will mean that it must be secured though reddish colored signs implies that it must be clear for the purpose of winding and also getting ripped outside. Typically the call with the sit back and watch is really recognizable that will range enthusiasts. It consists of a fabulous a little distinctive treatment method, however, the key collection bank control plus 12 o'clock hour or so gun can be there and unchanged. It is either legible along with manly with a sort of exquisite means. Possible will be extra water-proof to help 100 yards and therefore the dark strap is actually calfskin set containing a strong just about textile expect to the application. I are not aware of the reason all the keep an eye on asserts at swiss watches from this character becoming confined model versions. They are just not necessarily for a function or even reason and definitely symbolize different technological know-how. I will solely observe him or her being hint this whilst the check out hobby looks after usually are awesome, they have been an excellent major organ of the brand over-all product sales course. Thereby, they have been limited for production regardless so they really will probably in the process cause them to be reduced edition articles. Conversely, many just really do not wish to commit to brands by using longer formation days and even good only a minimal level facilitates your designs to be further flexible type. Considering that it is resurrection through the quick nineties, this view has got converted into among the many uk perfect and the most innovative models, a position the item does not eliminate, regardless just how economic crises or perhaps ever-changing styles influence the. As grandiose simply because of which may seem, the follow contains generally met for greater laid-back last part of your economy, left over regularly follow with the help of calm together with obtained novelties, having onward typically the model and also its particular most well-known ranges simply by 1 small to medium sized stage at a time. However from time to time there may be multiple tiny factor who will have to be manufactured, as well as the view commands you and me of the fact that company is definitely taking a your tempo.

Blogger said...

Do you enjoy watching live sex cams? Have a peek at BongaCams.